package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.LeaveHospitalDoc;
import com.lantone.qc.pub.model.label.LeaveHospitalDoctorAdviceLabel;
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.ModelDocGenerate;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import org.apache.commons.lang3.StringUtils;

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

/**
 * @Description: 出院小结文档生成
 * @author: rengb
 * @time: 2020/3/17 13:25
 */
public class ChangxLeaveHospitalDocTrans extends ModelDocTrans {

    @Override
    public LeaveHospitalDoc extract(MedrecVo medrecVo) {
        Map<String, Object> contentMap = ((List<Map>) medrecVo.getContent().get("content")).get(0);
        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);
        LeaveHospitalDoc leaveHospitalDoc = ModelDocGenerate.leaveHospitalDocGen(structureMap);

        if (StringUtils.isNotEmpty(structureMap.get("出院医嘱"))) {
            LeaveHospitalDoctorAdviceLabel leaveHospitalDoctorAdviceLabel = new LeaveHospitalDoctorAdviceLabel();
            leaveHospitalDoctorAdviceLabel.setText(structureMap.get("出院医嘱"));
            leaveHospitalDoctorAdviceLabel.setAiText(structureMap.get("出院医嘱"));
            leaveHospitalDoc.setLeaveHospitalDoctorAdviceLabel(leaveHospitalDoctorAdviceLabel);
        }
        leaveHospitalDoc.setText(CxXmlUtil.getXmlText(content));
        leaveHospitalDoc.setPageData((Map) structureMap);
        return leaveHospitalDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
            "患者姓名=姓名",
            "性别=",
            "病区++++病区名称=",
            "床号=",
            "病案号++++住院号=",
            "年龄=",
            "入院日期=入院时间",
            "出院日期=出院时间",
            "入院诊断=入院诊断",
            "出院诊断=出院诊断",
            "实际住院天数=住院天数",
            "入院情况=入院情况",
            "诊治经过++++入院诊治经过=诊治经过",
            "出院情况=",
            "出院医嘱=",
            /*           "健康教育=注意事项",*/
            "随访计划=",
            "签名++++=医师签名",
            "签名时间=签名时间",
            "日期=出院时间"
    );

}