package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.StagesSummaryDoc;
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.trans.changx.util.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/19 19:41
 */
public class ChangxStagesSummaryDocTrans extends ModelDocTrans {

    @Override
    public List<StagesSummaryDoc> extract(MedrecVo medrecVo) {
        List<StagesSummaryDoc> retList = Lists.newArrayList();
        List<String> contents = (List) medrecVo.getContent().get("content");
        contents.forEach(content -> {
            retList.add(getStagesSummaryDoc(content));
        });
        return retList;
    }

    private StagesSummaryDoc getStagesSummaryDoc(String content) {
        Map<String, String> xmlNodeValueMap = CxXmlUtil.firstLevelNodeValue("//DocObjContent//Region", content);
        Map<String, String> structureMap = OrdinaryAssistant.mapKeyContrast(xmlNodeValueMap, keyContrasts);

        String text = CxXmlUtil.getTextByNodePath(content, "//DocObjContent/Region/Content_Text");
        if (StringUtil.isBlank(text)) {
            text = CxXmlUtil.getTextByNodePath(content, "//DocObjContent/Region");
        }
        Map<String, String> cutWordMap = Preproc.getCutWordMap(true, sourceTitles, text);
        cutWordMap.putAll(structureMap);

        StagesSummaryDoc stagesSummaryDoc = ModelDocGenerate.stagesSummaryDocGen(cutWordMap);
        stagesSummaryDoc.setText(text);
        stagesSummaryDoc.setPageData((Map) xmlNodeValueMap);

        return stagesSummaryDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList(
            "记录日期",
            "患者姓名（住院）",
            "性别",
            "年龄",
            "原因",
            "入院日期",
            "入院情况",
            "入院诊断",
            "治疗经过",
            "目前情况",
            "目前诊断",
            "诊疗计划",
            "签名",
            "签名时间"
    );

    private List<String> keyContrasts = Lists.newArrayList(
            "记录日期=",
            "患者姓名（住院）=",
            "性别=",
            "年龄=",
            "原因=",
            "入院日期=",
            "入院情况=",
            "入院诊断++++初步诊断=入院诊断",
            "治疗经过=",
            "目前情况=",
            "目前诊断=",
            "诊疗计划++++下一步诊疗计划=诊疗计划",
            "签名++++=签名",
            "签名时间="
    );

}