package com.diagbot.facade;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.dto.BasDeptInfoDTO;
import com.diagbot.dto.BehInfoForH5DTO;
import com.diagbot.dto.DeptNumDTO;
import com.diagbot.dto.EntryNumDTO;
import com.diagbot.dto.LevelPercentDTO;
import com.diagbot.exception.CommonErrorCode;
import com.diagbot.exception.CommonException;
import com.diagbot.util.StringUtil;
import com.diagbot.util.SysUserUtils;
import com.diagbot.vo.BasDeptInfoVO;
import com.diagbot.vo.BehInfoForH5VO;
import com.diagbot.vo.FilterVO;
import com.diagbot.vo.HospitalIdVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @Author:zhaops
 * @time: 2022/5/6 10:40
 */
@Component
public class StatisticsForH5Facade {
    @Autowired
    private QcresultInfoFacade qcresultInfoFacade;
    @Autowired
    private BehospitalInfoFacade behospitalInfoFacade;
    @Autowired
    private BasDeptInfoFacade basDeptInfoFacade;

    /**
     * 单项否决占比
     *
     * @param filterVO
     * @return
     */
    public List<EntryNumDTO> entryRejectDistribution(FilterVO filterVO) {
        if (StringUtil.isBlank(filterVO.getHospitalId())) {
            try {
                String hospitalId = SysUserUtils.getCurrentHospitalID();
                filterVO.setHospitalId(hospitalId);
            } catch (Exception e) {
                throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院id");
            }
        }
        if (StringUtil.isBlank(filterVO.getHospitalId())) {
            throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院id");
        }
        List<EntryNumDTO> retList = qcresultInfoFacade.entryRejectPercent(filterVO);
        return retList;
    }

    /**
     * 病历等级占比
     *
     * @param filterVO
     * @return
     */
    public List<LevelPercentDTO> levelDistribution(FilterVO filterVO) {
        if (StringUtil.isBlank(filterVO.getHospitalId())) {
            try {
                String hospitalId = SysUserUtils.getCurrentHospitalID();
                filterVO.setHospitalId(hospitalId);
            } catch (Exception e) {
                throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院id");
            }
        }
        List<LevelPercentDTO> retList = qcresultInfoFacade.levelPercentByDept(filterVO);
        return retList;
    }

    /**
     * 病历扣分大于等于5占比
     *
     * @param filterVO
     * @return
     */
    public List<DeptNumDTO> deductGT5Distribution(FilterVO filterVO) {
        if (StringUtil.isBlank(filterVO.getHospitalId())) {
            try {
                String hospitalId = SysUserUtils.getCurrentHospitalID();
                filterVO.setHospitalId(hospitalId);
            } catch (Exception e) {
                throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院id");
            }
        }
        List<DeptNumDTO> retList = qcresultInfoFacade.deductGT5ByDept(filterVO);
        return retList;
    }


    /**
     * 病历详情
     *
     * @param behInfoForH5VO
     * @return
     */
    public IPage<BehInfoForH5DTO> getBehInfoPage(BehInfoForH5VO behInfoForH5VO) {
        if (StringUtil.isBlank(behInfoForH5VO.getHospitalId())) {
            try {
                String hospitalId = SysUserUtils.getCurrentHospitalID();
                behInfoForH5VO.setHospitalId(hospitalId);
            } catch (Exception e) {
                throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院id");
            }
        }
        IPage<BehInfoForH5DTO> page = behospitalInfoFacade.behospitalInfoForH5(behInfoForH5VO);
        return page;
    }

    /**
     * @param hospitalIdVO
     * @return
     */
    public List<BasDeptInfoDTO> listForUser(HospitalIdVO hospitalIdVO) {
        BasDeptInfoVO basDeptInfoVO = new BasDeptInfoVO();
        basDeptInfoVO.setHospitalId(hospitalIdVO.getHospitalId());
        List<BasDeptInfoDTO> basDeptInfoDTOList = basDeptInfoFacade.getList(basDeptInfoVO);
        return basDeptInfoDTOList;
    }
}
