123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package com.diagbot.facade;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import org.springframework.web.bind.annotation.RequestBody;
- import com.diagbot.client.AIServiceClient;
- import com.diagbot.client.bean.Response;
- 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.BeanUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.vo.GetTopPatientInfoVO;
- import com.diagbot.vo.PatientInfoVO;
- import com.diagbot.web.config.DBConn;
- /**
- * @Description: 患者业务逻辑
- * @author: wangyu
- * @time: 2018/11/19 13:19
- */
- @Component
- public class PatientInfoFacade extends PatientInfoServiceImpl {
- /*@Autowired
- private DoctorPageModeFacade doctorPageModeFacade;*/
- /*@Autowired
- private DeptInfoFacade deptInfoFacade;*/
-
- @Autowired
- private AIServiceClient aiServiceClient;
- public PatientInfoDTO savePatientInfo(PatientInfoVO patientInfoVO){
- PatientInfoDTO patientInfoDTO=baseMapper.getPatientInfos(patientInfoVO.getPatientCode(), patientInfoVO.getHospitalCode());
-
- PatientInfoDTO dto=updateOrInsert(patientInfoDTO,patientInfoVO);
- return dto;
- }
-
- private PatientInfoDTO updateOrInsert(PatientInfoDTO patientInfoDTO,PatientInfoVO patientInfoVO){
- PatientInfo patientInfo=new PatientInfo();
- if(patientInfoDTO!=null && patientInfoDTO.getId()!=null){
- //更新
- patientInfoVO.setId(patientInfoDTO.getId());
- getPatientData(patientInfoDTO,patientInfoVO);
- BeanUtil.copyProperties(patientInfoDTO,patientInfo);
-
- patientInfo.setId(patientInfoDTO.getId());
- patientInfo.setGmtModified(new Date());
- baseMapper.updateById(patientInfo);
- }else{
- //新增
- getPatientData(patientInfoDTO,patientInfoVO);
- BeanUtil.copyProperties(patientInfoDTO,patientInfo);
-
- patientInfo.setGmtCreate(new Date());
- baseMapper.insert(patientInfo);
- }
- return patientInfoDTO;
- }
-
- /**
- * 从不同来源获取患者信息
- */
- private void getPatientData(PatientInfoDTO patientInfoDTO,PatientInfoVO patientInfoVO){
- if("view".equals(patientInfoVO.getType())){
- //从视图或数据库中获取医生信息保存到本系统
- PatientInfoDTO data=DBConn.getPatientInfo(patientInfoVO);
- BeanUtil.copyProperties(data, patientInfoDTO);
- }else if("api".equals(patientInfoVO.getType())){
- //通过HIS接口获取信息保存到本系统
- Response<PatientInfoDTO> data=aiServiceClient.getPatientInfo(patientInfoVO);
- BeanUtil.copyProperties(data.getData(), patientInfoDTO);
- }else{
- BeanUtil.copyProperties(patientInfoVO, patientInfoDTO);
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
- try {
- patientInfoDTO.setBirthday(dateFormat.parse(patientInfoVO.getBirthday()));
- } catch (Exception e) {
- patientInfoDTO.setBirthday(null);
- }
- patientInfoDTO.setHospitalCode(patientInfoVO.getHospitalCode());
- patientInfoDTO.setCode(patientInfoVO.getPatientCode());
- }
- }
-
- /**
- * 获取患者信息
- *
- * @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;
- }
-
- }
|