package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.DeathCaseDiscussDoc;
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:22
 */
public class ChangxDeathCaseDiscussDocTrans extends ModelDocTrans {

    @Override
    public DeathCaseDiscussDoc 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);

        DeathCaseDiscussDoc deathCaseDiscussDoc = ModelDocGenerate.deathCaseDiscussDocGen(cutWordMap);
        deathCaseDiscussDoc.setText(text);
        deathCaseDiscussDoc.setPageData((Map) cutWordMap);

        return deathCaseDiscussDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList(
            "记录时间",
            "记录医师",
            "入院时间",
            "死亡时间",
            "出院时间",
            "入院诊断",
            "死亡诊断",
            "讨论时间",
            "讨论地点",
            "参加讨论人员",
            "讨论主持人",
            "讨论内容",
            "死亡原因",
            "结论"
    );

    private List<String> keyContrasts = Lists.newArrayList(
            "记录日期=记录时间",
            "讨论时间=",
            "主持人=讨论主持人",
            "参加人员姓名=参加讨论人员",
            "讨论内容=",
            "主持人小结++++主持人小结意见=结论",
            "签名++++=记录医师",
            "签名时间="
    );

}