package com.lantone.qc.trans.taizhou;

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.trans.ModelDocTrans;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import com.lantone.qc.dbanaly.facade.taizhou.TzXmlUtil;

import java.util.List;
import java.util.Map;

/**
 * @Description: 输血/血制品病程记录文档生成
 * @author: rengb
 * @time: 2020/3/17 13:21
 */
public class TaiZhouClinicalBloodDocTrans extends ModelDocTrans {

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

    private ClinicalBloodDoc getClinicalBloodDoc(Map<String, Object> contentMap) {
        String content = contentMap.get("xmlText").toString();
        Map<String, String> sourceMap = TzXmlUtil.getXmlToMapForTZ(content);
        sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
        sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
        Map<String, String> structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, keyContrasts);

        ClinicalBloodDoc clinicalBloodDoc = new ClinicalBloodDoc();
        clinicalBloodDoc.setStructureMap(structureMap);
        clinicalBloodDoc.setPageData((Map) structureMap);
        return clinicalBloodDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
            "开始时间=输注开始",
            "医生=记录医师",
            "结束时间=输注结束",
            "病历日期=记录时间",
            "内容=输注后效果评价"
    );

}