package com.diagbot.facade;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import com.diagbot.dto.GetTopPatientInfoDTO;
import com.diagbot.dto.PatientInfoDTO;
import com.diagbot.entity.PatientInfo;
import com.diagbot.service.impl.PatientInfoServiceImpl;
import com.diagbot.util.DateUtil;
import com.diagbot.vo.GetTopPatientInfoVO;
import com.diagbot.vo.PatientInfoVO;

/**
 * @Description: 患者业务逻辑
 * @author: wangyu
 * @time: 2018/11/19 13:19
 */
@Component
public class PatientInfoFacade extends PatientInfoServiceImpl {

    /*@Autowired
    private DoctorPageModeFacade doctorPageModeFacade;*/
    /*@Autowired
    private DeptInfoFacade deptInfoFacade;*/

    /**
     * 获取患者信息
     *
     * @param patientInfoVO
     * @return
     */
    public PatientInfoDTO getPatientInfo(PatientInfoVO patientInfoVO) {
        PatientInfoDTO patientInfoDTO = this.getPatientInfos(patientInfoVO.getPatientCode(), patientInfoVO.getHospitalCode());
        return patientInfoDTO;
    }

    /**
     * 页面顶部病人医生科室信息查询
     *
     * @param getTopPatientInfoVO
     * @return
     */
    public GetTopPatientInfoDTO getTopPatientInfo(@RequestBody GetTopPatientInfoVO getTopPatientInfoVO) {
        GetTopPatientInfoDTO getTopPatientInfoDTO = baseMapper.getTopPatientInfo(getTopPatientInfoVO);
        getTopPatientInfoDTO.setSystemTime(DateUtil.now());
        getTopPatientInfoDTO.setRecordId(getTopPatientInfoVO.getRecordId());
        getTopPatientInfoDTO.setPatientAge(DateUtil.yearCompare(getTopPatientInfoDTO.getBirthday(), DateUtil.now()));
        return getTopPatientInfoDTO;
    }

    /**
     * 根据ids获取病人信息
     * @param ids 病人ids
     * @return 病人信息
     */
    public Map<Long, PatientInfo> patientInfoMapByIds(List<Long> ids) {
    	Map<Long, PatientInfo> patientInfoMap = this.listByIds(ids).stream().filter(i -> i.getIsDeleted().equals("N")).collect(Collectors.toMap(PatientInfo::getId, i -> i));
    	return patientInfoMap;
    }
    

}
