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

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lantone.qc.pub.util.StringUtil;
import com.lantone.qc.trans.comsis.CommonAnalysisUtil;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

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

/**
 * @Description: 病危（重）通知单html解析
 * @author: HUJING
 * @time: 2020/9/14 15:28
 */
@Slf4j
public class BeiLunCriticallyIllNoticeHtmlAnalysis implements BeiLunHtmlAnalysis {

    private String modeId = "25";

    @Override
    public Map<String, String> analysis(String... args) {
        Map<String, String> structureMap = Maps.newLinkedHashMap();

        try {
            List<String> titles = Lists.newArrayList("姓名", "性别", "出生日期", "科别", "病区", "床号", "住院号",
                    "临床诊断", "病情摘要", "主要症状", "体格检查", "辅助检查", "告知医师签名",
                    "告知时间", "患方意见", "患方签名", "手印说明", "与患者关系", "签字时间");
            String html = args[0];
            String recTitle = args[1];
            String recTypeId = args[2];
            Document doc = Jsoup.parse(html);
            String htmlContent = BeiLunHtmlAnalysisUtil.blockDivToStr(doc.selectFirst("body").child(0), true);
            if (StringUtil.isNotBlank(htmlContent)) {
                htmlContent = htmlContent.replaceAll("[   ]", " ");
                CommonAnalysisUtil.html2StructureMap(titles, htmlContent, structureMap);
            }
            CommonAnalysisUtil.extractDateByTitle(structureMap, "告知时间");
            BeiLunHtmlAnalysisUtil.insertModuleId(modeId, recTypeId, structureMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return structureMap;
    }

}