package com.lantone.structure.facade;

import com.lantone.common.util.StringUtil;
import com.lantone.structure.dto.AnalysisDTO;
import com.lantone.structure.facade.tran.*;
import com.lantone.structure.vo.AnalysisVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description:
 * @author: rengb
 * @time: 2020/12/18 16:22
 */
@Slf4j
@Component
public class StructureFacade {

    public AnalysisDTO analysis(AnalysisVO analysisVO) {
        AnalysisDTO analysisDTO = new AnalysisDTO();
        TargetTran targetTran = null;
        switch (analysisVO.getType()) {
            case "剖宫产记录":
                targetTran = new CesareanSectionTran();
                break;
            case "输血记录":
                targetTran = new ClinicalBloodTran();
                break;
            case "抢救记录":
                targetTran = new RescueTran();
                break;
            case "阶段小结":
                targetTran = new StagesSummaryTran();
                break;
            case "死亡病例讨论记录":
                targetTran = new DeathCaseDiscussionTran();
                break;
            case "死亡记录":
                targetTran = new DeathRecordTran();
                break;
            case "出院小结":
                targetTran = new LeaveHospitalTran();
                break;
            case "术前小结":
                targetTran = new PreoperativeDiscussionTran();
                break;
            case "转科记录":
                targetTran = new TransferRecordTran();
                break;
            case "交接班记录":
                targetTran = new DutyShiftSystemTran();
                break;
            case "疑难病例讨论记录":
                targetTran = new DifficultCaseDiscussTran();
                break;
            case "上级医师查房记录":
                targetTran = new ThreeLevelWardTran();
                break;
            case "入院记录":
                targetTran = new BeHospitalizedTran();
                break;
            case "24h内入出院记录":
                targetTran = new BeHospitalizedTran();
                break;
            case "24h内入院死亡记录":
                targetTran = new DeathRecordTran();
                break;
            case "首次病程记录":
                targetTran = new FirstCourseRecordTran();
                break;
            case "病危通知书":
                targetTran = new CriticallyIllNoticeDocTran();
                break;
            case "手术知情同意书":
                targetTran = new OperationInformedConsentDocTran();
                break;
            case "会诊记录":
                targetTran = new ConsultationTran();
                break;
            case "其他知情告知同意书":
                targetTran = new InformedConsentTran();
                break;
            case "输血治疗同意书":
                targetTran = new ClinicBloodConsentDocTran();
                break;
            case "特殊检查及特殊治疗同意书":
                targetTran = new SpecialCureConsentDocTran();
                break;
            case "一般手术记录":
                targetTran = new OperationRecordDocTran();
                break;
            case "术前讨论":
                targetTran = new PreoperativeDiscussionTran();
                break;
            case "术后首次病程记录":
                targetTran = new OperationDiscussionTran();
                break;
            case "日常病程记录":
                targetTran = new DailyCourseRecordTran();
                break;
            default:
                break;
        }
        try {
            Map<String, String> result = targetTran.convert(analysisVO.getText());
            resultHandle(result);
            analysisDTO.setResult(result);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return analysisDTO;
    }

    private void resultHandle(Map<String, String> result) {
        if (MapUtils.isEmpty(result)) {
            return;
        }
        result.forEach((key, value) -> {
            if (StringUtil.isNotBlank(value)) {
                value = StringUtil.trim(value);
                if (value.endsWith("；") || value.endsWith(";")) {
                    value = value.substring(0, value.length() - 1);
                }
                result.put(key, value);
            }
        });
    }

}