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

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.CriticallyIllNoticeDoc;
import com.lantone.qc.pub.model.doc.DoctorAdviceDoc;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : MEDI02999
 * @Description : 病重患者无病重通知单
 * @Author : zhoutg
 * @Date: 2020-04-21 18:40
 */
@Component
public class MEDI02999 extends QCCatalogue {

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        /**
         * 1、医嘱中包含“病重”2个字
         * 2、病危通知单（包含病危+病重）列表中包含“病重”2个字
         *
         * 病危通知单数据示例：
         *      邵逸夫数据示例：病危通知 、病重通知
         *      长兴和台州病危和病重是混合的：示例：病危（重）告知书，0433 病危（重）通知
         */
        status.set("0");
        if (ListUtil.isEmpty(inputInfo.getDoctorAdviceDocs())) {
            return ;
        }
        Boolean flag = false;
        for (DoctorAdviceDoc bean : inputInfo.getDoctorAdviceDocs()) {
            Map<String, String> structureMap = bean.getStructureMap();
            if (StringUtil.isNotBlank(structureMap.get("医嘱项目名称"))
                    && structureMap.get("医嘱项目名称").indexOf("病重") != -1){
                // 包含病重医嘱
                flag = true;
                break;
            }
        }
        if (!flag) {
            return ;
        }
        // 病危通知书中包含“病重”2个字
        List<CriticallyIllNoticeDoc> criticallyIllNoticeDocs = inputInfo.getCriticallyIllNoticeDocs();
        if (ListUtil.isNotEmpty(criticallyIllNoticeDocs)) {
            for (CriticallyIllNoticeDoc bean : criticallyIllNoticeDocs) {
                Map<String, String> structureMap = bean.getStructureMap();
                String mapKey = ""; // 数据示例："rec_title=病重通知"
                for (Map.Entry<String, String> entity : structureMap.entrySet()) {
                    if (entity.getKey().indexOf("rec_title=") > -1){
                        mapKey = entity.getKey();
                        break;
                    }
                }
                if (StringUtil.isNotBlank(mapKey) && mapKey.contains("病重")) {
                    status.set("0");
                    return ;
                }
            }
        }
        status.set("-1");
    }
}