package com.lantone.qc.trans.xiamen;

import com.google.common.collect.Lists;
import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
import com.lantone.qc.pub.model.vo.MedrecVo;
import com.lantone.qc.pub.util.FastJsonUtils;
import com.lantone.qc.trans.ModelDocTrans;
import com.lantone.qc.trans.comsis.ModelDocGenerate;
import com.lantone.qc.trans.comsis.OrdinaryAssistant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;

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

/**
 * @Description: 入院记录文档生成
 * @author: rengb
 * @time: 2020/3/5 15:47
 */
@Slf4j
public class XiamenBeHospitalizedDocTrans extends ModelDocTrans {

    @Override
    public BeHospitalizedDoc extract(MedrecVo medrecVo) {
        BeHospitalizedDoc beHospitalizedDoc = null;
        try {
            Map<String, Object> contentMap = ((List<Map>) medrecVo.getContent().get("content")).get(0);
            String content = contentMap.get("xmlText").toString();
            Map<String, String> structureMap = null;
            if (contentMap.get("isParsed") != null && "1".equals(contentMap.get("isParsed").toString())) {
                structureMap = (Map) FastJsonUtils.getJsonToMap(content);
                structureMap = OrdinaryAssistant.mapKeyContrast(structureMap, keyContrasts, "1");
            }
            if (MapUtils.isNotEmpty(structureMap)) {
                beHospitalizedDoc = ModelDocGenerate.beHospitalizedDocGen(structureMap);
                beHospitalizedDoc.setPageData((Map) structureMap);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return beHospitalizedDoc;
    }

    private List<String> keyContrasts = Lists.newArrayList(
            "出生地=籍贯",
            "婚姻状况=婚姻",
            "既往史|过敏史=过敏史",
            "病历日期=记录时间",
            "户口地址=住址",
            "病历日期=记录日期",
            "病历|体格检查=体格检查",
            "病史陈述人=病史陈述者",
            "病史可靠程度=可靠程度"
    );

}