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

import com.google.common.collect.Maps;
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.LisDoc;
import com.lantone.qc.pub.model.doc.PacsDoc;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : MEDI03116
 * @Description: 病理检查缺少病理检查报告单
 * @author: zh
 * @time: 2021/04/06 11:22
 */

@Component
public class MEDI03116 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) throws ParseException {
        status.set("0");
        FirstPageRecordDoc firstPageRecordDoc = inputInfo.getFirstPageRecordDoc();
        if (firstPageRecordDoc == null) {
            //病案首页为空判断医嘱
            List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
            if(ListUtil.isEmpty(doctorAdviceDocs)){
                return;
            }
            if (doctorAdviceDocs.size() == 0) {
                return;
            }
            for (DoctorAdviceDoc dad : doctorAdviceDocs) {
                Map<String, String> structureMap = dad.getStructureMap();
                String state = structureMap.get("医嘱状态判别");
                if(StringUtil.isEmpty(state)){
                    continue;
                }
                if(state.equals("在用")) {
                    String name = structureMap.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");
                                List<PacsDoc> pacsDocs = inputInfo.getPacsDocs();
                                for (PacsDoc pacsDoc : pacsDocs) {
                                    Map<String, String> pacsDocStructureMap = pacsDoc.getStructureMap();
                                    String pacsDocStr = pacsDocStructureMap.get("报告名称");
                                    if (pacsDocStr.contains("病理")) {
                                        status.set("0");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        Map<String, String> firstPageRecordDocStructureMap = firstPageRecordDoc.getStructureMap();
        String pathologyMoneyStr = firstPageRecordDocStructureMap.get("病理诊断费");
        String operationMoneyStr = firstPageRecordDocStructureMap.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");
                List<PacsDoc> pacsDocs = inputInfo.getPacsDocs();
                for (PacsDoc pacsDoc : pacsDocs) {
                    Map<String, String> pacsDocStructureMap = pacsDoc.getStructureMap();
                    String pacsDocStr = pacsDocStructureMap.get("报告名称");
                    if (pacsDocStr.contains("病理")) {
                        status.set("0");
                        return;
                    }

                }
            }
        }

}
