Explorar o código

update 设备类行存储改为value值
fixed 医院信息处理bug修复

18339543638 %!s(int64=3) %!d(string=hai) anos
pai
achega
8898286ffd
Modificáronse 16 ficheiros con 495 adicións e 110 borrados
  1. 10 6
      coffee-system/src/main/java/com/coffee/bus/controller/BusClinicController.java
  2. 12 12
      coffee-system/src/main/java/com/coffee/bus/controller/BusDeviceRunningController.java
  3. 4 7
      coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java
  4. 33 0
      coffee-system/src/main/java/com/coffee/bus/controller/vo/ClinicStatsVo.java
  5. 174 0
      coffee-system/src/main/java/com/coffee/bus/controller/vo/DeviceRunningMockVo.java
  6. 2 2
      coffee-system/src/main/java/com/coffee/bus/controller/vo/MonitorFinishedVo.java
  7. 2 2
      coffee-system/src/main/java/com/coffee/bus/controller/vo/NoPumpConfigVo.java
  8. 1 1
      coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceRunningEntity.java
  9. 8 0
      coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceInfoEvent.java
  10. 6 1
      coffee-system/src/main/java/com/coffee/bus/mapper/BusClinicMapper.java
  11. 8 0
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java
  12. 33 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicStatsQueryResult.java
  13. 71 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicStatsReturnResult.java
  14. 62 63
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  15. 20 16
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/HisInfoListener.java
  16. 49 0
      coffee-system/src/main/resources/mapper/bus/BusClinicMapper.xml

+ 10 - 6
coffee-system/src/main/java/com/coffee/bus/controller/BusClinicController.java

@@ -1,18 +1,17 @@
 package com.coffee.bus.controller;
 
 import com.baomidou.mybatisplus.core.mapper.Mapper;
+import com.coffee.bus.controller.vo.ClinicStatsVo;
 import com.coffee.bus.entity.BusClinicEntity;
-import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.service.LocalBusClinicService;
-import com.coffee.bus.service.LocalBusPatientService;
+import com.coffee.bus.service.dto.ClinicStatsReturnResult;
 import com.coffee.common.crud.BaseService;
 import com.coffee.common.crud.controller.BaseCrudController;
+import com.coffee.common.result.R;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
+import org.springframework.web.bind.annotation.*;
 /**
  * @author lifang
  * @version 1.0.0
@@ -28,6 +27,11 @@ public class BusClinicController extends BaseCrudController<BusClinicEntity, Str
     private final LocalBusClinicService clinicService;
 
 
+    @PostMapping("/stats")
+    @ApiOperation("临床过程中的数据记录")
+    public R<ClinicStatsReturnResult> list(@RequestBody ClinicStatsVo statsVo) {
+        return R.success(clinicService.stats(statsVo));
+    }
     /**
      * 权限控制前缀
      * @return

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

@@ -3,15 +3,15 @@ package com.coffee.bus.controller;
 import cn.dev33.satoken.SaManager;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.stp.StpLogic;
-import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
-import com.coffee.bus.service.dto.DeviceShiftConfig;
-import com.coffee.bus.service.dto.ManualUndoConfig;
-import com.coffee.bus.controller.vo.NoPumpConfig;
+import com.coffee.bus.controller.vo.DeviceRunningMockVo;
+import com.coffee.bus.controller.vo.NoPumpConfigVo;
 import com.coffee.bus.entity.BusDeviceRunningEntity;
 import com.coffee.bus.enums.DeviceAlarmEnum;
 import com.coffee.bus.enums.DeviceStatusEnum;
+import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
 import com.coffee.bus.service.LocalBusDeviceRunningService;
 import com.coffee.common.crud.BaseService;
 import com.coffee.common.crud.controller.BaseQueryController;
@@ -21,6 +21,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.springframework.boot.SpringApplication;
 import org.springframework.web.bind.annotation.*;
 
 /**
@@ -52,7 +53,7 @@ public class BusDeviceRunningController implements BaseQueryController<BusDevice
     @PostMapping("/nopump")
     @SaCheckPermission("device:running:add")
     @ApiOperation(value = "新增无泵数据,权限为device:running:add")
-    public R saveNoPump(@RequestBody NoPumpConfig noPump){
+    public R saveNoPump(@RequestBody NoPumpConfigVo noPump){
         return R.success();
     }
 
@@ -69,13 +70,12 @@ public class BusDeviceRunningController implements BaseQueryController<BusDevice
                 .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("/mock")
+    @ApiOperation(value = "模拟设备运行数据",notes = "在进行数据模拟前,请确保该泵存在于bus_device表中,若不存在,请添加后再模拟数据,当出现泵重复状态时,权限标识为【无】")
+    public R undo(@RequestBody DeviceRunningMockVo mockVo){
+        SpringUtil.publishEvent(new DeviceInfoEvent(this,mockVo,mockVo.getDeviceId()));
+        return R.success();
+    }
 
 
 

+ 4 - 7
coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java

@@ -5,7 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.coffee.bus.controller.vo.MonitorFinished;
+import com.coffee.bus.controller.vo.MonitorFinishedVo;
 import com.coffee.bus.entity.*;
 import com.coffee.bus.enums.DeviceStatusEnum;
 import com.coffee.bus.enums.PatientAlarmEnum;
@@ -18,8 +18,6 @@ import com.coffee.bus.service.LocalBusDeviceRunningService;
 import com.coffee.bus.service.LocalBusInfusionHistoryService;
 import com.coffee.bus.service.LocalBusPatientService;
 import com.coffee.bus.service.dto.*;
-import com.coffee.common.crud.BaseService;
-import com.coffee.common.crud.controller.BaseCrudController;
 import com.coffee.common.exception.CustomException;
 import com.coffee.common.result.R;
 import com.coffee.common.result.ResultCode;
@@ -29,7 +27,6 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.context.request.async.DeferredResult;
 
 import java.util.*;
-import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
 /**
@@ -106,8 +103,8 @@ public class BusPatientController  {
     @SaCheckPermission("bus:patient:finished")
     @ApiResponse(code = 4001,message = "病号当前绑定了多个设备,不可结束管理")
     @ApiOperation(value = "即结束管理",notes = "病患当前绑定主设备必须要在关机、不在服务器、待机中才能结束管理,权限【bus:patient:finished】")
-    public R finished(@RequestBody MonitorFinished monitorFinished, @RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId){
-        List<String> patientCodes = monitorFinished.getPatientCodes();
+    public R finished(@RequestBody MonitorFinishedVo monitorFinishedVo, @RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId){
+        List<String> patientCodes = monitorFinishedVo.getPatientCodes();
         if(CollectionUtil.isEmpty(patientCodes)){
             throw new CustomException("请选择一个病患");
         }
@@ -127,7 +124,7 @@ public class BusPatientController  {
         }
         //组装撤泵信息
         List<ManualUndoConfig> undoConfigs = patientOperators.stream().map(operator ->
-                ManualUndoConfig.of(Collections.singletonList(operator.getBindDeviceId()), operator.getCode(), tenantId,true, monitorFinished.getUndo())
+                ManualUndoConfig.of(Collections.singletonList(operator.getBindDeviceId()), operator.getCode(), tenantId,true, monitorFinishedVo.getUndo())
         )
 //                .filter(undoConfig -> undoConfig.getDeviceIds() != null && undoConfig.getDeviceIds().size() > 0)
                 .collect(Collectors.toList());

+ 33 - 0
coffee-system/src/main/java/com/coffee/bus/controller/vo/ClinicStatsVo.java

@@ -0,0 +1,33 @@
+package com.coffee.bus.controller.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName ClinicStatsVo.java
+ * @Description TODO
+ * @createTime 2022年04月27日 15:46:00
+ */
+@ApiModel("临床数据统计")
+@Data
+public class ClinicStatsVo {
+    @ApiModelProperty("临床id")
+    private String clinicId;
+    @ApiModelProperty("设备id")
+    private String deviceId;
+    @ApiModelProperty("输注id")
+    private String infusionId;
+    @ApiModelProperty("是否统计流速")
+    private boolean continueDose;
+    @ApiModelProperty("是否统计追加量")
+    private boolean appendDose;
+    @ApiModelProperty("是否统计已输注量")
+    private boolean inputDose;
+    @ApiModelProperty("是否统计有效次数")
+    private boolean validCount;
+    @ApiModelProperty("是否统计无效次数")
+    private boolean inValidCount;
+}

+ 174 - 0
coffee-system/src/main/java/com/coffee/bus/controller/vo/DeviceRunningMockVo.java

@@ -0,0 +1,174 @@
+package com.coffee.bus.controller.vo;
+
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.coffee.bus.enums.DeviceAlarmEnum;
+import com.coffee.bus.enums.DeviceEnum;
+import com.coffee.bus.enums.DeviceStatusEnum;
+import com.coffee.common.enums.SexEnum;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.apache.ibatis.type.EnumTypeHandler;
+
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName DeviceRunningMockVo.java
+ * @Description TODO
+ * @createTime 2022年04月28日 11:52:00
+ */
+@ApiModel("Mock设备运行数据")
+@Data
+public class DeviceRunningMockVo {
+    @ApiModelProperty(value = "网络泵id",readOnly = true)
+    private String deviceId;
+
+    @ApiModelProperty(value = "病号")
+    private String patientCode;
+
+    @ApiModelProperty(value = "病区")
+    private String ward;
+
+    @ApiModelProperty(value = "床号")
+    private String bedNo;
+
+    @ApiModelProperty(value = "总量",readOnly = true)
+    @Max(value = 999,message = "总量最大值不得超过999")
+    @Min(value = 0,message ="总量最小值不得超过0" )
+    private Integer totalDose;
+
+    @ApiModelProperty(value = "公共参数-首次量",readOnly = true)
+    @Max(value = 50,message = "首次量最大值不得超过50")
+    @Min(value = 0,message ="首次量最小值不得超过0" )
+    private Integer firstDose;
+
+
+    @ApiModelProperty(value = "公共参数-剩余量",readOnly = true)
+    private BigDecimal remainDose;
+
+    @ApiModelProperty(value = "公共参数-已输入量",readOnly = true)
+    private BigDecimal inputDose;
+
+    @ApiModelProperty(value = "公共参数-追加量",readOnly = true)
+    @DecimalMax(value = "10",message = "PCA追加量最大值不得超过10")
+    @DecimalMin(value = "0",message ="PCA追加量最小值不得超过0" )
+    private BigDecimal appendDose;
+
+    @ApiModelProperty(value = "公共参数-追加锁时",readOnly = true)
+    @DecimalMax(value = "99",message = "PCA追加量最大值不得超过99")
+    @DecimalMin(value = "1",message ="PCA追加量最小值不得超过0" )
+    private BigDecimal appendLockTime;
+
+    @ApiModelProperty(value = "公共参数-极限量",readOnly = true)
+    @DecimalMax(value = "90",message = "PCA追加量最大值不得超过90")
+    @DecimalMin(value = "0",message ="PCA追加量最小值不得超过0" )
+    private BigDecimal maxDose;
+
+    @ApiModelProperty(value = "公共参数-自控锁时",readOnly = true)
+    private BigDecimal selfControlLockTime;
+
+    @ApiModelProperty(value = "公共参数-自控次数",readOnly = true)
+    private BigDecimal selfControlCount;
+
+    @ApiModelProperty(value = "公共参数-pca有效次数",readOnly = true)
+    private Integer pcaValidCount;
+
+    @ApiModelProperty(value = "公共参数-pca无效次数",readOnly = true)
+    private Integer pcaInvalidCount;
+
+    @ApiModelProperty(value = "公共参数-pca总按次数",readOnly = true)
+    private Integer pcaTotalCount;
+
+    @ApiModelProperty(value = "公共参数-持续量(流速)",readOnly = true)
+    @DecimalMax(value = "50",message = "持续给液量最大值不得超过50")
+    @DecimalMin(value = "0",message ="持续给液量最小值不得超过0" )
+    private BigDecimal continueDose;
+
+    @ApiModelProperty(value = "脉冲泵参数-脉冲量",readOnly = true)
+    @Max(value = 20,message = "脉冲量最大值不得超过20")
+    @Min(value = 0,message ="脉冲量最小值不得超过0" )
+    private Integer pulseDose;
+
+    @ApiModelProperty(value = "脉冲泵参数-脉冲锁时",readOnly = true)
+    @Max(value = 90,message = "脉冲锁时最大值不得超过90")
+    @Min(value = 30,message ="脉冲锁时最小值不得超过30" )
+    private Integer pulseLockTime;
+
+    @ApiModelProperty(value = "脉冲泵参数-脉冲首次锁时",readOnly = true)
+    @Max(value = 60,message = "脉冲首次锁时最大值不得超过60")
+    @Min(value = 0,message ="脉冲首次锁时最小值不得超过0" )
+    private Integer pulseFirstLockTime;
+
+    @ApiModelProperty(value = "智能泵参数-加档周期",readOnly = true)
+    @DecimalMax(value = "10",message = "加档周期最大值不得超过10")
+    @DecimalMin(value = "0.5",message ="加档周期最小值不得超过0.5" )
+    private BigDecimal flowUpCycle;
+
+    @ApiModelProperty(value = "智能泵参数-减档周期",readOnly = true)
+    @DecimalMax(value = "10",message = "减档周期最大值不得超过10")
+    @DecimalMin(value = "0.5",message ="减档周期最小值不得超过0.5" )
+    private BigDecimal flowDownCycle;
+
+    @ApiModelProperty(value = "智能泵参数-计次",readOnly = true)
+    @DecimalMax(value = "10",message = "PCA追加量最大值不得超过10")
+    @DecimalMin(value = "1",message ="PCA追加量最小值不得超过1" )
+    private BigDecimal flowCount;
+
+    @ApiModelProperty(value = "智能泵参数-上限",readOnly = true)
+    @DecimalMax(value = "50",message = "智能泵上限值最大值不得超过90")
+    @DecimalMin(value = "1",message ="智能泵上限值最小值不得超过0" )
+    private BigDecimal flowUpLimit;
+
+    @ApiModelProperty(value = "智能泵参数-下限",readOnly = true)
+    @DecimalMax(value = "50",message = "智能泵下限值最大值不得超过50")
+    @DecimalMin(value = "0.1",message ="智能泵下限值最小值不得超过0.1" )
+    private BigDecimal flowDownLimit;
+
+    @ApiModelProperty(value = "智能泵参数-自调比例",readOnly = true)
+    @DecimalMax(value = "95",message = "自调比例不得超过95")
+    @DecimalMin(value = "0",message ="自调比例最小值不得超过0" )
+    private BigDecimal flowAdjustRate;
+
+
+    @ApiModelProperty(value = "泵运行状态",readOnly = true)
+    @TableField(typeHandler = EnumTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.IGNORED)
+    private DeviceStatusEnum runState;
+
+    @ApiModelProperty(value = "报警信息",readOnly = true)
+    @TableField(typeHandler = EnumTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.IGNORED)
+    private DeviceAlarmEnum alarm;
+
+    @ApiModelProperty(value = "输注即将结束提醒",readOnly = true)
+    private Boolean warnWillFinished;
+
+    @ApiModelProperty(value = "镇痛不足提醒",readOnly = true)
+    private Boolean warnAnalgesicPoor;
+
+    @ApiModelProperty(value = "电量偏低提醒",readOnly = true)
+    private Boolean warnLowBattery;
+
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "分包标记位",readOnly = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private String classification;
+
+    @ApiModelProperty(value = "泵类型",readOnly = true)
+    @TableField(javaType = true,updateStrategy = FieldStrategy.NEVER)
+    private DeviceEnum type;
+
+    @ApiModelProperty(value = "数据上传时间",readOnly = true,hidden = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private Date uploadTime;
+}

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/controller/vo/MonitorFinished.java → coffee-system/src/main/java/com/coffee/bus/controller/vo/MonitorFinishedVo.java

@@ -11,13 +11,13 @@ import java.util.List;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName MonitorFinished.java
+ * @ClassName MonitorFinishedVo.java
  * @Description TODO
  * @createTime 2022年04月20日 20:34:00
  */
 @ApiModel("监控结束")
 @Data
-public class MonitorFinished {
+public class MonitorFinishedVo {
     @ApiModelProperty("结束监控的病号")
     private List<String> patientCodes;
 

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/controller/vo/NoPumpConfig.java → coffee-system/src/main/java/com/coffee/bus/controller/vo/NoPumpConfigVo.java

@@ -9,13 +9,13 @@ import lombok.Data;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName NoPumpConfig.java
+ * @ClassName NoPumpConfigVo.java
  * @Description 无泵监护配置
  * @createTime 2022年03月31日 20:58:00
  */
 @Data
 @ApiModel("新增无泵监护配置")
-public class NoPumpConfig {
+public class NoPumpConfigVo {
     @ApiModelProperty("泵数据")
     private BusDeviceRunningEntity pump;
     @ApiModelProperty("手术信息")

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

@@ -208,7 +208,7 @@ public class BusDeviceRunningEntity extends TenantGenericEntity<String,String> {
     private String classification;
 
     @ApiModelProperty(value = "泵类型",readOnly = true)
-    @TableField(typeHandler = EnumTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.NEVER)
+    @TableField(javaType = true,updateStrategy = FieldStrategy.NEVER)
     private DeviceEnum type;
 
     @ApiModelProperty(value = "数据上传时间",readOnly = true,hidden = true)

+ 8 - 0
coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceInfoEvent.java

@@ -1,5 +1,7 @@
 package com.coffee.bus.listener.event.bean;
 
+import cn.hutool.json.JSONUtil;
+import com.coffee.bus.controller.vo.DeviceRunningMockVo;
 import com.coffee.bus.entity.BusDeviceRunningEntity;
 import lombok.Getter;
 import org.springframework.context.ApplicationEvent;
@@ -36,6 +38,12 @@ public class DeviceInfoEvent extends ApplicationEvent {
         this.deviceId=deviceId;
     }
 
+    public DeviceInfoEvent(Object source, @NotNull DeviceRunningMockVo content, @NotNull String deviceId) {
+        super(source);
+        this.content= JSONUtil.toBean(JSONUtil.toJsonStr(content),BusDeviceRunningEntity.class);
+        this.deviceId=deviceId;
+    }
+
     public DeviceInfoEvent(Object source, Clock clock, @NotNull BusDeviceRunningEntity content, @NotNull String deviceId) {
         super(source, clock);
         this.content=content;

+ 6 - 1
coffee-system/src/main/java/com/coffee/bus/mapper/BusClinicMapper.java

@@ -1,8 +1,10 @@
 package com.coffee.bus.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.coffee.bus.controller.vo.ClinicStatsVo;
 import com.coffee.bus.entity.BusClinicEntity;
-import com.coffee.bus.entity.BusPatientEntity;
+import java.util.*;
+import com.coffee.bus.service.dto.ClinicStatsQueryResult;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -25,4 +27,7 @@ public interface BusClinicMapper extends BaseMapper<BusClinicEntity> {
      */
     @Select("select * from bus_clinic where tenant_id=#{hospitalId} and patient_code=#{patientCode} order by start_time DESC limit 0,1")
     BusClinicEntity recentClinic(@Param("hospitalId") String hospitalId,@Param("patientCode") String patientCode);
+
+
+    List<ClinicStatsQueryResult> stats(@Param("query") ClinicStatsVo query);
 }

+ 8 - 0
coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java

@@ -1,10 +1,14 @@
 package com.coffee.bus.service;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.coffee.bus.controller.vo.ClinicStatsVo;
 import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.mapper.BusClinicMapper;
 import com.coffee.bus.registry.patient.PatientRegistry;
+import com.coffee.bus.service.dto.ClinicStatsQueryResult;
+import com.coffee.bus.service.dto.ClinicStatsReturnResult;
 import com.coffee.common.crud.BaseService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -98,4 +102,8 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
     public void asyncFromHis(String hospitalId, String patientCode) {
 
     }
+
+    public ClinicStatsReturnResult stats(ClinicStatsVo statsVo) {
+        return ClinicStatsReturnResult.of(this.baseMapper.stats(statsVo));
+    }
 }

+ 33 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicStatsQueryResult.java

@@ -0,0 +1,33 @@
+package com.coffee.bus.service.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName ClinicStatsQueryResult.java
+ * @Description TODO
+ * @createTime 2022年04月27日 16:55:00
+ */
+@ApiModel("统计查询数据库结果")
+@Data
+public class ClinicStatsQueryResult implements Serializable {
+    @ApiModelProperty(value = "流速",hidden = true)
+    private BigDecimal continueDose;
+    @ApiModelProperty(value = "追加量",hidden = true)
+    private BigDecimal appendDose;
+    @ApiModelProperty(value = "已输注量",hidden = true)
+    private BigDecimal inputDose;
+    @ApiModelProperty(value = "无效次数",hidden = true)
+    private Integer validCount;
+    @ApiModelProperty(value = "有效次数",hidden = true)
+    private Integer inValidCount;
+    @ApiModelProperty(value = "数据上传时间",hidden = true)
+    private Date uploadTime;
+}

+ 71 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicStatsReturnResult.java

@@ -0,0 +1,71 @@
+package com.coffee.bus.service.dto;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.python.antlr.ast.Str;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.*;
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName ClinicStatsResult.java
+ * @Description TODO
+ * @createTime 2022年04月27日 16:16:00
+ */
+@Data
+@ApiModel("统计返回前端数据")
+public class ClinicStatsReturnResult implements Serializable {
+    @ApiModelProperty("流速数据集")
+    private List<List<Object>> continueDose;
+    @ApiModelProperty("追加量数据集")
+    private List<List<Object>> appendDose;
+    @ApiModelProperty("已输注量数据集")
+    private List<List<Object>> inputDose;
+    @ApiModelProperty("有效次数数据集")
+    private List<List<Object>> validCount;
+    @ApiModelProperty("无效次数数据集")
+    private List<List<Object>> inValidCount;
+
+    public static ClinicStatsReturnResult of(List<ClinicStatsQueryResult> queryResults){
+        ClinicStatsReturnResult result = new ClinicStatsReturnResult();
+        if(CollectionUtil.isEmpty(queryResults)){
+            return result;
+        }
+        queryResults.forEach(queryResult -> {
+            String uploadTime = DateUtil.format(queryResult.getUploadTime(), DatePattern.NORM_DATETIME_PATTERN);
+            List<List<Object>> continueDoses = Optional.ofNullable(result.getContinueDose()).orElse(new ArrayList<>());
+            List<List<Object>> appendDoses = Optional.ofNullable(result.getAppendDose()).orElse(new ArrayList<>());
+            List<List<Object>> inputDoses = Optional.ofNullable(result.getInputDose()).orElse(new ArrayList<>());
+            List<List<Object>> validCounts = Optional.ofNullable(result.getValidCount()).orElse(new ArrayList<>());
+            List<List<Object>> inValidCounts = Optional.ofNullable(result.getInValidCount()).orElse(new ArrayList<>());
+
+            if( queryResult.getContinueDose()!=null){
+                continueDoses.add(Arrays.asList(uploadTime, queryResult.getContinueDose()));
+            }
+            if(queryResult.getAppendDose()!=null){
+                appendDoses.add(Arrays.asList(uploadTime,queryResult.getAppendDose()));
+            }
+            if( queryResult.getInputDose()!=null){
+                inputDoses.add(Arrays.asList(uploadTime, queryResult.getInputDose()));
+            }
+            if(queryResult.getValidCount()!=null){
+                validCounts.add(Arrays.asList(uploadTime,queryResult.getValidCount()));
+            }
+            if(queryResult.getInValidCount()!=null){
+                inValidCounts.add(Arrays.asList(uploadTime,queryResult.getInValidCount()));
+            }
+
+            result.setContinueDose(continueDoses);
+            result.setAppendDose(appendDoses);
+            result.setInputDose(inputDoses);
+            result.setValidCount(validCounts);
+            result.setInValidCount(inValidCounts);
+        });
+        return result;
+    }
+}

+ 62 - 63
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -15,7 +15,6 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.coffee.bus.entity.*;
 import com.coffee.bus.enums.DeviceAlarmEnum;
-import com.coffee.bus.enums.DeviceEnum;
 import com.coffee.bus.enums.PatientAlarmEnum;
 import com.coffee.bus.listener.event.bean.HisEvent;
 import com.coffee.bus.registry.device.DeviceRegistry;
@@ -462,67 +461,67 @@ public class DeviceInfoListener {
             return;
         }
         ++count;
-        BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
-        pump.setType(DeviceEnum.continuous);
-        pump.setClassification(String.valueOf(mark));
-        pump.setDeviceId("123");
-        pump.setPatientCode("456");
-        pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump.setPcaValidCount(RandomUtil.randomInt(100));
-        pump.setPcaInvalidCount(RandomUtil.randomInt(100));
-        pump.setPcaTotalCount(RandomUtil.randomInt(100));
-        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
-
-        Thread.sleep(5000);
-
-        BusDeviceRunningEntity pump1 = new BusDeviceRunningEntity();
-        pump1.setDeviceId("456");
-        pump1.setType(DeviceEnum.continuous);
-        pump1.setClassification(String.valueOf(mark));
-        pump1.setPatientCode("456");
-        pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump1.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump1.setPcaValidCount(RandomUtil.randomInt(100));
-        pump1.setPcaInvalidCount(RandomUtil.randomInt(100));
-        pump1.setPcaTotalCount(RandomUtil.randomInt(100));
-        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump1,pump1.getDeviceId()));
-
-        Thread.sleep(5000);
-
-        BusDeviceRunningEntity pump2 = new BusDeviceRunningEntity();
-        pump2.setType(DeviceEnum.continuous);
-        pump2.setDeviceId("456");
-        pump2.setClassification(String.valueOf(mark));
-        pump2.setPatientCode("789");
-        pump2.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump2.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump2.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump2.setPcaValidCount(RandomUtil.randomInt(100));
-        pump2.setPcaInvalidCount(RandomUtil.randomInt(100));
-        pump2.setPcaTotalCount(RandomUtil.randomInt(100));
-        pump2.setAlarm(DeviceAlarmEnum.Bubble);
-        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump2,pump2.getDeviceId()));
-
-
-        Thread.sleep(5000);
-
-        BusDeviceRunningEntity pump3 = new BusDeviceRunningEntity();
-        pump3.setDeviceId("456");
-        pump3.setClassification(String.valueOf(mark));
-        pump3.setType(DeviceEnum.continuous);
-        pump3.setPatientCode("456");
-        pump3.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump3.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump3.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-        pump3.setPcaValidCount(RandomUtil.randomInt(100));
-        pump3.setPcaInvalidCount(RandomUtil.randomInt(100));
-        pump3.setPcaTotalCount(RandomUtil.randomInt(100));
-        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump3,pump3.getDeviceId()));
-//        });
-        Thread.sleep(5000);
+//        BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
+//        pump.setType(DeviceEnum.continuous);
+//        pump.setClassification(String.valueOf(mark));
+//        pump.setDeviceId("123");
+//        pump.setPatientCode("456");
+//        pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump.setPcaValidCount(RandomUtil.randomInt(100));
+//        pump.setPcaInvalidCount(RandomUtil.randomInt(100));
+//        pump.setPcaTotalCount(RandomUtil.randomInt(100));
+//        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
+//
+//        Thread.sleep(5000);
+//
+//        BusDeviceRunningEntity pump1 = new BusDeviceRunningEntity();
+//        pump1.setDeviceId("456");
+//        pump1.setType(DeviceEnum.continuous);
+//        pump1.setClassification(String.valueOf(mark));
+//        pump1.setPatientCode("456");
+//        pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump1.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump1.setPcaValidCount(RandomUtil.randomInt(100));
+//        pump1.setPcaInvalidCount(RandomUtil.randomInt(100));
+//        pump1.setPcaTotalCount(RandomUtil.randomInt(100));
+//        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump1,pump1.getDeviceId()));
+//
+//        Thread.sleep(5000);
+//
+//        BusDeviceRunningEntity pump2 = new BusDeviceRunningEntity();
+//        pump2.setType(DeviceEnum.continuous);
+//        pump2.setDeviceId("456");
+//        pump2.setClassification(String.valueOf(mark));
+//        pump2.setPatientCode("789");
+//        pump2.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump2.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump2.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump2.setPcaValidCount(RandomUtil.randomInt(100));
+//        pump2.setPcaInvalidCount(RandomUtil.randomInt(100));
+//        pump2.setPcaTotalCount(RandomUtil.randomInt(100));
+//        pump2.setAlarm(DeviceAlarmEnum.Bubble);
+//        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump2,pump2.getDeviceId()));
+//
+//
+//        Thread.sleep(5000);
+//
+//        BusDeviceRunningEntity pump3 = new BusDeviceRunningEntity();
+//        pump3.setDeviceId("456");
+//        pump3.setClassification(String.valueOf(mark));
+//        pump3.setType(DeviceEnum.continuous);
+//        pump3.setPatientCode("456");
+//        pump3.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump3.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump3.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+//        pump3.setPcaValidCount(RandomUtil.randomInt(100));
+//        pump3.setPcaInvalidCount(RandomUtil.randomInt(100));
+//        pump3.setPcaTotalCount(RandomUtil.randomInt(100));
+//        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump3,pump3.getDeviceId()));
+////        });
+//        Thread.sleep(5000);
         String now = DateUtil.yesterday().toString();
         BusClinicEntity clinic = new BusClinicEntity();
         clinic.setPatientCode("456");
@@ -533,7 +532,7 @@ public class DeviceInfoListener {
         clinic.setWard("病区:"+now);
         clinic.setBedNo("床号:"+now);
         clinic.setTenantId("1505808170691784706");
-        clinic.setStartTime(DateUtil.yesterday());
+        clinic.setStartTime(DateUtil.date(1651116958000L));
         SpringUtil.publishEvent(new HisEvent(this,Arrays.asList(clinic),clinic.getTenantId()));
 
     }

+ 20 - 16
coffee-system/src/main/java/com/coffee/bus/websocket/listener/HisInfoListener.java

@@ -204,25 +204,29 @@ public class HisInfoListener {
     private void changedRunningClinic(BusClinicEntity clinic,PatientOperator<PatientCacheInfo> patientOperator){
         String originClinic = patientOperator.getClinicId();
         if(!clinic.getId().equals(originClinic)){
+            //找到该临床的最新输注数据并更新
             BusInfusionHistoryEntity infusion =
                     infusionHistoryService.getOne(new QueryWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getClinicId, clinic.getId())
-                            .orderByDesc(BusInfusionHistoryEntity::getStartTime).last("limit 1"));
-            //临床信息发生变化
-            if(patientOperator.getFinished()){
-                patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
-                        .eq(BusPatientEntity::getCode,clinic.getPatientCode())
-                        .eq(BusPatientEntity::getTenantId,clinic.getTenantId())
-                        .set(BusPatientEntity::getTmpFinished,false)
-                        .set(BusPatientEntity::getMonitorStartTime,infusion.getStartTime()));
-                patientOperator.setFinished(false);
-            }else {
-                //重新计算病人该次临床的开始时间
-                patientService
-                        .update(new UpdateWrapper<BusPatientEntity>().lambda()
-                                .eq(BusPatientEntity::getCode,clinic.getPatientCode())
-                                .eq(BusPatientEntity::getTenantId,clinic.getTenantId())
-                                .set(BusPatientEntity::getMonitorStartTime,infusion.getStartTime()));
+                            .orderByAsc(BusInfusionHistoryEntity::getStartTime).last("limit 1"));
+            if(infusion!=null){
+                //临床信息发生变化
+                if(patientOperator.getFinished()){
+                    patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
+                            .eq(BusPatientEntity::getCode,clinic.getPatientCode())
+                            .eq(BusPatientEntity::getTenantId,clinic.getTenantId())
+                            .set(BusPatientEntity::getTmpFinished,false)
+                            .set(BusPatientEntity::getMonitorStartTime,infusion.getStartTime()));
+                    patientOperator.setFinished(false);
+                }else {
+                    //重新计算病人该次临床的开始时间
+                    patientService
+                            .update(new UpdateWrapper<BusPatientEntity>().lambda()
+                                    .eq(BusPatientEntity::getCode,clinic.getPatientCode())
+                                    .eq(BusPatientEntity::getTenantId,clinic.getTenantId())
+                                    .set(BusPatientEntity::getMonitorStartTime,infusion.getStartTime()));
+                }
             }
+
         }
         patientOperator.setClinicId(clinic.getId());
         patientOperator.setWard(clinic.getWard());

+ 49 - 0
coffee-system/src/main/resources/mapper/bus/BusClinicMapper.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.coffee.bus.mapper.BusClinicMapper">
+
+    <resultMap id="stats" type="com.coffee.bus.service.dto.ClinicStatsQueryResult">
+        <result column="continue_dose" property="continueDose"/>
+        <result column="append_dose" property="appendDose"/>
+        <result column="input_dose" property="inputDose"/>
+        <result column="valid_count" property="validCount"/>
+        <result column="invalid_count" property="inValidCount"/>
+        <result column="upload_time" property="uploadTime"/>
+    </resultMap>
+
+    <select id="stats" resultMap="stats">
+            SELECT
+            <if test="query.continueDose!=false">
+                h.continue_dose as continue_dose,
+            </if>
+            <if test="query.appendDose!=false">
+                h.append_dose as append_dose,
+            </if>
+            <if test="query.inputDose!=false">
+                h.input_dose as input_dose,
+            </if>
+            <if test="query.validCount!=false">
+                h.pca_valid_count as valid_count,
+            </if>
+            <if test="query.inValidCount!=false">
+                h.pca_invalid_count as invalid_count,
+            </if>
+            h.upload_time
+            FROM
+            (select id from bus_infusion_history
+             <where>
+                 <if test="query.clinicId!=null">
+                     and clinic_id = #{query.clinicId}
+                 </if>
+                 <if test="query.infusionId!=null">
+                     and id = #{query.infusionId}
+                 </if>
+                 <if test="query.deviceId!=null">
+                     and device_id = #{query.deviceId}
+                 </if>
+             </where>)
+              as i
+             left JOIN (select * from bus_device_history) as h on h.infusion_id=i.id
+             order by h.upload_time asc
+    </select>
+</mapper>