Преглед на файлове

fix 优化租户逻辑
add 病患设备重复报警

18339543638 преди 3 години
родител
ревизия
1921d9829d
променени са 20 файла, в които са добавени 299 реда и са изтрити 88 реда
  1. 1 1
      coffee-admin/src/main/resources/application.yml
  2. 1 1
      coffee-admin/src/test/java/com/coffee/admin/BusPatientTest.java
  3. 12 14
      coffee-system/src/main/java/com/coffee/bus/controller/BusDeviceRunningController.java
  4. 83 9
      coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java
  5. 27 0
      coffee-system/src/main/java/com/coffee/bus/controller/vo/MonitorFinished.java
  6. 1 1
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java
  7. 6 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionModifyEntity.java
  8. 4 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusPatientEntity.java
  9. 10 2
      coffee-system/src/main/java/com/coffee/bus/mapper/BusPatientMapper.java
  10. 2 0
      coffee-system/src/main/java/com/coffee/bus/registry/constant/DeviceKeyConstant.java
  11. 12 2
      coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceOperator.java
  12. 1 0
      coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceRegistry.java
  13. 11 0
      coffee-system/src/main/java/com/coffee/bus/registry/device/DeviceOperator.java
  14. 9 12
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java
  15. 18 12
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceRunningService.java
  16. 12 3
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java
  17. 3 10
      coffee-system/src/main/java/com/coffee/bus/service/dto/ManualUndoConfig.java
  18. 47 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/PatientDeviceNoneResult.java
  19. 23 17
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  20. 16 4
      coffee-system/src/main/resources/mapper/bus/BusPatientMapper.xml

+ 1 - 1
coffee-admin/src/main/resources/application.yml

@@ -64,7 +64,7 @@ mybatis-plus:
     dbConfig:
       idType: ASSIGN_ID
   configuration:
-    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
     default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
   type-aliases-package: com.coffee.bus.entity
 

+ 1 - 1
coffee-admin/src/test/java/com/coffee/admin/BusPatientTest.java

@@ -25,7 +25,7 @@ public class BusPatientTest {
 
     @Test
     public  void test(){
-        List<PatientDeviceRepeatResult> patientDeviceRepeatResults = patientService.repeatDevice("1505808170691784706");
+        List<PatientDeviceRepeatResult> patientDeviceRepeatResults = patientService.repeatDevice();
         System.out.println(patientDeviceRepeatResults);
     }
 }

+ 12 - 14
coffee-system/src/main/java/com/coffee/bus/controller/BusDeviceRunningController.java

@@ -59,29 +59,27 @@ public class BusDeviceRunningController implements BaseQueryController<BusDevice
     @PostMapping("/count/clinic")
     @ApiOperation(value = "查询临床下泵的数量",notes = "根据病号+临床id+医院id 查询一个病人下是否绑定了多个泵,以此来作为泵重复的依据,权限标识为【空】")
     @ApiImplicitParams({
-            @ApiImplicitParam(value = "code",name = "病号"),
-            @ApiImplicitParam(value = "clinicId",name = "临床id"),
-            @ApiImplicitParam(value = "tenantId",name = "医院id",required = false,example = "当为系统用户时,此参数必传,平台用户时,此参数可忽略"),
+            @ApiImplicitParam(value = "病号",name = "code"),
+            @ApiImplicitParam(value = "临床id",name = "clinicId")
     })
-    public R repeatCount(@RequestParam("code") String patientCode,@RequestParam("clinicId") String clinic,@RequestParam(required = false) String tenantId){
+    public R repeatCount(@RequestParam("code") String patientCode,@RequestParam("clinicId") String clinic){
         return R.success(netPumpService.count(new QueryWrapper<BusDeviceRunningEntity>()
                 .lambda()
                 .eq(BusDeviceRunningEntity::getPatientCode,patientCode)
-                .eq(BusDeviceRunningEntity::getClinicId,clinic)
-                .eq(StrUtil.isNotEmpty(tenantId),BusDeviceRunningEntity::getTenantId,tenantId)));
+                .eq(BusDeviceRunningEntity::getClinicId,clinic)));
     }
 
-    @PostMapping("/undo")
-    @SaCheckPermission("device:running:undo")
-    @ApiOperation(value = "进行临床撤泵操作",notes = "在进行撤泵操作之前[{/count/clinic}],即【查询临床下泵的数量】接口,当出现泵重复状态时,提醒用户处理,权限标识为【device:running:undo】")
-    public R undo(@RequestBody ManualUndoConfig manualUndoConfig){
-        netPumpService.undo(manualUndoConfig);
-        return R.success();
-    }
+//    @PostMapping("/undo")
+//    @SaCheckPermission("device:running:undo")
+//    @ApiOperation(value = "进行病患下临床撤泵操作",notes = "在进行撤泵操作之前[{/count/clinic}],即【查询临床下泵的数量】接口,当出现泵重复状态时,提醒用户处理,权限标识为【device:running:undo】")
+//    public R undo(@RequestBody ManualUndoConfig manualUndoConfig){
+//        netPumpService.undo(manualUndoConfig);
+//        return R.success();
+//    }
 
     @PostMapping("/shift")
     @SaCheckPermission("device:running:shift")
-    @ApiOperation(value = "进行主泵切换的操作",notes = "当出现泵重复状态时,若用户想要进行主泵的切换,调用该接口进行操作,权限标识为【device:running:shift】")
+    @ApiOperation(value = "进行主泵切换的操作",notes = "当出现泵重复状态时,若用户想要进行主泵的切换,调用该接口进行操作,主泵切换完成后,会将副泵自动撤泵,权限标识为【device:running:shift】")
     public R shift(@RequestBody DeviceShiftConfig shiftConfig){
         netPumpService.shift(shiftConfig);
         return R.success();

+ 83 - 9
coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java

@@ -1,24 +1,31 @@
 package com.coffee.bus.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
-import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
+import com.coffee.bus.controller.vo.MonitorFinished;
+import com.coffee.bus.entity.BusDeviceRunningEntity;
 import com.coffee.bus.entity.BusPatientEntity;
+import com.coffee.bus.enums.DeviceStatusEnum;
+import com.coffee.bus.service.LocalBusClinicService;
+import com.coffee.bus.service.LocalBusDeviceRunningService;
 import com.coffee.bus.service.LocalBusPatientService;
-import com.coffee.bus.service.dto.DeviceShiftConfig;
+import com.coffee.bus.service.dto.ManualUndoConfig;
+import com.coffee.bus.service.dto.PatientDeviceNoneResult;
 import com.coffee.bus.service.dto.PatientDeviceRepeatResult;
-import com.coffee.common.bo.LoginUser;
 import com.coffee.common.crud.BaseService;
 import com.coffee.common.crud.controller.BaseCrudController;
+import com.coffee.common.entity.QueryParamEntity;
+import com.coffee.common.exception.CustomException;
 import com.coffee.common.result.R;
-import com.coffee.common.util.SecurityUtil;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.context.request.async.DeferredResult;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -34,11 +41,76 @@ import java.util.List;
 public class BusPatientController extends BaseCrudController<BusPatientEntity, String> {
     private final LocalBusPatientService patientService;
 
+    private final LocalBusDeviceRunningService deviceRunningService;
 
+    private final LocalBusClinicService clinicService;
     @GetMapping("/repeat/device")
-    @ApiOperation(value = "获取当前医院绑定设备重复的所有病患信息",notes = "当出现病患统一时间绑定了多个泵时,调用该接口查询出所有设备重复报警数据【无】")
-    public R<List<PatientDeviceRepeatResult>> repeatDevice(@RequestParam(value = "tenantId",required = false)String tenantId){
-        return R.success(patientService.repeatDevice(tenantId));
+    @ApiOperation(value = "获取当前医院绑定设备重复的所有病患信息",notes = "当出现病患同一时间绑定了多个泵时,调用该接口查询出所有设备重复报警数据,权限【无】")
+    public R<List<PatientDeviceRepeatResult>> repeatDevice(){
+        return R.success(patientService.repeatDevice());
+    }
+
+    @GetMapping("/none/device")
+    @ApiOperation(value = "获取当前医院没有绑定泵的所有病患临床信息",notes = "当出现病患同一时间没有泵时,调用该接口查询出所有没有泵信息的病患临床数据,权限【无】")
+    public R<List<PatientDeviceNoneResult>> noneDevice(){
+        return R.success(patientService.noneDevice());
+    }
+
+    @PostMapping("/judge/repeat")
+    @ApiOperation(value = "判断所给病号中是否出现了绑定设备重复",notes = "当结束管理时,调用改接口判断所结束病号是否出现了设备重复异常,权限【无】")
+    @ApiResponses({
+            @ApiResponse(code = 200,message = "true 设备中未出现重复"),
+            @ApiResponse(code = 200,message = "false 设备中出现重复")
+    })
+    public R<Boolean> judgeRepeat(@RequestBody List<String> patientCode){
+        return R.success(patientService.count(new QueryWrapper<BusPatientEntity>().lambda().in(BusPatientEntity::getCode,patientCode))==0);
+    }
+
+    @PostMapping("/judge/finished")
+    @ApiOperation(value = "判断给定病号中是否可以结束临床管理",notes = "病患当前绑定主设备必须要在关机、不在服务器、待机中才能结束管理,权限【无】")
+    @ApiResponses({
+            @ApiResponse(code = 500,message = "没有选择病号"),
+            @ApiResponse(code =200 ,message = "若存在不可以结束的临床信息,将会把该临床的主泵信息返回",response = BusDeviceRunningEntity.class)
+    })
+    public R<List<BusDeviceRunningEntity>> judgeFinished(@RequestBody List<String> patientCodes){
+        if(CollectionUtil.isEmpty(patientCodes)){
+            throw new CustomException("请选择一个病患");
+        }
+
+        return R.success(deviceRunningService.list(new QueryWrapper<BusDeviceRunningEntity>()
+                .lambda()
+                .select(BusDeviceRunningEntity::getDeviceId,BusDeviceRunningEntity::getPatientCode,BusDeviceRunningEntity::getRunState,BusDeviceRunningEntity::getAlarm)
+                .eq(BusDeviceRunningEntity::getMaster,true)
+                .eq(BusDeviceRunningEntity::getMonitorType,true)
+                .ne(BusDeviceRunningEntity::getRunState, DeviceStatusEnum.Shutdown)
+                .in(BusDeviceRunningEntity::getPatientCode,patientCodes)));
+    }
+
+    @PostMapping("/finished")
+    @SaCheckPermission("bus:patient:finished")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "结束监控数据结构",name = "monitorFinished",dataTypeClass = MonitorFinished.class)
+    })
+    @ApiOperation(value = "判断给定病号中是否可以结束临床管理",notes = "病患当前绑定主设备必须要在关机、不在服务器、待机中才能结束管理,权限【bus:patient:finished】")
+    public R finished(@RequestBody MonitorFinished monitorFinished, @RequestAttribute("tenantId")String tenantId){
+        List<String> patientCodes = monitorFinished.getPatientCodes();
+        if(CollectionUtil.isEmpty(patientCodes)){
+            throw new CustomException("请选择一个病患");
+        }
+        List<BusDeviceRunningEntity> runningDevices = deviceRunningService.list(new QueryWrapper<BusDeviceRunningEntity>()
+                .lambda()
+                .select(BusDeviceRunningEntity::getDeviceId)
+                .in(BusDeviceRunningEntity::getPatientCode, patientCodes)
+                .eq(BusDeviceRunningEntity::getIsUndo, false)
+                .eq(BusDeviceRunningEntity::getMonitorType, true));
+        if(CollectionUtil.isNotEmpty(runningDevices)){
+            //病患绑定的有设备,对设备进行撤泵操作
+            ManualUndoConfig undoConfig = ManualUndoConfig.of(runningDevices.stream().map(BusDeviceRunningEntity::getId).collect(Collectors.toList()), true, monitorFinished.getUndo());
+            deviceRunningService.undo(undoConfig);
+        }
+        //结束临床
+        clinicService.finish(patientCodes,tenantId);
+        return R.success();
     }
     /**
      * 权限控制前缀
@@ -74,4 +146,6 @@ public class BusPatientController extends BaseCrudController<BusPatientEntity, S
     public R async(@PathVariable("hospitalId") String hospitalId, @PathVariable("patientCode")String patientCode){
         return R.success();
     }
+
+
 }

+ 27 - 0
coffee-system/src/main/java/com/coffee/bus/controller/vo/MonitorFinished.java

@@ -0,0 +1,27 @@
+package com.coffee.bus.controller.vo;
+
+import com.coffee.bus.service.dto.UndoDeviceConfig;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName MonitorFinished.java
+ * @Description TODO
+ * @createTime 2022年04月20日 20:34:00
+ */
+@ApiModel("监控结束")
+@Data
+public class MonitorFinished {
+    @ApiModelProperty("结束监控的病号")
+    private List<String> patientCodes;
+
+    @ApiModelProperty("撤泵配置")
+    @NotNull(message = "撤泵配置")
+    private UndoDeviceConfig undo;
+}

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java

@@ -199,7 +199,7 @@ public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String>
     @ApiModelProperty(value = "撤泵时间")
     private Date undoTime;
 
-    @ApiModelProperty(value = "撤泵时间")
+    @ApiModelProperty(value = "手术开始时间")
     private Date clinicStartTime;
 
     public static BusInfusionHistoryEntity parseRunningInfo(BusDeviceRunningEntity running){

+ 6 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionModifyEntity.java

@@ -13,6 +13,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import lombok.experimental.Accessors;
+import org.springframework.web.context.request.async.DeferredResult;
 
 import javax.validation.constraints.DecimalMax;
 import javax.validation.constraints.DecimalMin;
@@ -147,6 +148,11 @@ public class BusInfusionModifyEntity extends TenantGenericEntity<String,String>
     @ApiModelProperty(value = "参数修改时间")
     private Date modifyTime;
 
+    //todo
+    @ApiModelProperty(value = "监控当前病患临床开始时间")
+    @TableField(exist = false)
+    private Date clinicStartTime;
+
     public static BusInfusionModifyEntity parseRunningInfo(BusDeviceRunningEntity running){
         BusInfusionModifyEntity entity = new BusInfusionModifyEntity();
         entity.setDeviceId(running.getDeviceId());

+ 4 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusPatientEntity.java

@@ -39,6 +39,10 @@ public class BusPatientEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "性别")
     private SexEnum gender;
 
+    @TableField
+    @ApiModelProperty("病号最新的输注记录")
+    private String infusionId;
+
     @TableField(fill = FieldFill.INSERT)
     @TableLogic(value = "0",delval = "1")
     private Integer isDelete;

+ 10 - 2
coffee-system/src/main/java/com/coffee/bus/mapper/BusPatientMapper.java

@@ -3,6 +3,7 @@ package com.coffee.bus.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.entity.PatientDeviceRepeatDomain;
+import com.coffee.bus.service.dto.PatientDeviceNoneResult;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -19,8 +20,15 @@ public interface BusPatientMapper extends BaseMapper<BusPatientEntity> {
 
     /**
      * 查询给定医院下所有同时挂载多个泵的病患信息
-     * @param tenantId 医院id
+     * @param
      * @return
      */
-    List<PatientDeviceRepeatDomain> repeatDevice(@Param("tenantId") String tenantId);
+    List<PatientDeviceRepeatDomain> selectRepeatDevice();
+
+    /**
+     * 查询当前医院下所有没有泵的病患信息
+     * @return
+     */
+    List<PatientDeviceNoneResult> selectNoneDevice();
+
 }

+ 2 - 0
coffee-system/src/main/java/com/coffee/bus/registry/constant/DeviceKeyConstant.java

@@ -33,4 +33,6 @@ public class DeviceKeyConstant {
     public static final String INFUSION_ID="infusion_id";
 
     public static final String INFUSION_PARAM="infusion_param";
+
+    public static final String UNDO="undo";
 }

+ 12 - 2
coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceOperator.java

@@ -240,12 +240,22 @@ public class ClusterDeviceOperator implements DeviceOperator<DeviceCacheInfo> {
 
     @Override
     public void setClassification(String classification) {
-        configStorage.setConfig("classification",classification);
+        configStorage.setConfig(DeviceKeyConstant.CLASSIFY,classification);
     }
 
     @Override
     public String getClassification() {
-        return  getValue("classification").asString();
+        return  getValue(DeviceKeyConstant.CLASSIFY).asString();
+    }
+
+    @Override
+    public Boolean getUndo() {
+        return getValue(DeviceKeyConstant.UNDO).asBoolean();
+    }
+
+    @Override
+    public void setUndo(Boolean undo) {
+        configStorage.setConfig(DeviceKeyConstant.UNDO,undo);
     }
 
     @Override

+ 1 - 0
coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceRegistry.java

@@ -56,6 +56,7 @@ public class ClusterDeviceRegistry implements DeviceRegistry {
                 deviceOperator.setClassification(runningInfo.getClassification());
                 deviceOperator.setAlarm(runningInfo.getAlarm());
                 deviceOperator.setAlias(runningInfo.getAlias());
+                deviceOperator.setUndo(runningInfo.getIsUndo());
                 if(StrUtil.isNotEmpty(runningInfo.getInfusionId())){
                     deviceOperator.setInfusionId(runningInfo.getInfusionId());
                     BusInfusionModifyEntity infusionModify = infusionModifyService.getOne(new QueryWrapper<BusInfusionModifyEntity>().lambda().eq(BusInfusionModifyEntity::getInfusionId, runningInfo.getInfusionId()).orderByDesc(BusInfusionModifyEntity::getModifyTime).last("LIMIT 1"));

+ 11 - 0
coffee-system/src/main/java/com/coffee/bus/registry/device/DeviceOperator.java

@@ -174,6 +174,17 @@ public interface DeviceOperator<T> extends Operator<T> {
      */
     String getClassification();
 
+    /**
+     * 获取当前输注状态下是否撤泵
+     * @return
+     */
+    Boolean getUndo();
+
+    /**
+     * 设置撤泵信息
+     * @param undo
+     */
+    void setUndo(Boolean undo);
 
     void clear();
 }

+ 9 - 12
coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java

@@ -13,8 +13,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-
-import java.util.Date;
+import java.util.*;
 
 /**
  * @author lifang
@@ -52,19 +51,17 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
 
     /**
      * 结束当前医院病号的临床数据
-     * @param patientCode 病号
-     * @param tenantId 医院id
+     * @param patientCodes 病号
      */
     @Transactional(rollbackFor = Exception.class)
-    public void finish(String patientCode, String tenantId) {
-        this.update(new UpdateWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getPatientCode,patientCode)
-        .eq(BusClinicEntity::getTenantId,tenantId)
-        .eq(BusClinicEntity::getFinished,false)
-        .set(BusClinicEntity::getFinished,true)
-        .set(BusClinicEntity::getEndTime,new Date()));
+    public void finish(List<String> patientCodes, String tenantId) {
+        this.update(new UpdateWrapper<BusClinicEntity>().lambda()
+                .in(BusClinicEntity::getPatientCode,patientCodes)
+                .eq(BusClinicEntity::getFinished,false)
+                .set(BusClinicEntity::getFinished,true)
+                .set(BusClinicEntity::getEndTime,new Date()));
         //更新病人缓存
-        PatientOperator<PatientCacheInfo> patient = patientRegistry.getOperator(tenantId, patientCode);
-        patient.setFinished(true);
+        patientCodes.stream().map(code->patientRegistry.getOperator(tenantId,code)).forEach(operator->operator.setFinished(true));
     }
 
     /**

+ 18 - 12
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceRunningService.java

@@ -2,6 +2,7 @@ package com.coffee.bus.service;
 
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.coffee.bus.registry.device.DeviceRegistry;
 import com.coffee.bus.registry.patient.PatientOperator;
 import com.coffee.bus.registry.patient.PatientRegistry;
 import com.coffee.bus.registry.patient.bean.DeviceTimeSmallInfo;
@@ -15,6 +16,8 @@ import com.coffee.bus.entity.BusInfusionHistoryEntity;
 import com.coffee.bus.mapper.BusDeviceRunningMapper;
 import com.coffee.common.crud.BaseService;
 import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -31,11 +34,18 @@ import java.util.stream.Collectors;
  * @createTime 2022年03月19日 09:27:00
  */
 @Service
-@AllArgsConstructor
 public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMapper, BusDeviceRunningEntity,String> {
-    private final LocalBusClinicService clinicService;
     private final LocalBusInfusionHistoryService infusionHistoryService;
     private final PatientRegistry patientRegistry;
+    @Autowired
+    @Lazy
+    private DeviceRegistry deviceRegistry;
+
+    public LocalBusDeviceRunningService(LocalBusInfusionHistoryService infusionHistoryService, PatientRegistry patientRegistry) {
+        this.infusionHistoryService = infusionHistoryService;
+        this.patientRegistry = patientRegistry;
+    }
+
     @Override
     public void validateBeforeSave(BusDeviceRunningEntity entity) {
 
@@ -52,7 +62,7 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
     }
 
     /**
-     * 撤泵操作
+     * 结束病患监控操作
      * @param manualUndoConfig
      */
     @Transactional(rollbackFor = Exception.class)
@@ -79,11 +89,11 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
                     .set(BusInfusionHistoryEntity::getUndoTime,undo.getUndoTime())
                     .set(BusInfusionHistoryEntity::getDestroyer,undo.getDestroyer())
                     .set(BusInfusionHistoryEntity::getWitnesses,undo.getWitnesses()));
+            //将缓存设置为已撤泵状态
+            ids.stream().map(deviceRegistry::getOperator)
+                    .forEach(operator->operator.setUndo(true));
         }
-        if(!Boolean.TRUE.equals(manualUndoConfig.getShift())){
-            //不是泵切换操作,结束撤泵设备所绑定的临床数据
-            devices.forEach(device->{ clinicService.finish(device.getPatientCode(),device.getTenantId()); });
-        }
+
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -106,11 +116,7 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
         PatientOperator<PatientCacheInfo> operator = patientRegistry.getOperator(shiftConfig.getTenantId(), shiftConfig.getPatientCode());
         List<String> replicaIds = shiftConfig.getReplicaIds();
         if(CollectionUtil.isNotEmpty(replicaIds)){
-            ManualUndoConfig manualUndoConfig = new ManualUndoConfig();
-            manualUndoConfig.setIds(replicaIds);
-            manualUndoConfig.setMonitorType(true);
-            manualUndoConfig.setUndo(shiftConfig.getUndo());
-            manualUndoConfig.setShift(true);
+            ManualUndoConfig manualUndoConfig = ManualUndoConfig.of(replicaIds,true,shiftConfig.getUndo());
             //对副泵进行撤泵操作
             undo(manualUndoConfig);
         }

+ 12 - 3
coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java

@@ -3,6 +3,7 @@ package com.coffee.bus.service;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.entity.PatientDeviceRepeatDomain;
 import com.coffee.bus.mapper.BusPatientMapper;
+import com.coffee.bus.service.dto.PatientDeviceNoneResult;
 import com.coffee.bus.service.dto.PatientDeviceRepeatResult;
 import com.coffee.common.crud.BaseService;
 import lombok.AllArgsConstructor;
@@ -52,10 +53,10 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
 
     /**
      * 获取给定医院下所有的挂载多个设备的病人信息
-     * @param tenantId 医院id
+     *
      */
-    public List<PatientDeviceRepeatResult> repeatDevice(String tenantId) {
-        List<PatientDeviceRepeatDomain> patientDeviceRepeats = this.baseMapper.repeatDevice(tenantId);
+    public List<PatientDeviceRepeatResult> repeatDevice() {
+        List<PatientDeviceRepeatDomain> patientDeviceRepeats = this.baseMapper.selectRepeatDevice();
         Map<String, PatientDeviceRepeatResult> resultMap = new HashMap<>();
         patientDeviceRepeats.forEach(deviceRepeat->{
             PatientDeviceRepeatResult repeatResult = resultMap.computeIfAbsent(deviceRepeat.getCode(),k->
@@ -83,4 +84,12 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
         });
         return new ArrayList<>(resultMap.values());
     }
+
+    /**
+     * 获取无设备绑定的临床手术信息
+     * @return
+     */
+    public List<PatientDeviceNoneResult> noneDevice() {
+        return this.baseMapper.selectNoneDevice();
+    }
 }

+ 3 - 10
coffee-system/src/main/java/com/coffee/bus/service/dto/ManualUndoConfig.java

@@ -1,8 +1,9 @@
 package com.coffee.bus.service.dto;
 
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 
 import javax.validation.constraints.NotNull;
@@ -16,6 +17,7 @@ import java.util.*;
  */
 @Data
 @ApiModel("手动撤泵配置")
+@AllArgsConstructor(staticName = "of")
 public class ManualUndoConfig {
     @ApiModelProperty("进行撤泵的所有运行数据id")
     private List<String> ids;
@@ -23,16 +25,7 @@ public class ManualUndoConfig {
     @ApiModelProperty("是否为有泵监护,0、无泵 1、有泵")
     private Boolean monitorType;
 
-
     @ApiModelProperty("撤泵配置")
     @NotNull(message = "撤泵配置不能为空")
     private UndoDeviceConfig undo;
-
-    /**
-     * 此参数仅用来表示该次撤泵是否为切换主泵的撤泵
-     * 1、若为切换主泵中撤掉多余的副泵,仅变化病人绑定泵状态,不结束临床
-     * 2、若撤掉临床全部的泵,则结束临床
-     */
-    @JsonIgnoreProperties
-    private Boolean shift;
 }

+ 47 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/PatientDeviceNoneResult.java

@@ -0,0 +1,47 @@
+package com.coffee.bus.service.dto;
+
+import com.coffee.bus.enums.DeviceAlarmEnum;
+import com.coffee.bus.enums.DeviceEnum;
+import com.coffee.common.enums.SexEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName PatientDeviceRepeatResult.java
+ * @Description 病人无设备返回数据
+ * @createTime 2022年04月19日 14:53:00
+ */
+@Data
+@ApiModel("病人无设备返回数据")
+public class PatientDeviceNoneResult {
+    @ApiModelProperty("病患名称")
+    private String name;
+
+    @ApiModelProperty("病患性别")
+    private SexEnum gender;
+
+    @ApiModelProperty("病号")
+    private String code;
+
+    @ApiModelProperty("病患年龄")
+    private Integer age;
+
+    @ApiModelProperty("病区")
+    private String ward;
+
+    @ApiModelProperty("病床")
+    private String bedNo;
+
+    @ApiModelProperty("手术名称")
+    private String clinicName;
+
+    @ApiModelProperty("麻醉医生")
+    private String anaDoctor;
+}

+ 23 - 17
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -106,8 +106,10 @@ public class DeviceInfoListener {
                 log.error("设备[{}]所绑定临床已结束且未关机,将数据[{}]丢弃",device.getDeviceId(),device.toString());
                 return;
             }
-            //处理病患数据,解决泵重复,无泵等问题
-            handlePatient(device,cacheOperation);
+            //如果为新数据或者未撤泵
+            if(newInfusion.get()||!deviceOperator.getUndo()){
+                handlePatient(device,cacheOperation);
+            }
             //更新/保存当前输注信息
             handleInfusionHistory(device,deviceOperator,newInfusion,cacheOperation);
             //处理输注参数
@@ -116,7 +118,16 @@ public class DeviceInfoListener {
             BusDeviceHistoryEntity history=handleRunningHistory(device);
             //处理报警信息
             handleAlarm(history,deviceOperator,cacheOperation);
-            //todo 流速图
+
+            //如果是主泵信息且产生了新的输注,则与当前病号进行绑定
+            if(Boolean.TRUE.equals(device.getMaster())&&newInfusion.get()){
+                patientService.update(new UpdateWrapper<BusPatientEntity>()
+                        .lambda()
+                        .eq(BusPatientEntity::getCode,device.getPatientCode())
+                        .eq(BusPatientEntity::getTenantId,device.getTenantId())
+                        .set(BusPatientEntity::getInfusionId,device.getInfusionId()));
+            }
+            //todo 流速图处理
             if(first){
                 deviceUsingService.save(device);
             }else {
@@ -186,6 +197,9 @@ public class DeviceInfoListener {
         }
         suppliers.add(()->{
             //更新设备缓存数据
+            if(newInfusion.get()){
+                deviceOperator.setUndo(false);
+            }
             deviceOperator.setClassification(device.getClassification());
             deviceOperator.setTenantId(device.getTenantId());
             deviceOperator.setUsingId(device.getId());
@@ -330,16 +344,8 @@ public class DeviceInfoListener {
         BusInfusionHistoryEntity infusionHistory = BusInfusionHistoryEntity.parseRunningInfo(device);
         if (newInfusion.get()) {
             //检测数据库是否存在该输注信息
-            BusInfusionHistoryEntity existInfusion =
-                    infusionHistoryService.getOne(new QueryWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getDeviceId, device.getDeviceId())
-                            .eq(BusInfusionHistoryEntity::getClassification, device.getClassification()));
-            if(existInfusion==null){
-                infusionHistory.setId(String.valueOf(IdWorker.getId()));
-                infusionHistoryService.save(infusionHistory);
-            }else {
-                infusionHistory.setId(existInfusion.getId());
-                infusionHistoryService.updateById(infusionHistory);
-            }
+            infusionHistory.setId(String.valueOf(IdWorker.getId()));
+            infusionHistoryService.save(infusionHistory);
         }else {
             infusionHistory.setId(deviceOperator.getInfusionId());
             infusionHistoryService.updateById(infusionHistory);
@@ -450,7 +456,7 @@ public class DeviceInfoListener {
         mark=mark+1;
         BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
         pump.setType(DeviceEnum.continuous);
-        pump.setClassification(String.valueOf(mark));
+        pump.setClassification("1");
         pump.setDeviceId("123");
         pump.setPatientCode("456");
         pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
@@ -466,7 +472,7 @@ public class DeviceInfoListener {
         BusDeviceRunningEntity pump1 = new BusDeviceRunningEntity();
         pump1.setDeviceId("456");
         pump1.setType(DeviceEnum.continuous);
-        pump1.setClassification(String.valueOf(mark));
+        pump1.setClassification("1");
         pump1.setPatientCode("456");
         pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
         pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
@@ -481,7 +487,7 @@ public class DeviceInfoListener {
         BusDeviceRunningEntity pump2 = new BusDeviceRunningEntity();
         pump2.setType(DeviceEnum.continuous);
         pump2.setDeviceId("456");
-        pump2.setClassification(String.valueOf(mark));
+        pump2.setClassification("2");
         pump2.setPatientCode("789");
         pump2.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
         pump2.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
@@ -497,7 +503,7 @@ public class DeviceInfoListener {
 
         BusDeviceRunningEntity pump3 = new BusDeviceRunningEntity();
         pump3.setDeviceId("456");
-        pump3.setClassification(String.valueOf(mark));
+        pump3.setClassification("3");
         pump3.setType(DeviceEnum.continuous);
         pump3.setPatientCode("456");
         pump3.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));

+ 16 - 4
coffee-system/src/main/resources/mapper/bus/BusPatientMapper.xml

@@ -19,7 +19,7 @@
         <result column="master" property="master"/>
     </resultMap>
 
-    <select id="repeatDevice" resultMap="repeatDeviceResult">
+    <select id="selectRepeatDevice" resultMap="repeatDeviceResult">
          SELECT
  p.name,
  p.gender,
@@ -35,8 +35,20 @@
  d.alarm as device_alarm,
  d.start_time as infusion_start_time,
  d.master
-FROM (SELECT `name`,gender,CODE,tenant_id FROM bus_patient WHERE bus_patient.`alarm`=1) AS p
-left join (SELECT * from bus_device_running where monitor_type=1 ) as d on p.CODE=d.patient_code and p.tenant_id=d.tenant_id
-left join  (SELECT * FROM bus_clinic WHERE finished=0 ) AS c ON  c.`patient_code`=p.code AND c.`tenant_id`=p.tenant_id;
+FROM (SELECT `name`,gender,CODE FROM bus_patient WHERE bus_patient.`alarm`=1) AS p
+left join (SELECT * from bus_device_running where monitor_type=1 ) as d on p.CODE=d.patient_code
+left join  (SELECT * FROM bus_clinic WHERE finished=0 ) AS c ON  c.`patient_code`=p.code;
+    </select>
+    <select id="selectNoneDevice" resultType="com.coffee.bus.service.dto.PatientDeviceNoneResult">
+SELECT
+ p.name,
+ p.gender,
+ p.code,
+ c.patient_age as age,
+ c.ward,
+ c.bed_no,
+ c.`name` as clinic_name
+FROM (SELECT `name`,gender,CODE,tenant_id FROM bus_patient WHERE bus_patient.`alarm`=2 ) AS p
+left join  (SELECT * FROM bus_clinic WHERE finished=0 ) AS c ON  c.`patient_code`=p.code;
     </select>
 </mapper>