package com.lantone.qc.trans.yiwu;

import com.google.common.collect.Lists;
import com.lantone.qc.dbanaly.facade.yiwu.YiWuXmlUtil;
import com.lantone.qc.dbanaly.util.ModuleMappingUtil;
import com.lantone.qc.pub.model.doc.DifficultCaseDiscussDoc;
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.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description: 疑难病例讨论记录文档生成
 * @author: rengb
 * @time: 2020/3/17 13:23
 */
public class YiWuDifficultCaseDiscussDocTrans extends ModelDocTrans {
    private String modeId = "19";

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

    private DifficultCaseDiscussDoc getDifficultCaseDiscussDoc(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> sourceMap = YiWuXmlUtil.xmlToMap(content);
            List<String> titles =Lists.newArrayList("记录人","主持人");
            sourceMap.put("mode_id", ModuleMappingUtil.getDeptModuleId(modeId));
            sourceMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
            sourceMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
            structureMap = OrdinaryAssistant.mapKeyContrast(sourceMap, keyContrasts, modeId);
        }

        DifficultCaseDiscussDoc difficultCaseDiscussDoc = new DifficultCaseDiscussDoc();
        difficultCaseDiscussDoc.setStructureMap(structureMap);
        difficultCaseDiscussDoc.setPageData((Map) structureMap);

        return difficultCaseDiscussDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
            "医生=记录者",
            "讨论小结=主持人小结",
            "讨论意见=具体讨论意见",
            "讨论日期时间=讨论日期",
            "本人姓名=姓名",
            "参加人员及职称（护士）=参加人员的姓名及专业技术职务",
            "患者姓名=姓名",
            "性别代码=性别",
            "年龄 (岁)=年龄",
            "当前科室=科别",
            "主持人姓名=主持人姓名及专业技术职务",
            "参加讨论人员名单=参加人员的姓名及专业技术职务",
            "讨论内容=具体讨论意见",
            "讨论时间=讨论日期"
    );

}