package com.lantone.qc.trans.taizhou;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.FirstCourseRecordDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.pub.util.MapUtil;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.trans.comsis.ModelDocGenerate;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import com.lantone.qc.dbanaly.facade.taizhou.TzXmlUtil;

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

import static com.lantone.qc.trans.comsis.ModelDocGenerate.structureMapJoin;

/**
 * @Description: 首次病程录文档生成
 * @author: rengb
 * @time: 2020/3/17 13:25
 */
public class TaiZhouFirstCourseRecordDocTrans extends ModelDocTrans {

    @Override
    public FirstCourseRecordDoc extract(MedrecVo medrecVo) {
        Map<String, Object> contentMap = ((List<Map>) medrecVo.getContent().get("content")).get(0);
        String content = contentMap.get("xmlText").toString();

        Map<String, String> sourceMap = TzXmlUtil.getXmlToMapForTZ(content);
        sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
        sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
        Map<String, String> structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, keyContrasts);
        // 病例特点=主诉+现病史-发病情况+专科检查+实验室检查+影像学检查+辅助检查结果+呼吸+脉搏+体温+血压
        //        structureMap.put("病例特点", MapUtil.getSelectString(structureMap, Arrays.asList(
        //                "主诉",
        //                "现病史-发病情况",
        //                "专科检查",
        //                "实验室检查",
        //                "影像学检查",
        //                "辅助检查结果",
        //                "呼吸",
        //                "脉搏",
        //                "体温",
        //                "血压"
        //                ))
        //        );
        // 诊断依据=性别+年龄+主诉+现病史-发病情况+专科检查+实验室检查+影像学检查+辅助检查结果+呼吸+脉搏+体温+血压
        //        structureMap.put("诊断依据", MapUtil.getSelectString(structureMap, Arrays.asList(
        //                "性别",
        //                "年龄",
        //                "主诉",
        //                "现病史-发病情况",
        //                "专科检查",
        //                "实验室检查",
        //                "影像学检查",
        //                "辅助检查结果",
        //                "呼吸",
        //                "脉搏",
        //                "体温",
        //                "血压"
        //                ))
        //        );
        // 诊疗计划=检查计划+治疗计划和措施
        structureMap.put("诊疗计划-crf", MapUtil.getSelectString(structureMap, Arrays.asList(
                "检查计划",
                "治疗计划和措施"
                ))
        );

        // 诊疗计划
        FirstCourseRecordDoc firstCourseRecordDoc = ModelDocGenerate.firstCourseRecordDocGen(structureMap);
        firstCourseRecordDoc.setPageData((Map) structureMap);
        List<String> keys = Lists.newArrayList("检查计划", "治疗计划");
        String treatPlanJoin = structureMapJoin(structureMap, keys);
        firstCourseRecordDoc.getTreatPlanLabel().setAiText(treatPlanJoin);
        return firstCourseRecordDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
                        "本人姓名=姓名",
            "现病史- 发病情况=现病史",
            "现病史- 发病情况=现病史",
            "医生=医师签名",
            "治疗计划和措施=治疗计划",
            "体温(耳)=体温耳",
            "体温(口)=体温口",
            "病历日期=记录时间"
    );

}