package com.lantone.qc.trans.changx;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.DailyCourseRecordDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.pub.util.StringUtil;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.dbanaly.facade.changx.CxXmlUtil;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import com.lantone.qc.trans.comsis.Preproc;

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

/**
 * @Description: 日常病程录文档生成
 * @author: rengb
 * @time: 2020/3/17 17:34
 */
public class ChangxDailyCourseRecordDocTrans extends ModelDocTrans {

    @Override
    public List<DailyCourseRecordDoc> extract(MedrecVo medrecVo) {
        List<DailyCourseRecordDoc> retList = Lists.newArrayList();
        List<Map<String, Object>> contentMaps = (List) medrecVo.getContent().get("content");
        contentMaps.forEach(contentMap -> {
            retList.add(getDailyCourseRecordDoc(contentMap));
        });
        return retList;
    }

    private DailyCourseRecordDoc getDailyCourseRecordDoc(Map<String, Object> contentMap) {
        String content = contentMap.get("xmlText").toString();
        Map<String, String> xmlNodeValueMap = CxXmlUtil.firstLevelNodeValue(content);
        xmlNodeValueMap.put("mode_id=" + contentMap.get("modeId").toString(), "");
        xmlNodeValueMap.put("rec_title=" + contentMap.get("recTitle").toString(), "");
        Map<String, String> structureMap = OrdinaryAssistant.mapKeyContrast(xmlNodeValueMap, keyContrasts);

        String text = CxXmlUtil.getXmlText(content);
        Map<String, String> cutWordMap = Preproc.getCutWordMap(true, sourceTitles, text);
        cutWordMap.putAll(structureMap);

        DailyCourseRecordDoc dailyCourseRecordDoc = new DailyCourseRecordDoc();
        dailyCourseRecordDoc.setText(text);
        dailyCourseRecordDoc.setPageData((Map) cutWordMap);

        return dailyCourseRecordDoc;
    }

    private List<String> sourceTitles = Lists.newArrayList();

    private List<String> keyContrasts = Lists.newArrayList(
            "日常病程记录++++文本框=病程记录内容",
            "签名++++=签名"
    );

}