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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.Content;
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.FirstPageRecordDoc;
import com.lantone.qc.pub.model.doc.PacsDoc;
import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import io.netty.util.internal.ObjectUtil;

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

/**
 * @ClassName : THR03117
 * @Description :  病理检查存在病程记录中无病理报告结果
 * @Author : zh
 * @Date: 2021-04-02 17:06
 */
public class THR03117 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        FirstPageRecordDoc firstPageRecordDoc = inputInfo.getFirstPageRecordDoc();
        if(firstPageRecordDoc==null){
            //病案首页为空判断医嘱
            List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
            if (doctorAdviceDocs.size() == 0) {
                return;
            }
            for (DoctorAdviceDoc dad : doctorAdviceDocs) {
                Map<String, String> dadStructureMap = dad.getStructureMap();
                String state = dadStructureMap.get("医嘱状态判别");
                if(StringUtil.isEmpty(state)){
                    continue;
                }
                if(state.equals("在用")) {
                String name = dadStructureMap.get("医嘱项目名称");
                if (name.contains("非手术") || name.contains("手术室") || (name.contains("手术") && name.contains("取消")) || (name.contains("暂停") && name.contains("手术")) || name.contains("静脉穿刺置管术") || name.startsWith("停") || name.contains("前一次")
                        || name.contains("特殊病人手术使用一次性卫生材料") || name.contains("人免疫缺陷病毒抗体检测免费")) {
                    continue;
                }
                if (name.contains("手术")) {
                    for (DoctorAdviceDoc doctorAdviceDoc : doctorAdviceDocs) {
                        String adviceDocName = doctorAdviceDoc.getStructureMap().get("医嘱项目名称");
                        if (adviceDocName.contains("病理")) {
                            status.set("-1");
                            //查房记录查找病理报告
                            ThreeLevelWardDoc threeLevelWardDoc = inputInfo.getThreeLevelWardDocs().get(0);
                            //所有查房记录
                            List<ThreeLevelWardDoc> allDoctorWradDocs = threeLevelWardDoc.getAllDoctorWradDocs();
                            if(ListUtil.isEmpty(allDoctorWradDocs)){
                                return;
                            }
                            for (ThreeLevelWardDoc allDoctorWradDoc : allDoctorWradDocs) {
                                String pathographyStr = allDoctorWradDoc.getStructureMap().get("病情记录");
                                if(pathographyStr.contains("病理报告")){
                                    status.set("0");
                                    return;
                                }
                            }

                        }
                    }
                    }
                }
            }
        }
        Map<String, String> structureMap = firstPageRecordDoc.getStructureMap();
        String pathologyMoneyStr = structureMap.get("病理诊断费");
        String operationMoneyStr = structureMap.get("手术费");
        if(StringUtil.isEmpty(pathologyMoneyStr)||StringUtil.isEmpty(operationMoneyStr)){
            return;
        }
        if ((pathologyMoneyStr.equals("0")  || operationMoneyStr.equals("0") )) {
            return;
        }
        double a = Double.parseDouble(pathologyMoneyStr);
        double b = Double.parseDouble(operationMoneyStr);
        if (a > Content.pathologicalFee && b > 0) {
            status.set("-1");
            //查房记录查找病理报告
            ThreeLevelWardDoc threeLevelWardDoc = inputInfo.getThreeLevelWardDocs().get(0);
            //所有查房记录
            List<ThreeLevelWardDoc> allDoctorWradDocs = threeLevelWardDoc.getAllDoctorWradDocs();
            if(ListUtil.isEmpty(allDoctorWradDocs)){
                return;
            }
            for (ThreeLevelWardDoc allDoctorWradDoc : allDoctorWradDocs) {
                String pathographyStr = allDoctorWradDoc.getStructureMap().get("病情记录");
                if(pathographyStr.contains("病理报告")){
                    status.set("0");
                    return;
                }
            }
        }

    }
}
