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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
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.doc.FirstCourseRecordDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName : FIRC0500
 * @Description : 首程主诉与入院记录主诉不一致
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class FIRC0500 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        FirstCourseRecordDoc firstCourseRecordDoc = inputInfo.getFirstCourseRecordDoc();
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (firstCourseRecordDoc == null || beHospitalizedDoc == null) {
            status.set("0");
            return;
        }

        String chief_text = beHospitalizedDoc.getChiefLabel().getText();//入院记录主诉
        if (StringUtil.isBlank(chief_text)) {
            status.set("0");
            return;
        }
        chief_text = chief_text.replaceAll("[\\p{Punct}\\pP。]", "");

        Map<String, String> structureMap = firstCourseRecordDoc.getStructureMap();
        String firstCourseChief = structureMap.get("主诉");//首程结构化数据中取主诉

        if (StringUtil.isNotBlank(firstCourseChief)) {
            firstCourseChief = firstCourseChief.replaceAll("[\\p{Punct}\\pP。]", "");
            if (firstCourseChief.contains(chief_text) || chief_text.contains(firstCourseChief)) { //首程主诉.equals(入院记录主诉)
                status.set("0");
                return;
            }
        }
        //结构化再获取病历特点，判断是否包含主诉内容
        firstCourseChief = structureMap.get("病例特点");
        if (StringUtil.isNotBlank(firstCourseChief)) {
            firstCourseChief = firstCourseChief.replaceAll("[\\p{Punct}\\pP。]", "");
            if (firstCourseChief.contains(chief_text)) { //首程病历特点.contains(入院记录主诉)
                status.set("0");
                return;
            }
        }
        //结构化再获取诊断依据，判断是否包含主诉内容
        String diagnose_resuse = structureMap.get("诊断依据");
        if (StringUtil.isNotBlank(diagnose_resuse)) {
            diagnose_resuse = diagnose_resuse.replaceAll("[\\p{Punct}\\pP。]", "");
            if (diagnose_resuse.contains(chief_text)) { //首程诊断依据.contains(入院记录主诉)
                status.set("0");
                return;
            }
        }
        if(StringUtils.isNotBlank(firstCourseRecordDoc.getText())){
            if (firstCourseRecordDoc.getText().contains(chief_text)) {
                status.set("0");
            }
        }

    }
}