浏览代码

add 镇痛访视单
add 医院his对接 连接条件

A17404李放 3 年之前
父节点
当前提交
1c54d4d7bb
共有 26 个文件被更改,包括 622 次插入88 次删除
  1. 5 0
      coffee-admin/Dockerfile
  2. 2 3
      coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java
  3. 1 1
      coffee-common/src/main/java/com/coffee/common/config/websocket/handler/Subscribe.java
  4. 3 9
      coffee-system/src/main/java/com/coffee/bus/controller/BusAlarmController.java
  5. 78 5
      coffee-system/src/main/java/com/coffee/bus/controller/BusClinicController.java
  6. 0 19
      coffee-system/src/main/java/com/coffee/bus/controller/BusConstantController.java
  7. 14 13
      coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java
  8. 4 1
      coffee-system/src/main/java/com/coffee/bus/controller/vo/ClinicStatsVo.java
  9. 3 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusClinicEntity.java
  10. 4 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java
  11. 114 4
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionModifyEntity.java
  12. 24 5
      coffee-system/src/main/java/com/coffee/bus/his/HisScriptSession.java
  13. 8 0
      coffee-system/src/main/java/com/coffee/bus/his/strategy/all/EqualsStrategyHandler.java
  14. 5 0
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java
  15. 14 16
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java
  16. 0 1
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusInfusionHistoryService.java
  17. 6 4
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java
  18. 99 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalClinicRecord.java
  19. 38 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalInfusionModify.java
  20. 32 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalInfusionRecord.java
  21. 111 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalRecordResult.java
  22. 3 0
      coffee-system/src/main/java/com/coffee/bus/service/dto/PatientMonitorResult.java
  23. 41 5
      coffee-system/src/main/java/com/coffee/bus/websocket/HisConnectionHandler.java
  24. 1 1
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  25. 10 1
      coffee-system/src/main/resources/mapper/bus/BusClinicMapper.xml
  26. 2 0
      coffee-system/src/main/resources/mapper/bus/BusPatientMapper.xml

+ 5 - 0
coffee-admin/Dockerfile

@@ -2,6 +2,11 @@ FROM docker.io/java:8
 
 ADD target/coffee-admin.jar /pump.jar
 RUN bash -c "touch /pump.jar"
+ENV TZ 'Asia/Shanghai'
+ENV LANG en_US.UTF-8
+ENV LANGUAGE en_US:en
+ENV LC_ALL en_US.UTF-8
+
 #ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/pump.jar"]
 ENTRYPOINT ["java", "-jar", "/pump.jar"]
 EXPOSE 9090

+ 2 - 3
coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java

@@ -33,15 +33,14 @@ public class DefaultMessageListener implements MessageListener {
     private final String id;
     private final TopicWrapper topicWrapper;
     private final ObjectMapper objectMapper;
-
+    private final  Set<ChannelContext> channelContexts;
     @Override
     public void onMessage(Message message, byte[] pattern) {
-        Set<ChannelContext> channelContexts = Subscribe.getSubscribeChannel(topicWrapper.getTopic());
         if (CollectionUtil.isNotEmpty(channelContexts)) {
             Set<ChannelContext> closeChannel = new HashSet<>();
             channelContexts.parallelStream()
                     .forEach(channel -> {
-                        if (TioUtils.checkBeforeIO(channel)) {
+                        if (!TioUtils.checkBeforeIO(channel)) {
                             closeChannel.add(channel);
                             return;
                         }

+ 1 - 1
coffee-common/src/main/java/com/coffee/common/config/websocket/handler/Subscribe.java

@@ -135,7 +135,7 @@ public abstract class Subscribe implements WsHandler {
                 @Override
                 public Object doInRedis(RedisConnection connection) throws DataAccessException {
                     CompletableFuture.runAsync(()->{
-                        connection.pSubscribe(new DefaultMessageListener(getId(),topicWrapper,objectMapper),topicWrapper.getTopic().getBytes());
+                        connection.pSubscribe(new DefaultMessageListener(getId(),topicWrapper,objectMapper,channelContexts),topicWrapper.getTopic().getBytes());
                     });
                     redisConnectionMap.put(topicWrapper.getTopic(),connection);
                     return null;

+ 3 - 9
coffee-system/src/main/java/com/coffee/bus/controller/BusAlarmController.java

@@ -47,14 +47,8 @@ public class BusAlarmController extends BaseCrudController<BusDeviceAlarmEntity,
         return deviceAlarmService;
     }
 
-    public static void main(String[] args) {
-        set(DeviceTypeEnum.continuous);
-    }
-
-
-    public static  void set(Object value){
-        Field ordinal = ReflectionUtils.findField(value.getClass(), "ordinal");
-        ordinal.setAccessible(true);
-        System.out.println( ReflectionUtils.getField(ordinal,value));
+    @Override
+    public String getPermissionPrefix() {
+        return "bus:alarm";
     }
 }

+ 78 - 5
coffee-system/src/main/java/com/coffee/bus/controller/BusClinicController.java

@@ -1,17 +1,26 @@
 package com.coffee.bus.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.coffee.bus.controller.vo.ClinicStatsVo;
-import com.coffee.bus.service.LocalBusClinicService;
-import com.coffee.bus.service.dto.ClinicQuery;
-import com.coffee.bus.service.dto.ClinicResult;
-import com.coffee.bus.service.dto.ClinicStatsReturnResult;
+import com.coffee.bus.entity.*;
+import com.coffee.bus.service.*;
+import com.coffee.bus.service.dto.*;
+import com.coffee.common.exception.CustomException;
 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.*;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
 /**
  * @author lifang
  * @version 1.0.0
@@ -25,7 +34,10 @@ import org.springframework.web.bind.annotation.*;
 @Api(tags = "病人临床手术管理",description = "统一权限前缀(bus:clinic),例如新增bus:clinic:add")
 public class BusClinicController {
     private final LocalBusClinicService clinicService;
-
+    private final LocalBusEvaluationService evaluationService;
+    private final LocalBusInfusionHistoryService infusionHistoryService;
+    private final LocalBusInfusionModifyService infusionModifyService;
+    private final LocalBusDeviceHistoryService deviceHistoryService;
 
     @PostMapping("/stats")
     @ApiOperation(value = "临床过程中的数据记录",notes = "权限【无】")
@@ -40,4 +52,65 @@ public class BusClinicController {
     public R<IPage<ClinicResult>> page(@RequestBody ClinicQuery query) {
         return R.success(clinicService.pageQuery(query));
     }
+
+
+    @PostMapping("/anal/record/{clinicId}")
+    @SaCheckPermission("bus:clinic:query")
+    @ApiOperation(value = "查询临床信息的镇痛访视记录单",notes = "权限【bus:clinic:query】")
+    public R<ClinicAnalRecordResult> analRecord(@PathVariable("clinicId") String clinicId){
+        ClinicAnalRecordResult result = new ClinicAnalRecordResult();
+        BusClinicEntity clinic = clinicService.getById(clinicId);
+        if(clinic==null){
+            throw new CustomException("该临床信息不存在");
+        }
+        //填充临床信息
+        result.setClinic(ClinicAnalClinicRecord.parse(clinic));
+        CompletableFuture
+                .runAsync(()->{
+                    //填充评价记录
+                    result.setEvaluations(evaluationService.list(new QueryWrapper<BusEvaluationEntity>().lambda().eq(BusEvaluationEntity::getClinicId,clinicId).orderByAsc(BusEvaluationEntity::getEvaluateTime)));
+                })
+                .thenAcceptAsync(ignore->{
+                    //填充输注记录
+                    List<BusInfusionHistoryEntity> infusionHistories = infusionHistoryService.list(new QueryWrapper<BusInfusionHistoryEntity>().lambda()
+                            .eq(BusInfusionHistoryEntity::getClinicId, clinicId)
+                            .orderByAsc(BusInfusionHistoryEntity::getStartTime));
+                    List<String> infusionIds = infusionHistories.stream().map(BusInfusionHistoryEntity::getId).collect(Collectors.toList());
+                    List<BusInfusionModifyEntity> infusionModifies = infusionModifyService.list(new QueryWrapper<BusInfusionModifyEntity>().lambda()
+                            .in(BusInfusionModifyEntity::getInfusionId, infusionIds));
+                    result.fillInfusionRecords(infusionHistories,infusionModifies);
+                })
+                .thenAccept(ignore->{
+                    List<String> infusionIds = result.getInfusionRecords().stream().map(ClinicAnalInfusionRecord::getId).collect(Collectors.toList());
+                    List<BusDeviceHistoryEntity> deviceHistories = deviceHistoryService.list(new QueryWrapper<BusDeviceHistoryEntity>()
+                            .lambda()
+                            .select(BusDeviceHistoryEntity::getInfusionId,BusDeviceHistoryEntity::getPcaValidCount,BusDeviceHistoryEntity::getInfusionModifyId,
+                                    BusDeviceHistoryEntity::getPcaInvalidCount,BusDeviceHistoryEntity::getInputDose,BusDeviceHistoryEntity::getUploadTime)
+                            .in(BusDeviceHistoryEntity::getInfusionId, infusionIds)
+                            .eq(BusDeviceHistoryEntity::getMaster, true));
+                    //标记输注
+                    result.markInfusion(deviceHistories);
+                    List<ClinicStatsQueryResult> statsQueryResults = deviceHistories.stream().map(history -> {
+                        ClinicStatsQueryResult statsQueryResult = new ClinicStatsQueryResult();
+                        statsQueryResult.setInputDose(history.getInputDose());
+                        statsQueryResult.setInValidCount(history.getPcaInvalidCount());
+                        statsQueryResult.setValidCount(history.getPcaValidCount());
+                        statsQueryResult.setUploadTime(history.getUploadTime());
+                        return statsQueryResult;
+                    }).collect(Collectors.toList());
+                    //填充统计信息
+                    result.setStats(ClinicStatsReturnResult.of(statsQueryResults));
+                })
+                .join()
+        ;
+
+
+
+        //填充输注信息和输注修改参数
+
+        //填充统计图表
+
+
+        return R.success(result);
+    }
 }

+ 0 - 19
coffee-system/src/main/java/com/coffee/bus/controller/BusConstantController.java

@@ -34,25 +34,6 @@ public class BusConstantController {
     private HashMap<ConstantEnum, AbstractConstantService> constantHashMap=new HashMap<>();
 
 
-    @ApiOperation("该接口仅用来展示 常量-医生 的数据接口,无任何实际意义")
-    @PostMapping("/doctor")
-    private R doctor(@RequestBody BusConDoctor doctor){
-        return R.success();
-    }
-
-    @ApiOperation("该接口仅用来展示 常量-混合 的数据接口,无任何实际意义")
-    @PostMapping("/mix")
-    private R mix(@RequestBody BusConMixEntity doctor){
-        return R.success();
-    }
-
-
-    @ApiOperation("该接口仅用来展示 常量-报警 的数据接口,无任何实际意义")
-    @PostMapping("/alarm")
-    private R alarm(@RequestBody BusConAlarmEntity doctor){
-        return R.success();
-    }
-
     @Autowired
     public BusConstantController(List<AbstractConstantService> constantList) {
         constantList.stream().collect(Collectors.groupingBy(AbstractConstantService::getName)).forEach((k, vs)->{

+ 14 - 13
coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java

@@ -245,6 +245,12 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
             BusInfusionHistoryEntity infusion = infusionService.getById(patient.getInfusionId());
             result.setPatient(patient);
             result.setInfusion(infusion);
+            BusDeviceRunningEntity deviceRunning = deviceRunningService.getOne(new QueryWrapper<BusDeviceRunningEntity>()
+                    .lambda()
+                    .select(BusDeviceRunningEntity::getAlias).eq(BusDeviceRunningEntity::getId, infusion.getId()));
+            if(deviceRunning!=null){
+                infusion.setAlias(deviceRunning.getAlias());
+            }
             if(StrUtil.isNotEmpty(infusion.getClinicId())){
                 result.setClinic(clinicService.getById(infusion.getClinicId()));
             }
@@ -275,18 +281,12 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
     }
 
 
-    //todo 使用
-    @PostMapping("/pull/async/{hospitalId}/{patientCode}")
-    @ApiOperation(value = "异步更新患者信息,即等待更新完成后返回更新结果")
-    public DeferredResult<R> syn(@PathVariable("hospitalId") String hospitalId, @PathVariable("patientCode")String patientCode){
-        DeferredResult<R> result = new DeferredResult<>();
-        result.onCompletion(()->{
 
-        });
-        result.onTimeout(()->{
-            R.fail("响应超时");
-        });
-        return result;
+    @PostMapping("/pull/async")
+    @SaCheckPermission("device:patient:pull")
+    @ApiOperation(value = "同步更新患者信息,超时时间默认为10s,超时后数据返回继续处理,输注监控",notes = "权限标识为【bus:patient:pull】")
+    public DeferredResult<R<BusClinicEntity>> syn(@RequestAttribute("tenantId") String tenantId, @RequestBody GetPatientInfoVo vo){
+        return patientService.getPatientInfoFromHis(tenantId,vo.getPatientCode(),vo.getTimeout(),false);
     }
 
     /**
@@ -298,9 +298,10 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
      * @return R
      */
     @PostMapping("/pull/sync")
-    @ApiOperation(value = "同步更新患者信息,超时时间默认为10s,即立刻返回更新结果")
+    @SaCheckPermission("device:patient:pull")
+    @ApiOperation(value = "同步更新患者信息,超时时间默认为10s,超时后数据返回则不进行处理,无泵更新",notes = "权限标识为【bus:patient:pull】")
     public DeferredResult<R<BusClinicEntity>>  async(@RequestAttribute("tenantId") String tenantId, @RequestBody GetPatientInfoVo vo){
-        return patientService.syncGetPatientInfoFromHis(tenantId,vo.getPatientCode(),vo.getTimeout());
+        return patientService.getPatientInfoFromHis(tenantId,vo.getPatientCode(),vo.getTimeout(),true);
     }
 
 

+ 4 - 1
coffee-system/src/main/java/com/coffee/bus/controller/vo/ClinicStatsVo.java

@@ -3,7 +3,7 @@ package com.coffee.bus.controller.vo;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-
+import java.util.*;
 /**
  * @author lifang
  * @version 1.0.0
@@ -30,4 +30,7 @@ public class ClinicStatsVo {
     private boolean validCount;
     @ApiModelProperty("是否统计无效次数")
     private boolean inValidCount;
+
+    @ApiModelProperty("参数修改id")
+    private List<String> infusionModifyIds;
 }

+ 3 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusClinicEntity.java

@@ -50,6 +50,9 @@ public class BusClinicEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "手术监护结束时间")
     private Date endTime;
 
+    @ApiModelProperty(value = "asa")
+    private String asa;
+
     @ApiModelProperty(value = "患者姓名")
     @Length(max = 255,message = "患者姓名长度不得超过255个字节")
     private String patientName;

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

@@ -50,6 +50,10 @@ public class BusInfusionHistoryEntity extends CommonDeviceParam<String,String> {
     @ApiModelProperty(value = "输注开始时间,即本次运行开机时间",readOnly = true)
     private Date startTime;
 
+    @ApiModelProperty("泵别名")
+    @TableField(exist = false)
+    private String alias;
+
     @ApiModelProperty(value = "是否已撤泵,0、未撤泵1、已撤泵")
     @JsonIgnore
     private Boolean isUndo;

+ 114 - 4
coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionModifyEntity.java

@@ -5,8 +5,6 @@ import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.coffee.bus.entity.common.CommonDeviceParam;
-import com.coffee.bus.entity.common.DeviceProperties;
 import com.coffee.bus.enums.DeviceTypeEnum;
 import com.coffee.common.entity.TenantGenericEntity;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -37,7 +35,7 @@ import java.util.Date;
 @Accessors(chain = true)
 @TableName(value = "bus_infusion_modify",autoResultMap = true)
 @ApiModel(value="设备输注参数修改记录", description="当输注参数发生修改时,在此表中进行记录")
-public class BusInfusionModifyEntity extends DeviceProperties<String,String> {
+public class BusInfusionModifyEntity extends TenantGenericEntity<String,String> {
 
     @ApiModelProperty(value = "输注记录")
     private String infusionId;
@@ -45,14 +43,126 @@ public class BusInfusionModifyEntity extends DeviceProperties<String,String> {
     @ApiModelProperty(value = "参数修改时间")
     private Date modifyTime;
 
+    @ApiModelProperty(value = "网络泵id",readOnly = true)
+    private String deviceId;
 
+    @ApiModelProperty(value = "数据分类号,标识某些数据属于同一个输注",readOnly = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private String classification;
+
+    @ApiModelProperty(value = "数据编号",readOnly = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private Integer dataNumber;
+
+    @ApiModelProperty(value = "泵类型",readOnly = true)
+    @TableField(updateStrategy = FieldStrategy.NEVER)
+    private DeviceTypeEnum type;
+
+    @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 Integer selfControlLockTime;
+
+    @ApiModelProperty(value = "公共参数-自控次数",readOnly = true)
+    private Integer 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)
+    private Integer electricQuantity;
     public static BusInfusionModifyEntity parseRunningInfo(BusDeviceRunningEntity running){
         BusInfusionModifyEntity entity = new BusInfusionModifyEntity();
         entity.setDeviceId(running.getDeviceId());
         entity.setTenantId(running.getTenantId());
         entity.setInfusionId(running.getInfusionId());
         entity.setType(running.getType());
-
         entity.setClassification(running.getClassification());
         entity.setTotalDose(running.getTotalDose());
         entity.setFirstDose(running.getFirstDose());

+ 24 - 5
coffee-system/src/main/java/com/coffee/bus/his/HisScriptSession.java

@@ -1,6 +1,9 @@
 package com.coffee.bus.his;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSON;
@@ -19,7 +22,6 @@ import com.coffee.bus.service.LocalBusClinicService;
 import com.coffee.bus.service.LocalBusHospitalService;
 import com.coffee.common.cache.ClusterConfigStorage;
 import com.coffee.common.cache.value.Value;
-import com.coffee.common.exception.CustomException;
 import com.coffee.common.result.R;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -91,6 +93,16 @@ public class HisScriptSession {
         clusterConfigStorage.setConfig("info",hospital);
     }
 
+    /**
+     * 描述: 获取医院信息
+     * @author lifang
+     * @date 2022/5/16 9:29
+     * @param
+     * @return BusHospitalEntity
+     */
+    public BusHospitalEntity getHospitalInfo(){
+        return clusterConfigStorage.getConfig("info").as(BusHospitalEntity.class);
+    }
     /**
      * 描述: 同步拉取病人信息,超时后该次请求不再处理
      * @author lifang
@@ -246,15 +258,22 @@ public class HisScriptSession {
         Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(request),"utf-8"));
         executorService.schedule(()->{
             BusClinicEntity clinicEntity = clinicService.recentClinicByPatientCode("1", request.getPatientCode());
-            clinicEntity.setId(null);
-            clinicEntity.setMonitorType(true);
-            clinicEntity.setName("最新的临床数据3");
+            List<BusClinicEntity> clinic = new ArrayList<>();
             HisResponse hisResponse = new HisResponse();
             hisResponse.setMessageId(request.getMessageId());
             hisResponse.setSuccess(true);
             hisResponse.setTimestamp(new Date());
             hisResponse.setPatientCode(request.getPatientCode());
-            hisResponse.setContext(JSONUtil.toJsonStr(Arrays.asList(clinicEntity)));
+            for (int i = 0; i < 5; i++) {
+                clinicEntity.setId(null);
+                clinicEntity.setMonitorType(true);
+                clinicEntity.setName("新的临床数据"+i);
+                BusClinicEntity c = new BusClinicEntity();
+                BeanUtil.copyProperties(clinicEntity,c);
+                c.setStartTime(RandomUtil.randomDate(new Date(), DateField.HOUR_OF_DAY,-30,10));
+                clinic.add(c);
+            }
+            hisResponse.setContext(JSONUtil.toJsonStr(clinic));
             response(hisResponse);
         },1,TimeUnit.SECONDS);
     }

+ 8 - 0
coffee-system/src/main/java/com/coffee/bus/his/strategy/all/EqualsStrategyHandler.java

@@ -2,6 +2,7 @@ package com.coffee.bus.his.strategy.all;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.service.LocalBusClinicService;
 import com.coffee.bus.his.strategy.HisStrategyHandler;
@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -49,6 +51,12 @@ public class EqualsStrategyHandler implements HisAllStrategyHandler {
         source.sort(Comparator.comparing(BusClinicEntity::getStartTime));
         target.sort(Comparator.comparing(BusClinicEntity::getStartTime));
         for (int i = 0; i < source.size(); i++) {
+            BusClinicEntity targetClinic= source.get(i);
+            if(i<source.size()-1){
+                targetClinic.setFinished(true);
+            }else {
+                targetClinic.setFinished(false);
+            }
             clinicService.compareFromHis(source.get(i),target.get(i));
         }
     }

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

@@ -149,6 +149,11 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
         Assert.hasText(source.getTenantId(),"LocalBusClinicService.insertFromHis方法调用时,source参数tenantId不能为空");
         Assert.hasText(source.getPatientCode(),"LocalBusClinicService.insertFromHis方法调用时,source参数patientCode不能为空");
         Assert.hasText(source.getName(),"LocalBusClinicService.insertFromHis方法调用时,source参数name不能为空");
+        this.update(new UpdateWrapper<BusClinicEntity>()
+                .lambda()
+                .eq(BusClinicEntity::getPatientCode,source.getPatientCode()).eq(BusClinicEntity::getTenantId,source.getTenantId())
+                .eq(BusClinicEntity::getMonitorType,true)
+                .set(BusClinicEntity::getFinished,true));
         this.save(source);
         infusionHistoryService.adjustInfusionByClinic(source.getId(),source.getPatientCode(),source.getTenantId(),source.getStartTime());
     }

+ 14 - 16
coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java

@@ -6,21 +6,19 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.coffee.bus.entity.BusHospitalEntity;
+import com.coffee.bus.his.HisScriptSession;
+import com.coffee.bus.his.HisScriptSessionManager;
 import com.coffee.bus.his.strategy.HisStrategyEnum;
 import com.coffee.bus.mapper.BusHospitalMapper;
 import com.coffee.bus.utils.CodeUtils;
 import com.coffee.common.config.mybatis.GetNameInterface;
 import com.coffee.common.crud.BaseService;
 import com.coffee.common.exception.CustomException;
-import org.hibernate.validator.constraints.Length;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.Optional;
-import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -31,7 +29,9 @@ import java.util.stream.Collectors;
  */
 @Service
 public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusHospitalEntity,String> implements CommandLineRunner, GetNameInterface<String,String> {
-    private static Map<String,BusHospitalEntity> hospitalMap=new HashMap<>();
+    @Autowired
+    @Lazy
+    private HisScriptSessionManager scriptSessionManager;
     @Override
     public void validateBeforeSave(BusHospitalEntity entity) {
         long id = IdWorker.getId();
@@ -71,27 +71,24 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
 
     @Override
     public void postSave(BusHospitalEntity entity) {
-        hospitalMap.put(entity.getId(),entity);
+        HisScriptSession hisScriptSession = scriptSessionManager.get(entity.getId());
+        hisScriptSession.refresh(entity);
     }
 
     @Override
     public void postUpdate(BusHospitalEntity entity) {
-        hospitalMap.put(entity.getId(),entity);
+        HisScriptSession hisScriptSession = scriptSessionManager.get(entity.getId());
+        hisScriptSession.refresh(entity);
     }
 
     @Override
     public void postDelete(String id) {
-        hospitalMap.remove(id);
+        scriptSessionManager.unregister(id);
     }
 
     @Override
     public void run(String... args) {
         saveDefaultHospital();
-        List<BusHospitalEntity> hospitalList = this.list();
-        if(CollectionUtil.isNotEmpty(hospitalList)){
-            Map<String, List<BusHospitalEntity>> collect = hospitalList.stream().collect(Collectors.groupingBy(BusHospitalEntity::getId));
-            collect.forEach((k,v)->hospitalMap.put(k,v.get(0)));
-        }
     }
 
 
@@ -100,7 +97,8 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
         if(StrUtil.isAllBlank(id)){
             return "";
         }
-        return Optional.ofNullable(hospitalMap.get(id)).orElse(new BusHospitalEntity()).getName();
+        HisScriptSession hisScriptSession = scriptSessionManager.get(id);
+        return Optional.ofNullable(hisScriptSession.getHospitalInfo()).orElse(new BusHospitalEntity()).getName();
     }
 
 

+ 0 - 1
coffee-system/src/main/java/com/coffee/bus/service/LocalBusInfusionHistoryService.java

@@ -166,7 +166,6 @@ public class LocalBusInfusionHistoryService extends BaseService<BusInfusionHisto
             infusionHistories.forEach(infusion->infusion.setClinicId(clinicId));
             clinicService.update(new UpdateWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getId,clinicId)
             .set(BusClinicEntity::getMonitorStartTime,infusionHistories.get(0).getStartTime()));
-
         }
 
     }

+ 6 - 4
coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java

@@ -15,6 +15,7 @@ import com.coffee.bus.entity.PatientDeviceRepeatDomain;
 import com.coffee.bus.enums.DeviceAlarmEnum;
 import com.coffee.bus.enums.DeviceStatusEnum;
 import com.coffee.bus.enums.PatientAlarmEnum;
+import com.coffee.bus.his.HisScriptSession;
 import com.coffee.bus.his.HisScriptSessionManager;
 import com.coffee.bus.his.strategy.HisStrategyManager;
 import com.coffee.bus.service.dto.*;
@@ -102,13 +103,14 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
     }
 
     /**
-     * 异步获取病人信息 todo
+     * 获取病人信息
      * @param hospitalId  医院id
      * @param patientCode 病号
+     * @param sync 是否为同步操作
      */
-    public DeferredResult<R<BusClinicEntity>> syncGetPatientInfoFromHis(String hospitalId, String patientCode, long timeout){
-        return scriptSessionManager.get(hospitalId)
-                .syncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS);
+    public DeferredResult<R<BusClinicEntity>> getPatientInfoFromHis(String hospitalId, String patientCode, long timeout,boolean sync){
+        HisScriptSession hisScriptSession = scriptSessionManager.get(hospitalId);
+        return sync?hisScriptSession.syncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS):hisScriptSession.asyncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS,true);
     }
 
     /**

+ 99 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalClinicRecord.java

@@ -0,0 +1,99 @@
+package com.coffee.bus.service.dto;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
+import com.coffee.bus.entity.BusClinicEntity;
+import com.coffee.bus.entity.FormulaDrugDomain;
+import com.coffee.common.enums.SexEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.hibernate.validator.constraints.Length;
+
+import java.util.List;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName ClinicAnalClinicRecord.java
+ * @Description TODO
+ * @createTime 2022年05月16日 11:09:00
+ */
+@ApiModel("访视记录单中返回的临床数据")
+@Data
+public class ClinicAnalClinicRecord {
+    private String id;
+
+    private String patientCode;
+
+    private String surgeryName;
+
+    @ApiModelProperty(value = "患者姓名")
+    @Length(max = 255,message = "患者姓名长度不得超过255个字节")
+    private String patientName;
+
+    @ApiModelProperty(value = "患者性别")
+    private SexEnum patientGender;
+
+    @ApiModelProperty(value = "患者年龄")
+    private Integer patientAge;
+
+    @ApiModelProperty(value = "体重")
+    @Length(max = 255,message = "体重不得超过255个字节")
+    private String weight;
+
+    @ApiModelProperty(value = "身高")
+    @Length(max = 255,message = "身高不得超过255个字节")
+    private String height;
+
+    @ApiModelProperty(value = "病区")
+    @Length(max = 255,message = "病区")
+    private String ward;
+
+    @ApiModelProperty(value = "病床号")
+    @Length(max = 255,message = "病床号长度不得超过255个字节")
+    private String bedNo;
+
+    @ApiModelProperty(value = "asa分级")
+    private String asa;
+
+    @ApiModelProperty(value = "配方")
+    @TableField(typeHandler = FastjsonTypeHandler.class,javaType = true)
+    private List<FormulaDrugDomain> formula;
+
+    @ApiModelProperty(value = "麻醉医生")
+    @Length(max = 255,message = "麻醉医生不得超过255个字节")
+    private String anaDoctor;
+
+    @ApiModelProperty(value = "麻醉方式")
+    private String anaType;
+
+    @ApiModelProperty(value = "镇痛方式")
+    private String analType;
+
+    @ApiModelProperty(value = "手术医生")
+    @Length(max = 255,message = "手术医生不得超过255个字节")
+    private String surgeryDoctor;
+
+
+    public static ClinicAnalClinicRecord parse(BusClinicEntity clinic){
+        ClinicAnalClinicRecord clinicRecord = new ClinicAnalClinicRecord();
+        clinicRecord.setId(clinic.getId());
+        clinicRecord.setPatientCode(clinic.getPatientCode());
+        clinicRecord.setSurgeryName(clinic.getName());
+        clinicRecord.setPatientName(clinic.getPatientName());
+        clinicRecord.setPatientAge(clinic.getPatientAge());
+        clinicRecord.setPatientGender(clinic.getPatientGender());
+        clinicRecord.setWeight(clinic.getWeight());
+        clinicRecord.setHeight(clinic.getHeight());
+        clinicRecord.setBedNo(clinic.getBedNo());
+        clinicRecord.setAsa(clinic.getAsa());
+        clinicRecord.setFormula(clinic.getFormula());
+        clinicRecord.setAnaDoctor(clinic.getAnaDoctor());
+        clinicRecord.setAnaType(clinic.getAnaType());
+        clinicRecord.setAnalType(clinic.getAnalType());
+        clinicRecord.setSurgeryDoctor(clinic.getSurgeryDoctor());
+        return clinicRecord;
+    }
+
+}

+ 38 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalInfusionModify.java

@@ -0,0 +1,38 @@
+package com.coffee.bus.service.dto;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.coffee.bus.entity.BusInfusionModifyEntity;
+import com.coffee.bus.entity.common.DeviceProperties;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 访视记录单中返回的输注数据
+ * @Author lifang
+ * @Date 11:08 2022/5/16
+ * @Description
+ * @Param
+ * @return
+ **/
+@ApiModel("访视记录单中返回的输注修改数据")
+@Data
+public class ClinicAnalInfusionModify extends DeviceProperties<String,String> {
+    @ApiModelProperty(value = "输注记录Id")
+    private String infusionId;
+
+    @ApiModelProperty(value = "参数修改时间")
+    private Date modifyTime;
+
+    @ApiModelProperty("是否打印")
+    private boolean print;
+
+    public static ClinicAnalInfusionModify parse(BusInfusionModifyEntity source){
+        ClinicAnalInfusionModify result = new ClinicAnalInfusionModify();
+        BeanUtil.copyProperties(source,result);
+        return result;
+    }
+}

+ 32 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalInfusionRecord.java

@@ -0,0 +1,32 @@
+package com.coffee.bus.service.dto;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.coffee.bus.entity.BusInfusionHistoryEntity;
+import com.coffee.bus.entity.common.DeviceProperties;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.*;
+/**
+ * 访视记录单中返回的输注数据
+ * @Author lifang
+ * @Date 11:08 2022/5/16
+ * @Description
+ * @Param
+ * @return
+ **/
+@ApiModel("访视记录单中返回的输注数据")
+@Data
+public class ClinicAnalInfusionRecord extends DeviceProperties<String,String> {
+    @ApiModelProperty("参数修改记录")
+    private List<ClinicAnalInfusionModify> modifies;
+
+    @ApiModelProperty("是否打印")
+    private boolean print;
+
+    public static ClinicAnalInfusionRecord parse(BusInfusionHistoryEntity source){
+        ClinicAnalInfusionRecord result = new ClinicAnalInfusionRecord();
+        BeanUtil.copyProperties(source,result);
+        return result;
+    }
+}

+ 111 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/ClinicAnalRecordResult.java

@@ -0,0 +1,111 @@
+package com.coffee.bus.service.dto;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.coffee.bus.entity.BusDeviceHistoryEntity;
+import com.coffee.bus.entity.BusEvaluationEntity;
+import com.coffee.bus.entity.BusInfusionHistoryEntity;
+import com.coffee.bus.entity.BusInfusionModifyEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName ClinicAnalRecordResult.java
+ * @Description TODO
+ * @createTime 2022年05月16日 10:49:00
+ */
+@ApiModel("镇痛访视记录单返回结果")
+@Getter
+public class ClinicAnalRecordResult implements Serializable {
+
+    @ApiModelProperty("临床信息")
+    @Setter
+    private ClinicAnalClinicRecord clinic;
+
+    @ApiModelProperty("评价记录")
+    @Setter
+    private List<BusEvaluationEntity> evaluations;
+
+    @ApiModelProperty("输注记录")
+    private List<ClinicAnalInfusionRecord> infusionRecords;
+
+    @ApiModelProperty("统计图表")
+    @Setter
+    private ClinicStatsReturnResult stats;
+
+
+    private void setInfusionRecords(List<ClinicAnalInfusionRecord> infusionRecords){
+        this.infusionRecords=infusionRecords;
+    }
+
+    /**
+     * 描述: 填充并计算输注修改记录
+     * @author lifang
+     * @date 2022/5/16 15:03
+     * @param infusionHistories 输注历史记录
+     * @param infusionModifies 输注修改记录
+     * @return void
+     */
+    public void fillInfusionRecords(List<BusInfusionHistoryEntity> infusionHistories, List<BusInfusionModifyEntity> infusionModifies) {
+        List<ClinicAnalInfusionRecord> infusionRecords = infusionHistories.stream().map(ClinicAnalInfusionRecord::parse).collect(Collectors.toList());
+        List<ClinicAnalInfusionModify> modifies = infusionModifies.stream().map(ClinicAnalInfusionModify::parse).collect(Collectors.toList());
+        this.setInfusionRecords(infusionRecords);
+
+        Map<String, ClinicAnalInfusionRecord> recordHashMap = new HashMap<>();
+        infusionRecords.forEach(infusionRecord->recordHashMap.put(infusionRecord.getId(),infusionRecord));
+        Map<String, List<ClinicAnalInfusionModify>> modifyMapByInfusionId = modifies.stream().collect(Collectors.groupingBy(ClinicAnalInfusionModify::getInfusionId));
+        //将修改记录有输注记录绑定
+        modifyMapByInfusionId.forEach((k,v)->
+                recordHashMap.computeIfPresent(k,(id,infusion)->{
+                    infusion.setModifies(v);
+                    return infusion;
+                }));
+    }
+
+
+    /**
+     * 描述: 通过设备历史记录对输注信息进行标记
+     * @author lifang
+     * @date 2022/5/16 15:19
+     * @param histories
+     * @return void
+     */
+    public void markInfusion(List<BusDeviceHistoryEntity> histories){
+        Map<String, ClinicAnalInfusionRecord> recordHashMap = new HashMap<>();
+        Map<String, List<BusDeviceHistoryEntity>> historiesByInfusionId = histories.stream().collect(Collectors.groupingBy(BusDeviceHistoryEntity::getInfusionId));
+        infusionRecords.forEach(infusionRecord->recordHashMap.put(infusionRecord.getId(),infusionRecord));
+        historiesByInfusionId.forEach((infusionId,deviceHistories)->{
+            //找到对应的输注记录并标记
+            recordHashMap.computeIfPresent(infusionId, (k, v) -> {
+                v.setPrint(true);
+                markInfusionModify(v,deviceHistories);
+                return v;
+            });
+
+        });
+    }
+
+    private void markInfusionModify(ClinicAnalInfusionRecord record,List<BusDeviceHistoryEntity> histories){
+        Map<String, ClinicAnalInfusionModify> modifyHashMap = new HashMap<>();
+        List<ClinicAnalInfusionModify> modifies = record.getModifies();
+        if(CollectionUtil.isEmpty(modifies)){
+            return;
+        }
+        modifies.forEach(modify->modifyHashMap.put(modify.getId(),modify));
+
+        //找到对应的输注修改记录并标记
+        histories.forEach(history->modifyHashMap.computeIfPresent(history.getInfusionModifyId(),(k,v)->{
+            v.setPrint(true);
+            return v;
+        }));
+    }
+
+}

+ 3 - 0
coffee-system/src/main/java/com/coffee/bus/service/dto/PatientMonitorResult.java

@@ -130,6 +130,9 @@ public class PatientMonitorResult {
     @ApiModelProperty(value = "输注开始时间,即本次运行开机时间")
     private Date infusionStartTime;
 
+    @ApiModelProperty(value = "输注是否已结束")
+    private Boolean infusionFinished;
+
     @ApiModelProperty(value = "备注")
     private String remark;
 

+ 41 - 5
coffee-system/src/main/java/com/coffee/bus/websocket/HisConnectionHandler.java

@@ -1,15 +1,28 @@
 package com.coffee.bus.websocket;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.coffee.bus.entity.BusHospitalEntity;
 import com.coffee.bus.his.HisScriptSession;
 import com.coffee.bus.his.HisScriptSessionManager;
 import com.coffee.bus.service.LocalBusHospitalService;
 import com.coffee.common.config.websocket.MessagingRequest;
 import com.coffee.common.config.websocket.WebSocketConstant;
 import com.coffee.common.config.websocket.handler.Subscribe;
+import com.coffee.common.result.R;
 import lombok.AllArgsConstructor;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.tio.core.ChannelContext;
+import org.tio.core.Tio;
+import org.tio.websocket.common.WsResponse;
+
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author lifang
@@ -22,6 +35,8 @@ import org.tio.core.ChannelContext;
 @AllArgsConstructor
 public class HisConnectionHandler extends Subscribe {
     private final HisScriptSessionManager scriptSessionManager;
+    private final LocalBusHospitalService hospitalService;
+    private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
     @Override
     public String getId() {
         return WebSocketConstant.HIS_CONNECTION;
@@ -31,17 +46,38 @@ public class HisConnectionHandler extends Subscribe {
     public void onMessage(MessagingRequest message, ChannelContext channelContext) {
         //医院his脚本逻辑单独处理
         String tenantId = message.getTenantId();
-        channelContext.setAttribute(tenantId);
-        HisScriptSession hisScriptSession = scriptSessionManager.get(tenantId);
+        boolean close=false;
+        if(!"-1".equals(tenantId)){
+            Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(R.fail("连接参数错误,拒绝处理")),"utf-8"));
+            close=true;
+        }
+        List<String> params = message.getParams();
+        if (!close&&CollectionUtil.isEmpty(params)) {
+            Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(R.fail("连接参数为空,拒绝处理")),"utf-8"));
+            close=true;
+        }
+        BusHospitalEntity hospital = hospitalService.getOne(new QueryWrapper<BusHospitalEntity>().lambda().eq(BusHospitalEntity::getCode, params.get(0)));
+        if(!close&&hospital==null){
+            Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(R.fail(String.format("医院编码[{%s}]不存在,拒绝处理",params.get(0)))),"utf-8"));
+            close=true;
+        }
+        if(close){
+            executorService.schedule(()->  Tio.close(channelContext,"连接参数错误【"+JSONUtil.toJsonStr(message)+"】"),2, TimeUnit.SECONDS);
+            return ;
+        }
+        channelContext.set("tenantId",hospital.getId());
+        HisScriptSession hisScriptSession = scriptSessionManager.get(hospital.getId());
         //绑定
         hisScriptSession.bindChannel(channelContext);
     }
 
     @Override
     public void close(ChannelContext channelContext) {
-        String tenantId=String.valueOf(channelContext.getAttribute());
-        HisScriptSession hisScriptSession = scriptSessionManager.get(tenantId);
-        hisScriptSession.offline();
+        String tenantId=String.valueOf(channelContext.get("tenantId"));
+        if(StrUtil.isEmpty(tenantId)){
+            HisScriptSession hisScriptSession = scriptSessionManager.get(tenantId);
+            hisScriptSession.offline();
+        }
     }
 
     @Override

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

@@ -475,7 +475,7 @@ public class DeviceInfoListener {
      */
     private void handleAlarm(BusDeviceHistoryEntity history,DeviceOperator deviceOperator,List<Supplier<?>> cacheOperation){
         //不存在报警信息
-        if(history.getAlarm()==null){
+        if(history.getAlarm()==null||history.getAlarm().equals(DeviceAlarmEnum.None)){
             cacheOperation.add(()->{
                 deviceOperator.setAlarm(null);
                 return null;

+ 10 - 1
coffee-system/src/main/resources/mapper/bus/BusClinicMapper.xml

@@ -62,7 +62,16 @@
             </if>
         </where>)
         as i
-        left JOIN (select * from bus_device_history) as h on h.infusion_id=i.id
+        left JOIN (select * from bus_device_history
+        <where>
+            <if test="query.infusionModifyIds != null and query.infusionModifyIds.size > 0">
+                and infusionModifyIds in
+                <foreach item="infusionModifyId" index="index" collection="query.infusionModifyIds" open="(" separator="," close=")">
+                    #{infusionModifyId, jdbcType=VARCHAR}
+                </foreach>
+            </if>
+        </where>
+        ) as h on h.infusion_id=i.id
         order by h.upload_time asc
     </select>
 

+ 2 - 0
coffee-system/src/main/resources/mapper/bus/BusPatientMapper.xml

@@ -29,6 +29,7 @@
         <result column="device_id" property="deviceId"/>
         <result column="device_alias" property="deviceAlias"/>
         <result column="clinic_id" property="clinicId"/>
+        <result column="infusion_finished" property="infusionFinished"/>
         <result column="ward" property="ward"/>
         <result column="bed_no" property="bedNo"/>
         <result column="total_dose" property="totalDose"/>
@@ -151,6 +152,7 @@
         i.append_dose as append_dose,
         i.append_lock_time as append_lock_time,
         i.max_dose as max_dose,
+        i.finished as infusion_finished,
         i.electric_quantity as electric_quantity,
         i.warn_flow as warn_flow,
         i.self_control_count as self_control_count,