package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.DifficultCaseDiscussDoc;
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 ChangxDifficultCaseDiscussDocTrans extends ModelDocTrans {

    @Override
    public List<DifficultCaseDiscussDoc> extract(MedrecVo medrecVo) {
        List<DifficultCaseDiscussDoc> retList = Lists.newArrayList();
        List<Map<String, Object>> contentMaps = (List) medrecVo.getContent().get("content");
        contentMaps.forEach(contentMap -> {
            retList.add(getDifficultCaseDiscussDoc(contentMap));
        });
        return retList;
    }

    private DifficultCaseDiscussDoc getDifficultCaseDiscussDoc(Map<String, Object> contentMap) {
        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);

        DifficultCaseDiscussDoc difficultCaseDiscussDoc = ModelDocGenerate.difficultCaseDiscussDocGen(cutWordMap);
        difficultCaseDiscussDoc.setText(content);
        difficultCaseDiscussDoc.setPageData((Map) cutWordMap);

        return difficultCaseDiscussDoc;
    }

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

    private List<String> keyContrasts = Lists.newArrayList(
          "讨论日期=讨论时间",
          "人员及专业技术职务++++专业技术职务=参加讨论者",
          "患者病情汇报=简要病情",
          "讨论结果++++主持人小结意见=结论",
          "签名++++=签名",
            "患者病情汇报=讨论内容"
    );

}