package com.lantone.qc.trans.changx;

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

/**
 * @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<Map<String, Object>> contentMaps = (List) medrecVo.getContent().get("content");
        contentMaps.forEach(contentMap -> {
            retList.add(getClinicalBloodDoc(contentMap));
        });
        return retList;
    }
    private ClinicBloodEffectDoc getClinicalBloodDoc(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);


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

        return clinicBloodEffectDoc;
    }

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

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