package com.lantone.qc.trans.taizhou;

import com.google.common.collect.Lists;
import com.lantone.qc.dbanaly.facade.taizhou.TzXmlUtil;
import com.lantone.qc.pub.model.doc.AnesthesiaRelatedDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.pub.util.FastJsonUtils;
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 13:27
 */
public class TaiZhouAnesthesiaRelatedDocTrans extends ModelDocTrans {
    private String modeId = "12";

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

    private AnesthesiaRelatedDoc getAnesthesiaRelatedDoc(Map<String, Object> contentMap) {
        String content = contentMap.get("xmlText").toString();
        Map<String, String> structureMap = null;
        if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
            structureMap = (Map) FastJsonUtils.getJsonToMap(content);
        } else {
            Map<String, String> xmlNodeValueMap = TzXmlUtil.getXmlToMapForTZ(content);
            xmlNodeValueMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            xmlNodeValueMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            structureMap = OrdinaryAssistant.mapKeyContrast(xmlNodeValueMap, keyContrasts, modeId);
        }

        AnesthesiaRelatedDoc anesthesiaRelatedDoc = new AnesthesiaRelatedDoc();
        anesthesiaRelatedDoc.setStructureMap(structureMap);

        return anesthesiaRelatedDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList();

}