package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
import com.lantone.qc.pub.model.doc.ClinicBloodEffectDoc;
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;

/**
 * @author 王宇
 * @create 2020-04-30 12:39
 * @desc 输血后效果评价
 **/
public class ChangxClinicBloodEffectDocTrans extends ModelDocTrans {
    @Override
    public List<ClinicBloodEffectDoc> extract(MedrecVo medrecVo) {
        List<ClinicBloodEffectDoc> retList = Lists.newArrayList();
        List<String> contents = (List) medrecVo.getContent().get("content");
        contents.forEach(content -> {
            retList.add(getClinicalBloodDoc(content));
        });
        return retList;
    }
    private ClinicBloodEffectDoc 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);


        ClinicBloodEffectDoc clinicBloodEffectDoc = ModelDocGenerate.clinicBloodEffectDoc(cutWordMap);
        clinicBloodEffectDoc.setText(text);
        clinicBloodEffectDoc.setPageData((Map) xmlNodeValueMap);

        return clinicBloodEffectDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList(
            "输注时间",
            "输注后效果评价",
            "记录医师",
            "记录时间"
    );

    private List<String> keyContrasts = Lists.newArrayList(
            "记录日期=记录时间",
            "签名++++=记录医师",
            "签名时间=",
            "输血效果评价=输注后效果评价"
    );
}
