PatientInfoFacade.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.diagbot.facade;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.stream.Collectors;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Component;
  9. import org.springframework.web.bind.annotation.RequestBody;
  10. import com.diagbot.client.AIServiceClient;
  11. import com.diagbot.client.bean.Response;
  12. import com.diagbot.dto.GetTopPatientInfoDTO;
  13. import com.diagbot.dto.PatientInfoDTO;
  14. import com.diagbot.entity.PatientInfo;
  15. import com.diagbot.service.impl.PatientInfoServiceImpl;
  16. import com.diagbot.util.BeanUtil;
  17. import com.diagbot.util.DateUtil;
  18. import com.diagbot.vo.GetTopPatientInfoVO;
  19. import com.diagbot.vo.PatientInfoVO;
  20. import com.diagbot.web.config.DBConn;
  21. /**
  22. * @Description: 患者业务逻辑
  23. * @author: wangyu
  24. * @time: 2018/11/19 13:19
  25. */
  26. @Component
  27. public class PatientInfoFacade extends PatientInfoServiceImpl {
  28. /*@Autowired
  29. private DoctorPageModeFacade doctorPageModeFacade;*/
  30. /*@Autowired
  31. private DeptInfoFacade deptInfoFacade;*/
  32. @Autowired
  33. private AIServiceClient aiServiceClient;
  34. public PatientInfoDTO savePatientInfo(PatientInfoVO patientInfoVO){
  35. PatientInfoDTO patientInfoDTO=baseMapper.getPatientInfos(patientInfoVO.getPatientCode(), patientInfoVO.getHospitalCode());
  36. PatientInfoDTO dto=updateOrInsert(patientInfoDTO,patientInfoVO);
  37. return dto;
  38. }
  39. private PatientInfoDTO updateOrInsert(PatientInfoDTO patientInfoDTO,PatientInfoVO patientInfoVO){
  40. PatientInfo patientInfo=new PatientInfo();
  41. if(patientInfoDTO!=null && patientInfoDTO.getId()!=null){
  42. //更新
  43. patientInfoVO.setId(patientInfoDTO.getId());
  44. getPatientData(patientInfoDTO,patientInfoVO);
  45. BeanUtil.copyProperties(patientInfoDTO,patientInfo);
  46. patientInfo.setId(patientInfoDTO.getId());
  47. patientInfo.setGmtModified(new Date());
  48. baseMapper.updateById(patientInfo);
  49. }else{
  50. //新增
  51. getPatientData(patientInfoDTO,patientInfoVO);
  52. BeanUtil.copyProperties(patientInfoDTO,patientInfo);
  53. patientInfo.setGmtCreate(new Date());
  54. baseMapper.insert(patientInfo);
  55. }
  56. return patientInfoDTO;
  57. }
  58. /**
  59. * 从不同来源获取患者信息
  60. */
  61. private void getPatientData(PatientInfoDTO patientInfoDTO,PatientInfoVO patientInfoVO){
  62. if("view".equals(patientInfoVO.getType())){
  63. //从视图或数据库中获取医生信息保存到本系统
  64. PatientInfoDTO data=DBConn.getPatientInfo(patientInfoVO);
  65. BeanUtil.copyProperties(data, patientInfoDTO);
  66. }else if("api".equals(patientInfoVO.getType())){
  67. //通过HIS接口获取信息保存到本系统
  68. Response<PatientInfoDTO> data=aiServiceClient.getPatientInfo(patientInfoVO);
  69. BeanUtil.copyProperties(data.getData(), patientInfoDTO);
  70. }else{
  71. BeanUtil.copyProperties(patientInfoVO, patientInfoDTO);
  72. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  73. try {
  74. patientInfoDTO.setBirthday(dateFormat.parse(patientInfoVO.getBirthday()));
  75. } catch (Exception e) {
  76. patientInfoDTO.setBirthday(null);
  77. }
  78. patientInfoDTO.setHospitalCode(patientInfoVO.getHospitalCode());
  79. patientInfoDTO.setCode(patientInfoVO.getPatientCode());
  80. }
  81. }
  82. /**
  83. * 获取患者信息
  84. *
  85. * @param patientInfoVO
  86. * @return
  87. */
  88. public PatientInfoDTO getPatientInfo(PatientInfoVO patientInfoVO) {
  89. PatientInfoDTO patientInfoDTO = this.getPatientInfos(patientInfoVO.getPatientCode(), patientInfoVO.getHospitalCode());
  90. return patientInfoDTO;
  91. }
  92. /**
  93. * 页面顶部病人医生科室信息查询
  94. *
  95. * @param getTopPatientInfoVO
  96. * @return
  97. */
  98. public GetTopPatientInfoDTO getTopPatientInfo(@RequestBody GetTopPatientInfoVO getTopPatientInfoVO) {
  99. GetTopPatientInfoDTO getTopPatientInfoDTO = baseMapper.getTopPatientInfo(getTopPatientInfoVO);
  100. getTopPatientInfoDTO.setSystemTime(DateUtil.now());
  101. getTopPatientInfoDTO.setRecordId(getTopPatientInfoVO.getRecordId());
  102. getTopPatientInfoDTO.setPatientAge(DateUtil.yearCompare(getTopPatientInfoDTO.getBirthday(), DateUtil.now()));
  103. return getTopPatientInfoDTO;
  104. }
  105. /**
  106. * 根据ids获取病人信息
  107. * @param ids 病人ids
  108. * @return 病人信息
  109. */
  110. public Map<Long, PatientInfo> patientInfoMapByIds(List<Long> ids) {
  111. Map<Long, PatientInfo> patientInfoMap = this.listByIds(ids).stream().filter(i -> i.getIsDeleted().equals("N")).collect(Collectors.toMap(PatientInfo::getId, i -> i));
  112. return patientInfoMap;
  113. }
  114. }