BusPatientController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. package com.coffee.bus.controller;
  2. import cn.dev33.satoken.SaManager;
  3. import cn.dev33.satoken.annotation.SaCheckPermission;
  4. import cn.dev33.satoken.stp.StpLogic;
  5. import cn.hutool.core.collection.CollUtil;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  8. import com.baomidou.mybatisplus.core.mapper.Mapper;
  9. import com.coffee.bus.controller.vo.GetPatientInfoVo;
  10. import com.coffee.bus.controller.vo.MonitorDetailVo;
  11. import com.coffee.bus.controller.vo.MonitorFinishedVo;
  12. import com.coffee.bus.entity.*;
  13. import com.coffee.bus.enums.DeviceStatusEnum;
  14. import com.coffee.bus.enums.PatientAlarmEnum;
  15. import com.coffee.bus.registry.patient.PatientOperator;
  16. import com.coffee.bus.registry.patient.PatientRegistry;
  17. import com.coffee.bus.service.*;
  18. import com.coffee.bus.service.dto.*;
  19. import com.coffee.bus.utils.WsPublishUtils;
  20. import com.coffee.common.crud.BaseService;
  21. import com.coffee.common.crud.controller.BaseQueryController;
  22. import com.coffee.common.exception.CustomException;
  23. import com.coffee.common.result.R;
  24. import io.swagger.annotations.*;
  25. import lombok.AllArgsConstructor;
  26. import org.springframework.validation.annotation.Validated;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.context.request.async.DeferredResult;
  29. import java.util.*;
  30. /**
  31. * @author lifang
  32. * @version 1.0.0
  33. * @ClassName BusHospitalController.java
  34. * @Description TODO
  35. * @createTime 2022年03月19日 09:28:00
  36. */
  37. @RestController
  38. @AllArgsConstructor
  39. @RequestMapping("/bus/patient")
  40. @Api(tags = "医院病人管理",description = "关于病人的相关操作,查询操作权限【bus:patient:query】")
  41. public class BusPatientController implements BaseQueryController<BusPatientEntity,String> {
  42. private final LocalBusPatientService patientService;
  43. private final LocalBusClinicService clinicService;
  44. private final PatientRegistry patientRegistry;
  45. private final LocalBusInfusionHistoryService infusionService;
  46. private final LocalBusDeviceManualService manualService;
  47. private final WsPublishUtils wsPublishUtils;
  48. @PostMapping("/no_page")
  49. @SaCheckPermission("bus:patient:query")
  50. @ApiOperation(value = "输注监控列表",notes = "病人监控管理列表,权限【bus:patient:query】")
  51. public R<List<PatientMonitorResult>> selectPage(@RequestBody PatientMonitorQuery query){
  52. return R.success(patientService.selectAll(query));
  53. }
  54. @GetMapping("/repeat/device")
  55. @ApiOperation(value = "设备重复提示列表",notes = "当出现病患同一时间绑定了多个泵时,调用该接口查询出所有设备重复报警数据,权限【无】")
  56. public R<List<PatientDeviceRepeatResult>> repeatDevice(){
  57. return R.success(patientService.repeatDevice());
  58. }
  59. @GetMapping("/none/device")
  60. @ApiOperation(value = "临床无泵列表",notes = "当出现病患同一时间没有泵时,调用该接口查询出所有没有泵信息的病患临床数据,权限【无】")
  61. public R<List<PatientDeviceNoneResult>> noneDevice(){
  62. return R.success(patientService.noneDevice());
  63. }
  64. @PostMapping("/judge/repeat")
  65. @ApiOperation(value = "判断所给病号中是否出现了绑定设备重复",notes = "当结束管理时,调用改接口判断所结束病号是否出现了设备重复异常,权限【无】")
  66. @ApiResponses({
  67. @ApiResponse(code = 200,message = "0 病人中未出现重复,非0 病人中出现重复"),
  68. })
  69. public R<Long> judgeRepeat(@RequestBody List<String> patientCode){
  70. return R.success(patientService.count(new QueryWrapper<BusPatientEntity>().lambda().in(BusPatientEntity::getCode,patientCode).eq(BusPatientEntity::getAlarm,PatientAlarmEnum.DEVICE_REPEAT)));
  71. }
  72. @PostMapping("/judge/finished")
  73. @ApiOperation(value = "判断给定病号中是否可以结束临床管理",notes = "病患当前绑定主设备必须要在关机、不在服务器、待机中才能结束管理,权限【无】")
  74. @ApiResponses({
  75. @ApiResponse(code = 500,message = "没有选择病号"),
  76. @ApiResponse(code =200 ,message = "若存在不可以结束的临床信息,返回1",response = BusDeviceRunningEntity.class)
  77. })
  78. public R<Boolean> judgeFinished(@RequestBody List<String> patientCodes){
  79. if(CollUtil.isEmpty(patientCodes)){
  80. throw new CustomException("请选择一个病患");
  81. }
  82. return R.success(infusionService.count(new QueryWrapper<BusInfusionHistoryEntity>()
  83. .lambda()
  84. .nested(i->i.ne(BusInfusionHistoryEntity::getRunState,DeviceStatusEnum.Shutdown)
  85. .ne(BusInfusionHistoryEntity::getRunState,DeviceStatusEnum.NoSignal))
  86. .in(BusInfusionHistoryEntity::getPatientCode,patientCodes)
  87. .eq(BusInfusionHistoryEntity::getFinished,false))!=0);
  88. }
  89. @PostMapping("/do/{monitorType}/finished")
  90. @SaCheckPermission("bus:patient:finished")
  91. @ApiResponse(code = 4001,message = "病号当前绑定了多个设备,不可结束管理")
  92. @ApiOperation(value = "结束管理",notes = "病患当前绑定主设备必须要在关机、不在服务器、待机中才能结束管理,权限【bus:patient:finished】")
  93. public R<Boolean> finished(@PathVariable("monitorType")@ApiParam(value = "是否为无泵管理 false、无泵 true、有泵",defaultValue = "false" ) boolean haveDevice,
  94. @RequestBody MonitorFinishedVo monitorFinishedVo,
  95. @RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId){
  96. if(haveDevice){
  97. R<Boolean> result = monitorFinished(monitorFinishedVo, tenantId);
  98. wsPublishUtils.publishMonitorTotalCount(tenantId);
  99. wsPublishUtils.publishDeviceNone(tenantId);
  100. return result;
  101. }else {
  102. return manualFinished(monitorFinishedVo);
  103. }
  104. }
  105. /**
  106. * 描述: 输注监控结束管理(即使用驼人网络泵产品)
  107. * @author lifang
  108. * @date 2022/5/10 11:48
  109. * @param monitorFinishedVo
  110. * @param tenantId
  111. * @return R
  112. */
  113. private R<Boolean> monitorFinished(MonitorFinishedVo monitorFinishedVo, String tenantId){
  114. List<String> patientCodes = monitorFinishedVo.getPatientCodes();
  115. if(CollUtil.isEmpty(patientCodes)){
  116. List<String> clinicIds = monitorFinishedVo.getClinicIds();
  117. if (CollUtil.isEmpty(clinicIds)) {
  118. throw new CustomException("未选择临床信息");
  119. }
  120. }
  121. List<BusPatientEntity> patients = patientService.list(new QueryWrapper<BusPatientEntity>().lambda().in(BusPatientEntity::getCode, patientCodes));
  122. List<ManualUndoConfig> undoConfigs=new ArrayList<>();
  123. for (BusPatientEntity patient : patients) {
  124. undoConfigs.add(
  125. ManualUndoConfig.of(
  126. Collections.singletonList(patient.getInfusionId()),
  127. patient.getCode(),
  128. patient.getClinicId(),
  129. tenantId,
  130. true,
  131. monitorFinishedVo.getUndo())
  132. );
  133. }
  134. //病患绑定的有设备,对设备进行撤泵操作,且结束临床
  135. infusionService.batchUndo(undoConfigs,true);
  136. return R.success(true);
  137. }
  138. /**
  139. * 描述: 其他监控手动结束管理(即未采用驼人网络泵产品)
  140. * @author lifang
  141. * @date 2022/5/10 11:49
  142. * @param monitorFinishedVo
  143. * @return R
  144. */
  145. private R<Boolean> manualFinished(MonitorFinishedVo monitorFinishedVo){
  146. List<String> clinicIds = monitorFinishedVo.getClinicIds();
  147. if (CollUtil.isEmpty(clinicIds)) {
  148. throw new CustomException("未选择临床信息");
  149. }
  150. manualService.finishedMonitor(monitorFinishedVo);
  151. return R.success(true);
  152. }
  153. @PostMapping("/monitor/reset/{clinicId}")
  154. @SaCheckPermission("device:patient:edit")
  155. @ApiOperation(value = "病人当前监控时间重启",notes = "当结束临床后有新的输注信息产生,那么病人监控会重新显示,此时监控时间不会重新计算,需先调用该接口,权限标识为【device:patient:edit】")
  156. public R<Boolean> reset(@ApiParam("临床id")@PathVariable("clinicId")String clinicId){
  157. R<Boolean> result = R.success(clinicService.update(new UpdateWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getId, clinicId)
  158. .set(BusClinicEntity::getEndTime, null)));
  159. BusClinicEntity clinic = clinicService.getById(clinicId);
  160. wsPublishUtils.publishPatientMonitor(clinic.getPatientCode(),clinic.getTenantId());
  161. return result;
  162. }
  163. @PostMapping("/{alarm}/_count")
  164. @SaCheckPermission("device:patient:query")
  165. @ApiOperation(value = "病人报警数量统计",notes = "病人报警数量统计 0、未报警 1、泵重复 2、无泵,权限标识为【device:patient:query】")
  166. public R<Long> alarmCount(@PathVariable("alarm") int alarm){
  167. PatientAlarmEnum alarmEnum = PatientAlarmEnum.of(alarm);
  168. if(alarmEnum==null){
  169. return R.success(0L);
  170. }
  171. return R.success(patientService.patientAlarmCount(alarmEnum));
  172. }
  173. @PostMapping("/shift")
  174. @SaCheckPermission("device:patient:shift")
  175. @ApiOperation(value = "主泵切换的操作,只切换,不结束",notes = "当出现泵重复状态时,若用户想要进行主泵的切换,调用该接口进行操作,主泵切换完成后,会将副泵自动撤泵,权限标识为【device:patient:shift】")
  176. public R shift(@RequestBody@Validated DeviceShiftConfig shiftConfig){
  177. patientService.shift(shiftConfig);
  178. wsPublishUtils.publishPatientMonitor(shiftConfig.getPatientCode(),shiftConfig.getTenantId());
  179. return R.success();
  180. }
  181. @PostMapping("/undo")
  182. @SaCheckPermission("device:patient:undo")
  183. @ApiOperation(value = "批量撤泵,只撤泵,不切换",notes = "当出现泵重复状态时,若用户想要取消对其他副泵的监控,则调用此接口进行撤泵操作,权限标识为【device:patient:undo】")
  184. public R shift(@RequestBody@Validated ManualUndoConfig undoConfig, @RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId){
  185. undoConfig.setTenantId(tenantId);
  186. //泵切换完成后,对病号报警解除
  187. infusionService.undo(undoConfig,false);
  188. PatientOperator operator = patientRegistry.getOperator(undoConfig.getTenantId(), undoConfig.getPatientCode());
  189. //判断当前病号下是否还存在副泵
  190. long count = infusionService.count(new QueryWrapper<BusInfusionHistoryEntity>().lambda()
  191. .eq(BusInfusionHistoryEntity::getClinicId, operator.getClinicId())
  192. .eq(BusInfusionHistoryEntity::getFinished,false)
  193. .eq(BusInfusionHistoryEntity::getIsUndo,false));
  194. //处理缓存信息
  195. if(count==1){
  196. patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
  197. .eq(BusPatientEntity::getCode,undoConfig.getPatientCode())
  198. .eq(BusPatientEntity::getTenantId,undoConfig.getTenantId())
  199. .set(BusPatientEntity::getAlarm, PatientAlarmEnum.NONE));
  200. wsPublishUtils.publishDeviceRepeat(undoConfig.getTenantId());
  201. }
  202. wsPublishUtils.publishPatientMonitor(undoConfig.getPatientCode(),undoConfig.getTenantId());
  203. return R.success();
  204. }
  205. @PostMapping("/monitor")
  206. @SaCheckPermission("device:patient:query")
  207. @ApiOperation(value = "查看病人当前监控详情",notes = "查看病人当前监控详情,权限标识为【device:patient:query】")
  208. public R<PatientMonitorDetailResult> monitor(@RequestBody@Validated MonitorDetailVo vo){
  209. PatientMonitorDetailResult result = new PatientMonitorDetailResult();
  210. BusClinicEntity clinic =null;
  211. Boolean monitorType = vo.getMonitorType();
  212. if(Boolean.TRUE.equals(monitorType)){
  213. String patientCode = vo.getPatientCode();
  214. BusPatientEntity patient = patientService.getOne(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode, patientCode));
  215. if(patient==null){
  216. throw new CustomException("该病号信息不存在,请刷新后重试");
  217. }
  218. clinic = clinicService.getById(patient.getClinicId());
  219. BusInfusionHistoryEntity infusion =infusionService.getById(patient.getInfusionId());
  220. result.setInfusion(infusion);
  221. }else {
  222. String clinicId = vo.getClinicId();
  223. clinic = clinicService.getById(clinicId);
  224. result.setClinic(clinic);
  225. //无泵查看
  226. result.setDeviceManual( manualService.getOne(new QueryWrapper<BusDeviceManualEntity>().lambda().eq(BusDeviceManualEntity::getClinicId, clinic.getId())));
  227. }
  228. if(clinic==null){
  229. throw new CustomException("该临床信息不存在,请刷新后重试");
  230. }
  231. result.setClinic(clinic);
  232. return R.success(result);
  233. }
  234. @PostMapping("/stats/status")
  235. @SaCheckPermission("device:patient:query")
  236. @ApiOperation(value = "按照状态统计病人监控状态数量",notes = "权限【device:patient:query】")
  237. public R<MonitorStatusStatsCountResult> statsStatus(){
  238. return R.success(patientService.statusStats(null));
  239. }
  240. @PostMapping("/stats/time")
  241. @SaCheckPermission("device:patient:query")
  242. @ApiOperation(value = "按照时间统计病人监控数量",notes = "权限【device:patient:query】")
  243. public R<MonitorTimeStatsCountResult> statsTime(){
  244. return R.success(patientService.timeStats(null));
  245. }
  246. @PostMapping("/pull/async")
  247. @SaCheckPermission("device:patient:pull")
  248. @ApiOperation(value = "异步更新患者信息,超时时间默认为10s,超时后数据返回继续处理,输注监控",notes = "权限标识为【bus:patient:pull】")
  249. public DeferredResult<R<BusClinicEntity>> syn(@RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId, @RequestBody GetPatientInfoVo vo){
  250. return patientService.getPatientInfoFromHis(tenantId,vo.getPatientCode(),vo.getTimeout(),false);
  251. }
  252. @SaCheckPermission("device:patient:query")
  253. @ApiOperation(value = "泵重复绑定数量",notes = "权限标识为【bus:patient:query】")
  254. @PostMapping("/_count/repeat")
  255. public R<Integer> repeatCount(){
  256. return R.success(CollUtil.size(patientService.repeatDevice()));
  257. }
  258. @SaCheckPermission("device:patient:query")
  259. @ApiOperation(value = "无泵数量",notes = "权限标识为【bus:patient:query】")
  260. @PostMapping("/_count/none")
  261. public R<Integer> noneCount(){
  262. return R.success(CollUtil.size(patientService.repeatDevice()));
  263. }
  264. /**
  265. * 描述:
  266. * @author lifang
  267. * @date 2022/5/15 21:56
  268. * @param tenantId
  269. * @param vo
  270. * @return R
  271. */
  272. @PostMapping("/pull/sync")
  273. @SaCheckPermission("device:patient:pull")
  274. @ApiOperation(value = "同步更新患者信息,超时时间默认为10s,超时后数据返回则不进行处理,无泵更新",notes = "权限标识为【bus:patient:pull】")
  275. public DeferredResult<R<BusClinicEntity>> async(@RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId, @RequestBody GetPatientInfoVo vo){
  276. return patientService.getPatientInfoFromHis(tenantId,vo.getPatientCode(),vo.getTimeout(),true);
  277. }
  278. @Override
  279. public BaseService<? extends Mapper<BusPatientEntity>, BusPatientEntity, String> getService() {
  280. return patientService;
  281. }
  282. @Override
  283. public String getPermissionPrefix() {
  284. return "bus:patient:";
  285. }
  286. @Override
  287. public StpLogic getStpLogin() {
  288. return SaManager.getStpLogic("");
  289. }
  290. }