package com.lantone.qc.trans.changx;

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

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

    private RescueDoc getRescueDoc(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);

        RescueDoc rescueDoc = ModelDocGenerate.rescueDocGen(cutWordMap);
        rescueDoc.setText(text);
        rescueDoc.setPageData((Map) cutWordMap);

        return rescueDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList(
            "抢救时间",
            "记录时间",
            "记录医师",
            "抢救过程",
            "参与人员"
    );

    private List<String> keyContrasts = Lists.newArrayList(
            "记录日期=记录时间",
            "病情变化情况=",
            "抢救时间及措施++++抢救措施=",
            "参加抢救者的姓名及专业技术职称++++参加现场抢救的医师及护理人员=参与人员",
            "签名++++=记录医师",
            "签名时间=抢救时间"
//            "参与人员=参加人员及职称"
    );

}