package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.PathologyShipDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.dbanaly.facade.changx.CxXmlUtil;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;

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

/**
 * @ClassName : PathologyShipDocTrans
 * @Description : 病理检验送检单
 * @Author : 楼辉荣
 * @Date: 2020-04-19 17:49
 */
public class ChangxPathologyShipDocTrans extends ModelDocTrans {
    @Override
    public List<PathologyShipDoc> extract(MedrecVo medrecVo) {
        List<PathologyShipDoc> retList = Lists.newArrayList();
        List<Map<String, Object>> contentMaps = (List) medrecVo.getContent().get("content");
        contentMaps.forEach(contentMap -> {
            retList.add(getPathologyShipDoc(contentMap));
        });
        return retList;
    }

    private PathologyShipDoc getPathologyShipDoc(Map<String, Object> contentMap) {
        String content = contentMap.get("xmlText").toString();
        Map<String, String> sourceMap = CxXmlUtil.firstLevelNodeValue(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);

        PathologyShipDoc pathologyShipDoc = new PathologyShipDoc();
        pathologyShipDoc.setStructureMap(structureMap);
        pathologyShipDoc.setPageData((Map) structureMap);
        return pathologyShipDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
            "姓名++++患者姓名=姓名",
            "病案号++++住院号=病案号",
            "病区++++病区名称=病区",
            "数量=标本件数",
            "医师=送检医师",
            "++++送检材料=送检标本名称",
            "++++标本送检时间=标本离体时间",
            "++++取材部位=送检组织取材部位",
            "联系地址=病人详细通讯地址",
            "检查结果=辅助检查结果",
            "手术所见=术中发现",
            "传染性标本=是否为传染性标本",
            "日期=检验日期",
            "++++月经日期=末次月经日期"
    );

}