package com.lantone.qc.trans.ywzxyy.util;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lantone.qc.dbanaly.facade.ywzxyy.YwzxyyXmlUtil;
import com.lantone.qc.trans.comsis.CommonAnalysisUtil;
import lombok.extern.slf4j.Slf4j;

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

/**
 * @Description:
 * @author: rengb
 * @time: 2021/1/25 14:04
 */
@Slf4j
public class YwzxyyLeaveHospitalXmlAnalysis implements YwzxyyXmlAnalysis {

    @Override
    public Map<String, String> analysis(String... args) {
        Map<String, String> structureMap = Maps.newHashMap();
        try {
            String xml = args[0];
            xml = xml.replace("</出院情况>出院情况", "</出院情况>出院去向");
            String text = YwzxyyXmlUtil.xml2Txt(xml);
            List<String> titles = CommonAnalysisUtil.sortTitles(
                    Lists.newArrayList("入院时间", "出院时间", "住院天数", "入院诊断", "出院诊断", "入院情况",
                            "住院经过", "出院情况", "出院去向", "出院医嘱", "健康教育", "随访计划", "医师签名", "签名时间"),
                    text
            );
            CommonAnalysisUtil.cutByTitles(text, titles, 0, structureMap);
            structureMap.put("入院日期", structureMap.get("入院时间"));
            structureMap.put("出院日期", structureMap.get("出院时间"));
            structureMap.put("记录时间", structureMap.get("签名时间"));
            structureMap.put("记录医生", structureMap.get("医师签名"));
            CommonAnalysisUtil.cutByTitles(structureMap.get("住院经过"), Lists.newArrayList("出院情况"), 0, structureMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return structureMap;
    }

}