package com.lantone.qc.kernel.catalogue.behospitalized;

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.entity.Diag;
import com.lantone.qc.pub.model.label.ChiefLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;


/**
 * @ClassName : BEH0010
 * @Description : 主诉中出现诊断名称（病理确诊：如肿瘤疾病、再入院除外）
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0010 extends QCCatalogue {
    private List<String> containList = Arrays.asList("癌", "瘤", "复诊", "术后", "化疗后", "发现", "体检", "检查", "确诊"
            , "诊断", "复查", "复发", "示", "超", "CT", "血透", "血液透析");

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        ChiefLabel chiefLabel = inputInfo.getBeHospitalizedDoc().getChiefLabel();
        if (chiefLabel == null) {
            status.set("0");
            return;
        }
        String chiefText = chiefLabel.getText();
        if (StringUtil.isNotBlank(chiefText)) {
            for (String word : containList) {
                if (chiefText.contains(word)) {
                    status.set("0");
                    return;
                }
            }
        }
        List<Diag> diags = chiefLabel.getDiags();
        /*
        if (diags != null && diags.size() > 0) {
            Iterator<Diag> diagIterator = diags.iterator();
            while (diagIterator.hasNext()) {
                Diag diag = diagIterator.next();
                String diagName = diag.getHospitalDiagName();
                for (String word: containList) {
                    if (diagName.contains(word)){
                        diagIterator.remove();
                        break;
                    }
                }
            }
        }
         */
        if (diags != null && diags.size() > 0) {
            status.set("-1");
            for (Diag diag : diags) {
                if (StringUtil.isEmpty(info.get())) {
                    info.set(diag.getHospitalDiagName());
                } else {
                    info.set(info.get() + "," + diag.getHospitalDiagName());
                }
            }
        }

    }
}