package com.lantone.qc.trans.shaoyf;

import com.google.common.collect.Lists;
import com.lantone.qc.dbanaly.facade.shaoyf.ShaoyfXmlUtil;
import com.lantone.qc.pub.model.doc.RescueDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;

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

/**
 * @Description: 抢救记录文档生成
 * @author: rengb
 * @time: 2020/3/17 17:34
 */
public class ShaoyfRescueDocTrans 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> sourceMap = ShaoyfXmlUtil.getXmlToMap(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);

        RescueDoc rescueDoc = new RescueDoc();
        rescueDoc.setStructureMap(structureMap);
        rescueDoc.setPageData((Map) structureMap);

        return rescueDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
            "事件日期=抢救开始时间",
            "本人姓名=姓名"
    );

}