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

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

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

/**
 * @Description:
 * @author: rengb
 * @time: 2020/9/17 14:27
 */
@Slf4j
public class BeiLunDeathCaseDiscussHtmlAnalysis implements BeiLunHtmlAnalysis {

    private String modeId = "3";

    @Override
    public Map<String, String> analysis(String... args) {
        Map<String, String> map = Maps.newLinkedHashMap();
        try {
            String html = args[0];
            String recTypeId = args[2];
            Document doc = Jsoup.parse(html);
            Element bigDivElement = doc.selectFirst("body").child(0);

            bigDivElement.child(0).lastElementSibling().remove();
            map.put("医生签名时间", BeiLunHtmlAnalysisUtil.elementLayer1ToStr(bigDivElement.child(0).lastElementSibling(), false));
            bigDivElement.child(0).lastElementSibling().remove();

            String text = BeiLunHtmlAnalysisUtil.blockDivToStr(bigDivElement, false);
            List<String> titles = Lists.newArrayList("姓名", "性别", "出生日期", "科别", "病区", "床号", "住院号",
                    "入院诊断", "死亡诊断", "尸检结果", "讨论时间", "讨论地点",
                    "主 持 人", "参加人员", "具体讨论意见", "主持人小结意见", "主持人（签名）", "记录者签名");
            CommonAnalysisUtil.cutByTitlesNoColon(text, titles, 0, map);
            BeiLunHtmlAnalysisUtil.mapValueRemoveStartColon(map);
            BeiLunHtmlAnalysisUtil.insertModuleId(modeId, recTypeId, map);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return map;
    }

}