package com.lantone.qc.kernel.catalogue.beilun.majorInspection;

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.DoctorAdviceDoc;
import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.MapUtil;
import com.lantone.qc.pub.util.StringUtil;

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

/**
 * @ClassName : THR03115
 * @Description :  接受CT情况下病程记录缺少CT检查记录
 * @Author : zh
 * @Date: 2021-04-06 17:06
 */
public class THR03115 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        int ctNum=0;
        int bcNum=0;
        List<DoctorAdviceDoc> doctorAdviceDocsList = inputInfo.getDoctorAdviceDocs();
        if(ListUtil.isNotEmpty(doctorAdviceDocsList)) {
            for (DoctorAdviceDoc doctorAdviceDoc : doctorAdviceDocsList) {
                Map<String, String> doctorAdviceDocStructureMap = doctorAdviceDoc.getStructureMap();
                String state = doctorAdviceDocStructureMap.get("医嘱状态判别");
                if(StringUtil.isEmpty(state)){
                    continue;
                }
                if(state.equals("在用")) {
                //ct取临时医嘱
                String doctorAsks = doctorAdviceDocStructureMap.get("医嘱类型判别");
                if ("临时医嘱".equals(doctorAsks)) {
                    //取医嘱项目名称
                    String daItemName = doctorAdviceDocStructureMap.get("医嘱项目名称");
                    if (daItemName.contains("CT") || daItemName.contains("X线")) {
                        if ((!daItemName.contains("ATCH") && !daItemName.contains("TCT") && !daItemName.contains("HCT") && !daItemName.contains("OCT") && !daItemName.contains("NCT") && !daItemName.contains("LCT") && !daItemName.contains("ACT")) || (daItemName.contains("停"))) {
                            //都不包含为CT
                            ctNum++;
                            continue;
                        }
                    }
                }
                }
            }
            List<ThreeLevelWardDoc> allDoctorWradDocs = inputInfo.getThreeLevelWardDocs().get(0).getAllDoctorWradDocs();
            if(ListUtil.isNotEmpty(allDoctorWradDocs)&&allDoctorWradDocs.size()>0){
                for (ThreeLevelWardDoc allDoctorWradDoc : allDoctorWradDocs) {
                    Map<String, String> structureMap = allDoctorWradDoc.getStructureMap();
                    String records = structureMap.get("病情记录");
                    if (records.contains("CT")&&StringUtil.isNotEmpty(records)) {
                        bcNum++;
                    }
                }
            }
            if(ctNum!=bcNum){
                status.set("-1");
            }

        }
    }

}
