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.MedicalWritingDoc;
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 13:27
 */
public class ShaoyfMedicalWritingDocTrans extends ModelDocTrans {

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

    private MedicalWritingDoc getMedicalWritingDoc(Map<String, Object> contentMap) {
        String content = contentMap.get("xmlText").toString();
        Map<String, String> xmlNodeValueMap = ShaoyfXmlUtil.getXmlToMap(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);

        MedicalWritingDoc medicalWritingDoc = new MedicalWritingDoc();
        medicalWritingDoc.setStructureMap(structureMap);

        return medicalWritingDoc;
    }

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

}