package com.lantone.facade.cdss;

import com.diagbot.dto.RespDTO;
import com.diagbot.exception.CommonErrorCode;
import com.diagbot.exception.CommonException;
import com.diagbot.util.RespDTOUtil;
import com.diagbot.util.StringUtil;
import com.lantone.client.CdssCoreClient;
import com.lantone.dto.med.RetrievalDTO;
import com.lantone.vo.cdss.RetrievalVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author:zhaops
 * @time: 2020/8/12 16:44
 */
@Component
public class CdssRetrievalFacade {
    @Autowired
    private CdssCoreClient cdssCoreClient;

    /**
     * 检索
     *
     * @param retrievalVO
     * @return
     */
    public RetrievalDTO index(RetrievalVO retrievalVO) {
        RetrievalDTO retrievalDTO = new RetrievalDTO();
        if (null == retrievalVO
                || (null != retrievalVO
                && (null == retrievalVO.getHospitalId() || retrievalVO.getHospitalId().equals(-1L)))) {
            //无医院或者朗通医院查询标准词
            RespDTO<RetrievalDTO> respDTO = cdssCoreClient.index(retrievalVO);
            RespDTOUtil.respNGDealCover(respDTO, "检索失败");
            retrievalDTO = respDTO.data;
        } else {
            //实际医院查询医院词
            if (retrievalVO.getDefaultList().equals(0)
                    && StringUtil.isBlank(retrievalVO.getInputStr())) {
                throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入检索内容！");
            }
            /*HospitalCheckVO hospitalCheckVO = new HospitalCheckVO();
            hospitalCheckVO.setHospitalId(retrievalVO.getHospitalId());
            if (!hospitalInfoFacade.checkHospital(hospitalCheckVO)) {
                throw new CommonException(CommonErrorCode.NOT_EXISTS, "该医院ID不存在或者未启用！");
            }
            else {
                switch (retrievalVO.getType()) {
                    case 2:
                        retrievalDTO.setLisDetailNames(mappingConfigFacade.getHisDetailNames(retrievalVO));
                        break;
                    case 1:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                    case 14:
                    case 16:
                        List<RetrievalConceptDTO> hisNameList = new ArrayList<>();
                        List<String> hisNames = mappingConfigFacade.getHisNames(retrievalVO);
                        for (String str : hisNames) {
                            RetrievalConceptDTO data = new RetrievalConceptDTO();
                            data.setName(str);
                            hisNameList.add(data);
                        }
                        retrievalDTO.setNameList(hisNameList);
                        break;

                }
            }*/
        }
        return retrievalDTO;
    }
}