package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.dto.GetDiseaseIcdDTO;
import com.diagbot.entity.DiseaseIcd;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.DiseaseIcdServiceImpl;
import com.diagbot.util.EntityUtil;
import com.diagbot.vo.GetDiseaseIcdVO;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: wangyu
 * @time: 2019/2/14 15:25
 */
@Component
public class TranDiseaseIcdFacade extends DiseaseIcdServiceImpl {

    /**
     * 根据医院编号和诊断ids获取各自的icd编码
     *
     * @param getDiseaseIcdVO
     * @return
     */
    public List<GetDiseaseIcdDTO> getDiseaseIcds(GetDiseaseIcdVO getDiseaseIcdVO) {
        Map paramMap = new HashMap<>();
        paramMap.put("questions", Arrays.asList(getDiseaseIcdVO.getQuestions().split(",")));
        paramMap.put("hospitalCode", getDiseaseIcdVO.getHospitalCode());
        return this.getDiseaseIcds(paramMap);
    }

    /**
     * 根据医院编码获取疾病映射关系 Map<icssName,diseaseName>
     *
     * @return
     */
    public Map<String, String> getDiseaseIcdByHosCode(String hosCode) {
        QueryWrapper<DiseaseIcd> diseaseIcdQueryWrapper = new QueryWrapper<>();
        diseaseIcdQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("hospital_code",hosCode);
        List<DiseaseIcd> diseaseIcdList = this.list(diseaseIcdQueryWrapper);
        Map<String, String> retMap= EntityUtil.makeMapWithKeyValue(diseaseIcdList, "icssQuestionName", "diseaseName");
        return retMap;
    }
}