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

import com.google.common.collect.Lists;
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.doc.BeHospitalizedDoc;
import com.lantone.qc.pub.model.entity.Clinical;
import com.lantone.qc.pub.model.label.PastLabel;
import com.lantone.qc.pub.model.label.PresentLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * @ClassName : BEH0013
 * @Description :  现病史缺少有鉴别意义的阴性症状
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0013 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<String> words = Lists.newArrayList("无", "否认", "内固定", "诱因");
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (beHospitalizedDoc == null) {
            return;
        }
        //现病史
        PresentLabel presentLabel = beHospitalizedDoc.getPresentLabel();
        //既往史
        PastLabel pastLabel = beHospitalizedDoc.getPastLabel();
        //入院记录存在一般情况
        Map<String, String> structureMap_bh = beHospitalizedDoc.getStructureMap();
        String generalCondition = structureMap_bh.get("一般情况");
        if (StringUtil.isNotBlank(generalCondition) && presentLabel == null) {
            for (String word : words) {
                if (generalCondition.contains(word)) {
                    return;
                }
            }
        }
        if ((presentLabel == null || StringUtil.isBlank(presentLabel.getText()) || "。".equals(presentLabel.getText()))
                && (pastLabel == null || StringUtil.isBlank(pastLabel.getText()) || "。".equals(pastLabel.getText()))) {
            return;
        }
        String text = presentLabel.getText();
        if (StringUtil.isNotBlank(text)) {
            for (String word : words) {
                if (text.contains(word)) {
                    return;
                }
            }
        }
        List<Clinical> clinicalNegative = new ArrayList<>();
        List<Clinical> clinicals = presentLabel.getClinicals();
        if (clinicals.size() > 0) {
            for (Clinical clinical : clinicals) {
                if (clinical.getNegative() != null) {
                    clinicalNegative.add(clinical);
                }
            }
        }
        if (clinicalNegative.size() == 0) {
            status.set("-1");
        }
    }
}