package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.ClinicalBloodDoc;
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/17 13:21
 */
public class ChangxClinicalBloodDocTrans extends ModelDocTrans {

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

    private ClinicalBloodDoc getClinicalBloodDoc(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);


        ClinicalBloodDoc clinicalBloodDoc = ModelDocGenerate.clinicalBloodDocGen(cutWordMap);
        clinicalBloodDoc.setText(text);
        clinicalBloodDoc.setPageData((Map) xmlNodeValueMap);

        return clinicalBloodDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList(
            "输注原因",
            "输注时间",
            "输注开始",
            "输注结束",
            "输注种类、血型、数量",
            "输注过程",
            "输注后效果评价",
            "记录医师",
            "记录时间"
    );

    private List<String> keyContrasts = Lists.newArrayList(
            "记录日期=记录时间",
            "输注原因=",
            "输注开始=",
            "输注结束=",
            "输注种类、血型、数量=",
            "输注过程=",
            "签名++++=记录医师",
            "签名时间="
    );

}