package com.lantone.qc.trans.yiwu;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.lantone.qc.dbanaly.facade.yiwu.YiWuXmlUtil;
import com.lantone.qc.dbanaly.util.ModuleMappingUtil;
import com.lantone.qc.pub.model.doc.operation.OperationDiscussionDoc;
import com.lantone.qc.pub.model.doc.operation.OperationDoc;
import com.lantone.qc.pub.model.doc.operation.OperationInformedConsentDoc;
import com.lantone.qc.pub.model.doc.operation.OperationRecordDoc;
import com.lantone.qc.pub.model.doc.operation.OperationSafetyChecklistDoc;
import com.lantone.qc.pub.model.doc.operation.PreoperativeDiscussionDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.pub.util.FastJsonUtils;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.trans.comsis.CommonAnalysisUtil;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import org.apache.commons.lang3.StringUtils;

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

/**
 * @Description: 手术文档生成
 * @author: rengb
 * @time: 2020/3/20 17:11
 */
public class YiWuOperationDocTrans extends ModelDocTrans {

    /**
     * 手术文档包含：术后首次病程及谈话记录；手术记录；术前讨论、术前小结；手术知情同意书；手术安全核查表
     *
     * @param medrecVo
     * @return
     */
    @Override
    public List<OperationDoc> extract(MedrecVo medrecVo) {
        List<OperationDoc> retList = Lists.newArrayList();

        Map<String, List<String>> contentMap = (Map) medrecVo.getContent().get("content");
        if (contentMap == null) {
            return retList;
        }

        Map<String, OperationDiscussionDoc> operationDiscussionDocMap = getOperationDiscussionDocMap((List) contentMap.get("术后首次病程及谈话记录"));
        Map<String, OperationRecordDoc> operationRecordDocMap = getOperationRecordDocMap((List) contentMap.get("手术记录"));
        Map<String, PreoperativeDiscussionDoc> preoperativeDiscussionDocMap = getPreoperativeDiscussionDocMap((List) contentMap.get("术前讨论、术前小结"));
        Map<String, OperationInformedConsentDoc> operationInformedConsentDocMap = getOperationInformedConsentDocMap((List) contentMap.get("手术知情同意书"));
        //Map<String, OperationSafetyChecklistDoc> operationSafetyChecklistDocMap = getOperationSafetyChecklistDocMap((List) contentMap.get("手术安全核查表"));

        Set<String> operationNameSet = Sets.newHashSet();
        operationNameSet.addAll(operationDiscussionDocMap.keySet());
        operationNameSet.addAll(operationRecordDocMap.keySet());
        operationNameSet.addAll(preoperativeDiscussionDocMap.keySet());
        operationNameSet.addAll(operationInformedConsentDocMap.keySet());
        //operationNameSet.addAll(operationSafetyChecklistDocMap.keySet());

        operationNameSet.forEach(operationName -> {
            OperationDoc operationDoc = new OperationDoc();
            operationDoc.setOperationName(operationName);
            operationDoc.setOperationDiscussionDoc(operationDiscussionDocMap.get(operationName));
            operationDoc.setOperationRecordDoc(operationRecordDocMap.get(operationName));
            operationDoc.setPreoperativeDiscussionDoc(preoperativeDiscussionDocMap.get(operationName));
            operationDoc.setOperationInformedConsentDoc(operationInformedConsentDocMap.get(operationName));
            //operationDoc.setOperationSafetyChecklistDoc(operationSafetyChecklistDocMap.get(operationName));
            retList.add(operationDoc);
        });
        return retList;
    }


    /*******************************************术后首次病程及谈话记录***************************************************/
    private Map<String, OperationDiscussionDoc> getOperationDiscussionDocMap(List<Map<String, Object>> contentMaps) {
        Map<String, OperationDiscussionDoc> retMap = Maps.newHashMap();
        if (ListUtil.isEmpty(contentMaps)) {
            return retMap;
        }
        int index = 1;
        String operationName = null;
        for (Map<String, Object> contentMap : contentMaps) {
            if (contentMap.get("xmlText") == null || StringUtil.isBlank(contentMap.get("xmlText").toString())) {
                continue;
            }
            operationName = index + "";
            OperationDiscussionDoc operationDiscussionDoc = getOperationDiscussionDoc(contentMap);
            operationDiscussionDoc.setOperationName(operationName);
            retMap.put(operationName, operationDiscussionDoc);
            index++;
        }
        return retMap;
    }

    private OperationDiscussionDoc getOperationDiscussionDoc(Map<String, Object> contentMap) {
        String modeId = "18";
        String content = contentMap.get("xmlText").toString();
        Map<String, String> structureMap = null;
        if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
            structureMap = (Map) FastJsonUtils.getJsonToMap(content);
        } else {
            Map<String, String> sourceMap = YiWuXmlUtil.xmlToMap(content);
            sourceMap.put("mode_id", ModuleMappingUtil.getDeptModuleId(modeId));
            List<String> titles = Lists.newArrayList("手术开始时间", "术中诊断", "麻醉方式", "手术方式",
                    "手术简要经过（包括术中所见）", "术后诊疗计划（处理措施）", "术后注意观察事项", "医师签名",
                    "签名时间", "患者或代理人签名", "签名时间", "术中见", "术后诊断", "术后谈话");
            String text = sourceMap.get("原始文本");
            List<String> sortTitles = CommonAnalysisUtil.sortTitles(titles, text);
            CommonAnalysisUtil.cutByTitles(text, sortTitles, 0, sourceMap);
            sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            int index = 0;
            if (text.contains("手术开始时间")) {
                index = text.indexOf("手术开始时间") + 8;
            }
            String timevalue = text.substring(index, index + 18);
            sourceMap.put("手术开始时间", timevalue);
            String[] str = new String[3];
            String s = "";
            if (text.contains("术中诊断")) {
                str = text.split("术中诊断");
                s = str[1].replace(":", "");
            }
            sourceMap.put("术中诊断", s);

            structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, operationDiscussion_keyContrasts, modeId);

        }

        OperationDiscussionDoc operationDiscussionDoc = new OperationDiscussionDoc();
        operationDiscussionDoc.setStructureMap(structureMap);
        operationDiscussionDoc.setPageData((Map) structureMap);

        return operationDiscussionDoc;
    }

    private List<String> operationDiscussion_keyContrasts = Lists.newArrayList(
            "本人姓名=姓名",
            "书写日期=记录时间",
            "注意事项=术后注意事项",
            "治疗计划和措施=术后处理措施",
            "术后注意观察事项=术后注意事项",
            "手术方式=手术名称方式",
            "手术简要经过（包括术中所见）=手术简要经过",
            "术中诊断=术中后诊断",
            "术后诊疗计划（处理措施）=术后处理措施",
            "手术开始时间=开始时间",
            "病程内容=手术简要经过",
            "术后诊断=术后处理措施",
            "术后谈话=术后注意事项",
            "记录医师签名=记录医生",
            "医师签名=记录医生",
            "签名时间=记录时间",
            "会诊日期=手术日期",
            "记录医师=记录医生",
            "医师签名日期=记录时间"
    );


    /**********************************************手术记录*************************************************************/
    private Map<String, OperationRecordDoc> getOperationRecordDocMap(List<Map<String, Object>> contentMaps) {
        Map<String, OperationRecordDoc> retMap = Maps.newHashMap();
        if (ListUtil.isEmpty(contentMaps)) {
            return retMap;
        }
        int index = 1;
        String operationName = null;
        for (Map<String, Object> contentMap : contentMaps) {
            if (contentMap.get("xmlText") == null || StringUtil.isBlank(contentMap.get("xmlText").toString())) {
                continue;
            }
            operationName = index + "";
            OperationRecordDoc operationRecordDoc = getOperationRecordDoc(contentMap);
            operationRecordDoc.setOperationName(operationName);
            retMap.put(operationName, operationRecordDoc);
            index++;
        }
        return retMap;
    }

    private OperationRecordDoc getOperationRecordDoc(Map<String, Object> contentMap) {
        String modeId = "17";
        String content = contentMap.get("xmlText").toString();
        Map<String, String> structureMap = null;
        if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
            structureMap = (Map) FastJsonUtils.getJsonToMap(content);
        } else {
            Map<String, String> sourceMap = YiWuXmlUtil.xmlToMap(content);
            sourceMap.put("mode_id", ModuleMappingUtil.getDeptModuleId(modeId));
            List<String> titles = Lists.newArrayList("手术开始时间", "手术结束时间", "手术时间", "手术前诊断", "术（中）后诊断",
                    "手术名称", "手术医师", "助手医师", "第一助手", "第二助手","第三助手","洗手护士", "麻醉方式", "手术人员", "麻醉人员",
                    "麻醉医师", "手术护士", "巡回护士", "手术中用药（化疗等药物）", "手术切口类别（可选）", "术中出血量", "输血量", "术中输血量"
                    , "围术期并发症", "手术切除标本", "冰冻切片结果", "标本件数", "是否有植入物", "手术步骤", "记录者签名", "记录日期", "术中失血量",
                    "手术简要经过（包括“术中所见”）", "医师签名", "签名时间", "患者或代理人签名", "术中并发症", "日    期", "术前诊断", "术后诊断","手术经过",
                    "手术适应症","手术记录人员","ml");

            String text = sourceMap.get("原始文本");
            List<String> sortTitles = CommonAnalysisUtil.sortTitles(titles, text);
            CommonAnalysisUtil.cutByTitles(text, sortTitles, 0, sourceMap);
            sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, operationRecord_keyContrasts, modeId);
            //出血量、输血量有些有ml有些没有，统一一下
            if(structureMap.containsKey("输血量")){
                structureMap.put("输血量",structureMap.get("输血量").replaceAll("ml",""));
            }
            OrdinaryAssistant.removeBlank(structureMap);
        }
        OperationRecordDoc operationRecordDoc = new OperationRecordDoc();
        operationRecordDoc.setStructureMap(structureMap);
        operationRecordDoc.setPageData((Map) structureMap);
        return operationRecordDoc;
    }

    // 手术记录
    private List<String> operationRecord_keyContrasts = Lists.newArrayList(
            /*"结束时间=手术结束时间",
            "开始时间=手术开始时间",*/
            "医生=主刀医师签名",
            "助手=一助",
            "本人姓名=姓名",
            "手术开始日期时间=开始时间",
            "手术结束日期时间=结束时间",
            "术后诊断=术中后诊断",
            "麻醉方法代码=麻醉方式",
            "麻醉医师签名=麻醉医师",
            "手术过程的详细描述=手术经过及处理",
            "手术开始时间=开始时间",
            "手术结束时间=结束时间",
            "手术中用药=手术中用药化疗等药物",
            "术后送检病理无有标本件数=标本件数",
            "出血量=出血",
            "是否有植入物=是否术中植入物",
            "手术切口类别（可选）=切口类别",
            "手术步骤=手术经过及处理",
            "记录者签名=记录医生",
            "记录日期=记录时间",
            "手术人员=主刀医师",
            "手术医师=主刀医师",
            "失血量=出血",
            "术中失血量=出血",
            "医师签名时间=记录时间",
            "医师签名=记录医生",
            "手术过程=手术经过及处理",
            "手术简要经过（包括“术中所见”）=手术经过及处理",
            "第一助手=一助",
            "洗手护士=手术护士",
            "手术经过=手术经过及处理",
            "助手医师=一助",
            "主治医师=主刀医师",
            "术中出血量=出血",
            "初步诊断=术前诊断",
            "手术经过=手术经过及处理",
            "助手=一助",
            "手术前诊断=术前诊断",
            "手术记录人员=记录医生",
            "签名时间=记录时间"

    );


    /**********************************************术前讨论、术前小结****************************************************/
    private Map<String, PreoperativeDiscussionDoc> getPreoperativeDiscussionDocMap(List<Map<String, Object>> contentMaps) {
        Map<String, PreoperativeDiscussionDoc> retMap = Maps.newHashMap();
        if (ListUtil.isEmpty(contentMaps)) {
            return retMap;
        }
        int index = 1;
        String operationName = null;
        for (Map<String, Object> contentMap : contentMaps) {
            if (contentMap.get("xmlText") == null || StringUtil.isBlank(contentMap.get("xmlText").toString())) {
                continue;
            }
            operationName = index + "";
            PreoperativeDiscussionDoc preoperativeDiscussionDoc = getPreoperativeDiscussionDoc(contentMap);
            preoperativeDiscussionDoc.setOperationName(operationName);
            retMap.put(operationName, preoperativeDiscussionDoc);
            index++;
        }
        return retMap;
    }

    private PreoperativeDiscussionDoc getPreoperativeDiscussionDoc(Map<String, Object> contentMap) {
        String modeId = "11";
        String content = contentMap.get("xmlText").toString();
        Map<String, String> structureMap = null;
        if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
            structureMap = (Map) FastJsonUtils.getJsonToMap(content);
        } else {
            Map<String, String> sourceMap = YiWuXmlUtil.xmlToMap(content);
            sourceMap.put("mode_id", ModuleMappingUtil.getDeptModuleId(modeId));
            List<String> titles = Lists.newArrayList("讨论时间", "讨论地点", "主持人", "经治医师", "讨论意见",
                    "参加人员及技术职称", "讨论方式", "讨论记录", "主持人签名", "记录人签名", "病史摘要", "术前诊断", "术前准备"
                    , "拟施手术", "拟施麻醉", "术中注意点", "家属谈话内容", "医生签名", "日  期", "术前准备情况", "手术指征", "手术方案",
                    "可能出现的意外及防范措施", "讨论日期时间", "参加人员", "讨论主持人", "小结", "记录医师","手术者签名","麻醉医师签名","手术指征与禁忌症"
                    , "拟施手术名称和方式及可能的变更", "可替代方案", "计划性多次手术",
                    "术前特殊准备", "心理状态", "经济评估", "主要术中、术后风险及防范措施", "术中、术后注意事项（含护理事项）",
                    "一：经治医师汇报病史", "二：讨论目的", "三：讨论","主持人的姓名及专业技术职务","参加讨论者的姓名及专业技术职务","记录医师签名",
                    "手术预期","注意事项","防范措施","拟实施麻醉方式","手术时间","医师签名","会诊意见","患者术前情况");
            String text = sourceMap.get("原始文本");
            List<String> sortTitles = CommonAnalysisUtil.sortTitles(titles, text);
            CommonAnalysisUtil.cutByTitles(text, sortTitles, 0, sourceMap);
            sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            if(sourceMap.containsKey("术前诊断")){
                String[] str=sourceMap.get("术前诊断").split("术前准备");
                if(str.length>1){
                    sourceMap.put("术前准备",str[1]);
                    sourceMap.put("术前诊断",str[0]);
                }
            }
            if(sourceMap.containsKey("术前准备情况")){
                if(sourceMap.get("原始文本").split("术前准备情况").length>1){
                    sourceMap.put("术前准备情况",sourceMap.get("原始文本").split("术前准备情况")[1].split("手术指征")[0].split("拟实施麻醉方式")[0]);
                }
            }
            if(sourceMap.containsKey("计划性多次手术")){
                sourceMap.put("计划性多次手术",sourceMap.get("计划性多次手术").split("拟施麻醉方式")[0]);
            }
            structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, preoperativeDiscussion_keyContrasts, modeId);
            //去除list中key对应的value中末尾的数字字符
            List<String> title = Lists.newArrayList("术前诊断","手术指征与禁忌","拟施手术方式名称及可能的变更与禁忌症",
                    "可替代方案","计划性多次手术","主要术中、术后风险及防范措施","心理状态","经济评估","手术预期","注意事项","防范措施","讨论意见");
            for (String str:title) {
                if(structureMap.containsKey(str)){
                    String orign=structureMap.get(str).replaceAll("\\.","");
                    String discarded=(orign+"1").replaceAll(".*[^\\d](?=(\\d+))","");
                    String value=(orign+"1").replaceAll(discarded,"");
                    structureMap.put(str,value);
                }
            }
            addKeyMapping(structureMap, "麻醉方式", "拟施手术名称及麻醉方式");
            addKeyMapping(structureMap, "主刀医师签名", "主刀医生");
            addKeyMapping(structureMap, "既往疾病史", "其他");
            addKeyMapping(structureMap, "诊疗计划", "治疗计划和措施");
        }
        PreoperativeDiscussionDoc preoperativeDiscussionDoc = new PreoperativeDiscussionDoc();
        preoperativeDiscussionDoc.setStructureMap(structureMap);
        preoperativeDiscussionDoc.setPageData((Map) structureMap);
        return preoperativeDiscussionDoc;
    }

    private List<String> preoperativeDiscussion_keyContrasts = Lists.newArrayList(
            "参加人员及职称=参加人员",
            "主刀医师=主刀医师签名",
            "注意事项=术前术后注意事项",
            "其他术前相关情况=术前术后注意事项",
            "辅助检查结果=辅助检查",
            "术中、术后防范措施=主要术中、术后风险及防范措施",
            "术中注意点=主要术中、术后风险及防范措施",
            "现病史- 发病情况=发病经过",
            "本人姓名=姓名",
            "拟施手术名称和方式=拟施手术方式名称及可能的变更与禁忌症",
            "拟施手术=拟施手术方式名称及可能的变更与禁忌症",
            "拟实施麻醉方法代码=拟施麻醉方式",
            "拟施麻醉=拟施麻醉方式",
            "拟实施手术及操作名称=拟施手术方式、名称及可能的变更与禁忌症",
            "术前术后注意事项=主要术中、术后风险及防范措施",
            "时间=讨论时间",
            "手术指征与禁忌症=手术指征与禁忌",
            "讨论日期时间=讨论时间",
            "讨论日期=讨论时间",
            "参加人员及技术职称=参加人员",
            "主持人姓名=讨论主持人",
            "术前准备内容=术前准备",
            "经治医师=经治医生",
            "记录人签名=记录医生",
            "医生签名=记录医生",
            "讨论记录=讨论意见",
            "记录医师=记录医生",
            "讨论日期时间=讨论时间",
            "可能出现的意外及防范措施=主要术中、术后风险及防范措施",
            "术前准备情况=术前准备",
            "手术指征=手术指征与禁忌",
            "手术方案=拟施手术方式名称及可能的变更与禁忌症",
            "主持人=讨论主持人",
            "小结=主持人小结",
            "术前特殊准备=术前准备",
            "参加讨论人员名单=参加人员",
            "患者姓名=患者",
            "当前床号=床号",
            "当前科室=科别",
            "一：经治医师汇报病史=经治医师汇报病史",
            "二：讨论目的=讨论目的",
            "三：讨论=讨论",
            "患者签名日期=记录时间",
            "手术名称=拟施手术方式名称及可能的变更与禁忌症",
            "麻醉方式=拟施麻醉方式",
            "拟施手术名称和方式及可能的变更=拟施手术方式名称及可能的变更与禁忌症",
            "手术要点=主要术中、术后风险及防范措施",
            "参加讨论者的姓名及专业技术职务=参加人员",
            "主持人的姓名及专业技术职务=讨论主持人",
            "病史摘要=简要病情",
            "医师签名=记录医生",
            "注意事项=术中术后注意事项含护理事项",
            "防范措施=主要术中、术后风险及防范措施",
            "医师签名时间=记录时间",
            "医师签名=记录医生",
            "会诊意见=讨论意见"
    );

    /**********************************************手术知情同意书****************************************************/
    private Map<String, OperationInformedConsentDoc> getOperationInformedConsentDocMap(List<Map<String, Object>> contentMaps) {
        Map<String, OperationInformedConsentDoc> retMap = Maps.newHashMap();
        if (ListUtil.isEmpty(contentMaps)) {
            return retMap;
        }
        int index = 1;
        String operationName = null;
        for (Map<String, Object> contentMap : contentMaps) {
            if (contentMap.get("xmlText") == null || StringUtil.isBlank(contentMap.get("xmlText").toString())) {
                continue;
            }
            operationName = index + "";
            OperationInformedConsentDoc operationInformedConsentDoc = getOperationInformedConsentDoc(contentMap);
            operationInformedConsentDoc.setOperationName(operationName);
            retMap.put(operationName, operationInformedConsentDoc);
            index++;
        }
        return retMap;
    }

    private OperationInformedConsentDoc getOperationInformedConsentDoc(Map<String, Object> contentMap) {
        String modeId = "16";
        String content = contentMap.get("xmlText").toString();
        Map<String, String> structureMap = null;
        if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
            structureMap = (Map) FastJsonUtils.getJsonToMap(content);
        } else {
            Map<String, String> sourceMap = YiWuXmlUtil.xmlToMap(content);
            sourceMap.put("mode_id", ModuleMappingUtil.getDeptModuleId(modeId));
            sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, operationInformedConsent_keyContrasts, modeId);
        }
        OperationInformedConsentDoc operationInformedConsentDoc = new OperationInformedConsentDoc();
        operationInformedConsentDoc.setStructureMap(structureMap);
        operationInformedConsentDoc.setPageData((Map) structureMap);
        return operationInformedConsentDoc;
    }

    private List<String> operationInformedConsent_keyContrasts = Lists.newArrayList(
            "姓名++++患者姓名=姓名",
            "性别=",
            "病区++++病区名称=病区",
            "床号=",
            "病案号++++住院号=病案号",
            "手术医生=",
            "目前诊断=",
            "手术名称=",
            "手术指征=手术指征与禁忌",
            "风险及并发症=",
            "++++保守治疗=保守治疗",
            "++++其他手术=其他手术",
            "签名++++=签名",
            "签名时间=签名时间",
            "术前准备内容=术前准备"
    );


    /**********************************************手术安全核查表****************************************************/
    private Map<String, OperationSafetyChecklistDoc> getOperationSafetyChecklistDocMap(List<Map<String, Object>> contentMaps) {
        Map<String, OperationSafetyChecklistDoc> retMap = Maps.newHashMap();
        if (ListUtil.isEmpty(contentMaps)) {
            return retMap;
        }
        int index = 1;
        String operationName = null;
        for (Map<String, Object> contentMap : contentMaps) {
            if (contentMap.get("xmlText") == null || StringUtil.isBlank(contentMap.get("xmlText").toString())) {
                continue;
            }
            operationName = index + "";
            OperationSafetyChecklistDoc operationSafetyChecklistDoc = getOperationSafetyChecklistDoc(contentMap);
            operationSafetyChecklistDoc.setOperationName(operationName);
            retMap.put(operationName, operationSafetyChecklistDoc);
            index++;
        }
        return retMap;
    }

    private OperationSafetyChecklistDoc getOperationSafetyChecklistDoc(Map<String, Object> contentMap) {
        String modeId = "21";
        String content = contentMap.get("xmlText").toString();
        Map<String, String> structureMap = null;
        if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
            structureMap = (Map) FastJsonUtils.getJsonToMap(content);
        } else {
            Map<String, String> sourceMap = YiWuXmlUtil.xmlToMap(content);
            sourceMap.put("mode_id", ModuleMappingUtil.getDeptModuleId(modeId));
            sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, operationSafetyChecklist_keyContrasts, modeId);
        }
        OperationSafetyChecklistDoc operationSafetyChecklistDoc = new OperationSafetyChecklistDoc();
        operationSafetyChecklistDoc.setStructureMap(structureMap);
        operationSafetyChecklistDoc.setPageData((Map) structureMap);

        return operationSafetyChecklistDoc;
    }

    private List<String> operationSafetyChecklist_keyContrasts = Lists.newArrayList(
            "姓名++++患者姓名=姓名",
            "性别",
            "病区",
            "床号",
            "病案号++++住院号=病案号",
            "签名++++=签名"
    );

    /**
     * 给structureMap添加一个key（映射）
     *
     * @param structureMap
     * @param target       需要用到的key
     * @param source       structureMap中含有的key
     */
    protected void addKeyMapping(Map<String, String> structureMap, String target, String source) {
        if (StringUtils.isEmpty(structureMap.get(target)) && StringUtils.isNotEmpty(structureMap.get(source))) {
            structureMap.put(target, structureMap.get(source));
        }
    }

}