package com.lantone.qc.trans.shaoyf;

import com.google.common.collect.Lists;
import com.lantone.qc.dbanaly.facade.shaoyf.ShaoyfXmlUtil;
import com.lantone.qc.pub.jdbc.MysqlJdbc;
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.pub.util.PropertiesUtil;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.trans.comsis.ModelDocGenerate;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;

import java.util.*;

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

/**
 * @Description: 首次病程录文档生成
 * @author: rengb
 * @time: 2020/3/17 13:25
 */
public class ShaoyfFirstCourseRecordDocTrans 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 = ShaoyfXmlUtil.getXmlToMap(content);
        sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
        sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
        if (sourceMap.get("主诊医生") != null) {
            sourceMap.put("主诊医生", sourceMap.get("主诊医生").replace("&amp;amp;nbsp;", ""));
        }
//        PropertiesUtil propertiesUtil = new PropertiesUtil("kernel.properties");
//        MysqlJdbc nlpJdbc = new MysqlJdbc(propertiesUtil.getProperty("mysql.redis.user"), propertiesUtil.getProperty("mysql.redis.password"), propertiesUtil.getProperty("mysql.redis.url"));
//
//        Map<String, Object> map = new HashMap<>();
//        map.put("ft", sourceMap.get("病例特点"));
//        List<Map<String, Object>> list = new ArrayList<>();
//        list.add(map);
//        nlpJdbc.insert(list, "ft_temp", new String[]{"ft"});
        Map<String, String> structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, keyContrasts);
        structureMap.put("记录时间",structureMap.get("病历日期"));
        // 病例特点=主诉+现病史-发病情况+专科检查+实验室检查+影像学检查+辅助检查结果+呼吸+脉搏+体温+血压
        //        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(
                        "本人姓名=姓名",
            "现病史- 发病情况=发病经过",
            "入院原因=主诉",
            "医生=医师签名",
            "治疗计划和措施=治疗计划",
            "体温(耳)=体温耳",
            "体温(口)=体温口"
    );

}