package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.DeathRecordDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.pub.util.StringUtil;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.dbanaly.facade.changx.CxXmlUtil;
import com.lantone.qc.trans.comsis.ModelDocGenerate;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import com.lantone.qc.trans.comsis.Preproc;

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

/**
 * @Description: 死亡记录文档生成
 * @author: rengb
 * @time: 2020/3/17 13:23
 */
public class ChangxDeathRecordDocTrans extends ModelDocTrans {

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

        Map<String, String> xmlNodeValueMap = CxXmlUtil.firstLevelNodeValue(content);
        xmlNodeValueMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
        xmlNodeValueMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
        Map<String, String> structureMap = OrdinaryAssistant.mapKeyContrast(xmlNodeValueMap, keyContrasts);

        String text = CxXmlUtil.getXmlText(content);
        Map<String, String> cutWordMap = Preproc.getCutWordMap(true, sourceTitles, text);
        cutWordMap.putAll(structureMap);

        DeathRecordDoc deathRecordDoc = ModelDocGenerate.deathRecordDocGen(cutWordMap);
        deathRecordDoc.setText(text);
        deathRecordDoc.setPageData((Map) cutWordMap);

        return deathRecordDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList(
            "姓名",
            "性别",
            "科别",
            "床号",
            "病案号",
            "年龄",
            "入院时间",
            "死亡时间",
            "入院情况",
            "发病经过",
            "入院诊断",
            "诊疗经过",
            "死亡原因",
            "死亡诊断",
            "记录医师",
            "记录时间"
    );

    private List<String> keyContrasts = Lists.newArrayList(
            "姓名++++患者姓名=姓名",
            "性别=",
            "病区++++病区名称=",
            "床号=",
            "病案号++++住院号=病案号",
            "入院时间=",
            "死亡时间=",
            "入院情况=",
            "入院诊断++++初步诊断=入院诊断",
            "诊疗经过=",
            "死亡原因=",
            "死亡诊断++++初步诊断=死亡诊断",
            "签名++++=记录医师",
            "签名时间=记录时间"
    );

}