ZkManageService.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package thyyxxk.webserver.service.medicaladvice.patientinfo;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.convert.Convert;
  4. import cn.hutool.core.util.StrUtil;
  5. import lombok.RequiredArgsConstructor;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import org.springframework.transaction.annotation.Transactional;
  10. import org.springframework.web.client.RestTemplate;
  11. import thyyxxk.webserver.config.envionment.YzConfig;
  12. import thyyxxk.webserver.config.exception.ExceptionEnum;
  13. import thyyxxk.webserver.dao.his.inpatient.PatientDao;
  14. import thyyxxk.webserver.dao.his.medicaladvice.patientinfo.AdjustBedDao;
  15. import thyyxxk.webserver.dao.his.medicaladvice.patientinfo.ZkManageDao;
  16. import thyyxxk.webserver.entity.ResultVo;
  17. import thyyxxk.webserver.entity.executeItem.NumberEnum;
  18. import thyyxxk.webserver.entity.inpatient.ZyActpatient;
  19. import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZkBedVo;
  20. import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMi;
  21. import thyyxxk.webserver.entity.zhuyuanyisheng.ZyOrderZk;
  22. import thyyxxk.webserver.service.hutoolcache.DeptCache;
  23. import thyyxxk.webserver.service.zhuyuanyisheng.YiZhuLuRuServer;
  24. import thyyxxk.webserver.utils.AssertUtil;
  25. import thyyxxk.webserver.utils.CommonUtil;
  26. import thyyxxk.webserver.utils.ResultVoUtil;
  27. import thyyxxk.webserver.utils.TokenUtil;
  28. import java.math.BigDecimal;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. import java.util.Map;
  32. import java.util.stream.Collectors;
  33. /**
  34. * @Description:
  35. * @Author:lihong
  36. * @Date: 2024/1/3
  37. */
  38. @Slf4j
  39. @Service
  40. @RequiredArgsConstructor
  41. public class ZkManageService {
  42. private final ZkManageDao dao;
  43. private final PatientDao patientDao;
  44. private final AdjustBedDao adjustBedDao;
  45. private final DeptCache deptCache;
  46. private final RestTemplate template;
  47. private final YzConfig yzConfig;
  48. private final YiZhuLuRuServer yiZhuLuRuServer;
  49. public List<ZyActpatient> queryZkPatient(Map<String, String> query) {
  50. AssertUtil.isnotBlank(query.get("wardCode"), "病室编码不能为空");
  51. List<ZyActpatient> list = dao.selectZkPatient(query.get("keyWard"), query.get("wardCode"));
  52. CommonUtil.BeanTrim(list);
  53. return list;
  54. }
  55. public List<ZkBedVo> queryZkBedVo(Map<String, String> query) {
  56. AssertUtil.isnotBlank(query.get("wardCode"), "病室编码不能为空");
  57. List<ZkBedVo> list = dao.selectZkBedVo(query.get("wardCode"));
  58. CommonUtil.BeanTrim(list);
  59. return list;
  60. }
  61. public ResultVo<String> checkZk(ZkBedVo param) {
  62. AssertUtil.isnotBlank(param.getInpatientNo(), "住院号不能为空");
  63. AssertUtil.isnotBlank(param.getAdmissTimes(), "住院次数不能为空");
  64. AssertUtil.isnotBlank(param.getWardCode(), "病室不能为空");
  65. AssertUtil.isnotBlank(param.getDeptCode(), "转科病室不能为空");
  66. AssertUtil.isnotBlank(param.getZkDept(), "小科室不能为空");
  67. if (!passZk(param)) {
  68. Map<String, Object> map = dao.selectZkYz(param);
  69. if (CollUtil.isEmpty(map) || Convert.toInt(map.get("zk_count"), 0) == 0) {
  70. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人没有转科医嘱,不可做转科处理!", param.getInpatientNo()));
  71. }
  72. ZyOrderZk zyOrderZk = dao.selectZkOrder(Convert.toBigDecimal(map.get("act_order_no")));
  73. if (zyOrderZk == null) {
  74. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人没有转科医嘱详情,请确认!", param.getInpatientNo()));
  75. }
  76. if (!param.getDeptCode().equals(zyOrderZk.getNewWard()) || !param.getZkDept().equals(zyOrderZk.getNewDept())) {
  77. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人选择的转科病区或小科室不对,正确的转科医嘱为病区:[{}],小科室:[{}]!",
  78. param.getInpatientNo(), deptCache.getDeptName(zyOrderZk.getNewWard()), deptCache.getDeptName(zyOrderZk.getNewDept())));
  79. }
  80. Integer countZk = dao.selectZyZkList(param.getInpatientNo(), param.getAdmissTimes(), Convert.toBigDecimal(map.get("act_order_no")));
  81. if (countZk > 0) {
  82. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人已经转科,请不要重复操作!", param.getInpatientNo()));
  83. }
  84. }
  85. Integer count = dao.countYd(param);
  86. Integer countTy = dao.sumTy(param);
  87. if (count > 0 || (countTy != null && countTy > 0)) {
  88. List<BigDecimal> detailYd = dao.detailYd(param);
  89. if (CollUtil.isNotEmpty(detailYd)) {
  90. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人还有未提交的药单,医嘱号为:[{}],请先处理!", param.getInpatientNo(), CollUtil.join(detailYd, ",")));
  91. }
  92. List<BigDecimal> detailty = dao.detailTy(param);
  93. if (CollUtil.isNotEmpty(detailty)) {
  94. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人还有未退药品,医嘱号为:[{}],请先处理!", param.getInpatientNo(), CollUtil.join(detailty, ",")));
  95. }
  96. }
  97. //接收药品
  98. int infant = param.getInpatientNo().contains("$") ? 1 : 0;
  99. patientDao.zyReceiveDrug(param.getInpatientNo(), param.getAdmissTimes(), infant);
  100. //接收医嘱
  101. patientDao.zyReceiveOne(param.getInpatientNo(), param.getAdmissTimes(), infant);
  102. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE, "药品和医嘱接收成功!");
  103. }
  104. private boolean passZk(ZkBedVo param) {
  105. String SJ_DEPT_CODE = yzConfig.getShoushubingqu();
  106. return SJ_DEPT_CODE != null && (SJ_DEPT_CODE.equals(param.getDeptCode()) || SJ_DEPT_CODE.equals(param.getWardCode()));
  107. }
  108. @Transactional(rollbackFor = Exception.class)
  109. public ResultVo<String> saveZkData(List<ZkBedVo> param) {
  110. List<ZkBedVo> data = param.stream().filter(item -> StrUtil.isNotBlank(item.getInpatientNo())).collect(Collectors.toList());
  111. AssertUtil.isnotBlank(data, "保存数据不能为空");
  112. String userId = TokenUtil.getInstance().getTokenUserId();
  113. for (ZkBedVo item : data) {
  114. AssertUtil.isnotBlank(item.getZkDept(), StrUtil.format("{}病人转科科室不能为空!", item.getInpatientNo()));
  115. int count = 0;
  116. if (!item.getInpatientNo().contains("$")) {
  117. count = dao.countBaby(item.getInpatientNo() + "$%");
  118. }
  119. if (count > 0) {
  120. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人有婴儿信息,不可做转科处理!", item.getInpatientNo()));
  121. }
  122. Integer hasBedNo = adjustBedDao.isIdleBedNo(item.getBedNo(), item.getWardCode());
  123. if (hasBedNo == null) {
  124. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, StrUtil.format("{}病人转科的床位已经有病人了,请刷新重新分配床位!", item.getInpatientNo()));
  125. }
  126. //清空原床位
  127. ZyBedMi zyBedMi = new ZyBedMi();
  128. zyBedMi.setInpatientNo(null);
  129. zyBedMi.setAdmissTimes(null);
  130. zyBedMi.setBedStatus(NumberEnum.ONE.getCode());
  131. zyBedMi.setBedNo(item.getOrigBed());
  132. zyBedMi.setDeptCode(item.getOrigDept());
  133. zyBedMi.setWardCode(item.getOrigDept());
  134. adjustBedDao.updatePatientByBed(zyBedMi);
  135. //给专科后的床位
  136. ZyBedMi tempBed = new ZyBedMi();
  137. tempBed.setInpatientNo(item.getInpatientNo());
  138. tempBed.setAdmissTimes(item.getAdmissTimes());
  139. tempBed.setBedStatus(NumberEnum.TWO.getCode());
  140. tempBed.setDeptCode(item.getWardCode());
  141. tempBed.setWardCode(item.getWardCode());
  142. tempBed.setBedNo(item.getBedNo());
  143. adjustBedDao.updatePatientByBed(tempBed);
  144. //修改在院表的转科科室
  145. dao.updateZkZyActpatien(item);
  146. dao.insertZyAdt(item);
  147. item.setOpId(userId);
  148. String SJ_DEPT_CODE = yzConfig.getShoushubingqu();
  149. if (SJ_DEPT_CODE != null && (SJ_DEPT_CODE.equals(item.getOrigDept()) || SJ_DEPT_CODE.equals(item.getWardCode()))) {
  150. dao.insertZyZkListNoActOrderNo(item);
  151. } else {
  152. dao.insertZyZkList(item);
  153. }
  154. yiZhuLuRuServer.updateChargeByWardCode(item.getInpatientNo(), item.getAdmissTimes());
  155. }
  156. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE, "保存成功");
  157. }
  158. public ResultVo<String> createPatientDoor(List<ZkBedVo> param) {
  159. for (ZkBedVo zkBedVo : param) {
  160. try {
  161. Map<String, Object> paramMap = new HashMap<>();
  162. paramMap.put("patNo", StrUtil.trim(zkBedVo.getInpatientNo()));
  163. template.postForObject("http://172.16.32.167:20923/thyy/api/haikang/door/createPatient", paramMap, ResultVo.class);
  164. } catch (Exception e) {
  165. log.error("住院号=" + zkBedVo.getInpatientNo() + "创建门禁报错,{}", e);
  166. }
  167. }
  168. return ResultVoUtil.success();
  169. }
  170. }