package com.lantone.qc.trans.ninghaiyiyi.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:
 * @author: HUJING
 * @time: 2020/9/9 11:24
 */
@Slf4j
public class NingHaiYiYiFirstCourseRecordHtmlAnalysis implements NingHaiYiYiHtmlAnalysis {

    private String modeId = "2";

    @Override
    public Map<String, String> analysis(String... args) {
        Map<String, String> structureMap = Maps.newLinkedHashMap();
        try {
            List<String> titles = Lists.newArrayList("一. 病例特点", "二. 拟诊讨论", "三. 诊疗计划","三、诊疗计划", "医师签名");
            Document doc = Jsoup.parse(args[0]);
            String htmlContent = NingHaiYiYiHtmlAnalysisUtil.blockDivToStr(doc.selectFirst("body").child(0), true);
            if (StringUtil.isNotBlank(htmlContent)) {
                CommonAnalysisUtil.html2StructureMap(titles, htmlContent, structureMap);
            }
            if (structureMap.containsKey("二.拟诊讨论")) {
                List<String> listTitle = CommonAnalysisUtil.sortTitles(
                        Lists.newArrayList("1.初步诊断", "2.诊断依据", "3.鉴别诊断"
                                ,"诊断依据","鉴别诊断","初步诊断"), structureMap.get("二.拟诊讨论")
                );
                CommonAnalysisUtil.cutByTitles(structureMap.get("二.拟诊讨论"), listTitle, 0, structureMap);
            }
            NingHaiYiYiHtmlAnalysisUtil.insertModuleId(modeId, args[2], structureMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return structureMap;
    }

}