|
|
@@ -2,6 +2,7 @@ package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.SignUtil;
|
|
|
@@ -25,6 +26,7 @@ import com.coffee.bus.registry.patient.PatientRegistry;
|
|
|
import com.coffee.bus.registry.patient.bean.DeviceTimeSmallInfo;
|
|
|
import com.coffee.bus.registry.patient.bean.PatientCacheInfo;
|
|
|
import com.coffee.bus.service.*;
|
|
|
+import com.coffee.bus.websocket.handler.DeviceInfoHook;
|
|
|
import com.coffee.common.config.websocket.WebSocketConstant;
|
|
|
import com.coffee.common.enums.SexEnum;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -73,9 +75,15 @@ public class DeviceInfoListener {
|
|
|
private final LocalBusDeviceHistoryService historyService;
|
|
|
|
|
|
private final LocalBusPatientService patientService;
|
|
|
+
|
|
|
+ private final LocalBusClinicService clinicService;
|
|
|
+
|
|
|
+ private final List<DeviceInfoHook> deviceInfoHooks;
|
|
|
/**
|
|
|
* 监听上传的数据信息,
|
|
|
* 若设备详情发生变化,则及时通知相应的ws通道
|
|
|
+ * 当输注信息或新输注时,进行主副泵判断及切换
|
|
|
+ * 当新输注时,将关闭的临床重启
|
|
|
* @param infoEvent
|
|
|
*/
|
|
|
@EventListener
|
|
|
@@ -86,33 +94,45 @@ public class DeviceInfoListener {
|
|
|
log.info("开始处理时间------------------------[{}]",System.currentTimeMillis());
|
|
|
/****************处理泵数据 todo 后续交由上游处理****************/
|
|
|
BusDeviceRunningEntity device = infoEvent.getContent();
|
|
|
+ device.setMonitorType(true);
|
|
|
+ device.setMaster(true);
|
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
|
String deviceId = device.getDeviceId();
|
|
|
+ device.setUploadTime(device.getUploadTime()==null?new Date():device.getUploadTime());
|
|
|
DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getOperator(deviceId);
|
|
|
if (deviceOperator==null||!Boolean.TRUE.equals(deviceOperator.getEnable())) {
|
|
|
log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
|
return ;
|
|
|
}
|
|
|
- device.setUploadTime(device.getUploadTime()==null?new Date():device.getUploadTime());
|
|
|
+
|
|
|
+ //数据准确性判断
|
|
|
+ String classification = device.getClassification();
|
|
|
+ //默认为主泵,后续判断若不满足主泵条件,则替换为副泵
|
|
|
+ if(classification==null){
|
|
|
+ log.error("设备号:[{}]分包标识号为空,无法更新开始时间");
|
|
|
+ throw new RuntimeException("设备数据中分包标识不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
AtomicBoolean newInfusion=new AtomicBoolean(false);
|
|
|
AtomicBoolean valid = new AtomicBoolean(true);
|
|
|
//缓存操作
|
|
|
List<Supplier<?>> cacheOperation=new ArrayList<>();
|
|
|
- //处理设备运行数据
|
|
|
- boolean first = handleRunningInfo(device, deviceOperator,newInfusion,valid,cacheOperation);
|
|
|
+ //处理设备运行数据, 判断是否为注册后第一次开机,判断是否为新的输注信息
|
|
|
+ boolean first = handleRunningInfo(device, deviceOperator,newInfusion,cacheOperation);
|
|
|
+
|
|
|
+ //临床已结束,且设备非主设备
|
|
|
if(!valid.get()){
|
|
|
log.error("设备[{}]所绑定临床已结束且未关机,将数据[{}]丢弃",device.getDeviceId(),device.toString());
|
|
|
return;
|
|
|
+ }else {
|
|
|
+ //todo 重启临床数据
|
|
|
}
|
|
|
- //如果为新数据或者未撤泵
|
|
|
- if(newInfusion.get()||!deviceOperator.getUndo()){
|
|
|
- handlePatient(device,cacheOperation);
|
|
|
- }
|
|
|
- //更新/保存当前输注信息
|
|
|
- handleInfusionHistory(device,deviceOperator,newInfusion,cacheOperation);
|
|
|
+
|
|
|
//处理输注参数
|
|
|
- handleInfusionParam(device,deviceOperator,newInfusion,cacheOperation);
|
|
|
+ handleInfusion(device,deviceOperator,newInfusion,cacheOperation);
|
|
|
+
|
|
|
//处理历史运行数据
|
|
|
BusDeviceHistoryEntity history=handleRunningHistory(device);
|
|
|
//处理报警信息
|
|
|
@@ -126,6 +146,7 @@ public class DeviceInfoListener {
|
|
|
.eq(BusPatientEntity::getTenantId,device.getTenantId())
|
|
|
.set(BusPatientEntity::getInfusionId,device.getInfusionId()));
|
|
|
}
|
|
|
+
|
|
|
//todo 流速图处理
|
|
|
if(first){
|
|
|
deviceUsingService.save(device);
|
|
|
@@ -151,38 +172,33 @@ public class DeviceInfoListener {
|
|
|
* 设备运行数据处理,返回是否为第一次接受数据消息
|
|
|
* @param device 接收到的设备信息
|
|
|
* @param deviceOperator 设备缓存信息操作符
|
|
|
- * @param valid 设备数据是否有效
|
|
|
* @param newInfusion 是否为新的输注
|
|
|
* @return 是否为第一次接收数据消息
|
|
|
*/
|
|
|
- private boolean handleRunningInfo( BusDeviceRunningEntity device,DeviceOperator<DeviceCacheInfo> deviceOperator,AtomicBoolean newInfusion,AtomicBoolean valid,List<Supplier<?>> suppliers){
|
|
|
- //判断此条数据的分包标识是否发生了改变,若改变则
|
|
|
+ private boolean handleRunningInfo( BusDeviceRunningEntity device,DeviceOperator<DeviceCacheInfo> deviceOperator,AtomicBoolean newInfusion,List<Supplier<?>> suppliers){
|
|
|
+ //判断此条数据的分包标识是否发生了改变
|
|
|
String originClassify = deviceOperator.getClassification();
|
|
|
String classification = device.getClassification();
|
|
|
- //默认为主泵,后续判断若不满足主泵条件,则替换为副泵
|
|
|
- device.setMaster(true);
|
|
|
- if(classification==null){
|
|
|
- log.error("设备号:[{}]分包标识号为空,无法更新开始时间");
|
|
|
- newInfusion.set(true);
|
|
|
- throw new RuntimeException("设备数据中分包标识不能为空");
|
|
|
- }
|
|
|
String usingId = deviceOperator.getUsingId();
|
|
|
+ device.setIsUndo(deviceOperator.getUndo());
|
|
|
//todo 这部分操作交由上游处理
|
|
|
device.setTenantId(deviceOperator.getTenantId());
|
|
|
- device.setMonitorType(true);
|
|
|
+
|
|
|
+// PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode());
|
|
|
+// Boolean finished = patientOperator.getFinished();
|
|
|
if(!classification.equals(originClassify)){
|
|
|
newInfusion.set(true);
|
|
|
//启动新的输注,则撤泵标识取消
|
|
|
device.setIsUndo(false);
|
|
|
//分包标识发生了改变,设备开机时间重新计算
|
|
|
device.setStartTime(new Date());
|
|
|
- }else {
|
|
|
- PatientOperator<PatientCacheInfo> patient = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode());
|
|
|
- Boolean finished = patient.getFinished();
|
|
|
- if(Boolean.TRUE.equals(finished)){
|
|
|
- //分包标识未改变且临床已结束 ,则此次数据无效
|
|
|
- valid.set(false);
|
|
|
- }
|
|
|
+ //todo 处理临床数据
|
|
|
+// if(Boolean.TRUE.equals(finished)){
|
|
|
+// 将临床重新开启
|
|
|
+// clinicService
|
|
|
+// .update(new UpdateWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getId,patientOperator.getClinicId())
|
|
|
+// .set(BusClinicEntity::getFinished,false));
|
|
|
+// }
|
|
|
}
|
|
|
boolean first=false;
|
|
|
if(StrUtil.isNullOrUndefined(usingId)){
|
|
|
@@ -193,14 +209,18 @@ public class DeviceInfoListener {
|
|
|
first=true;
|
|
|
}else {
|
|
|
device.setId(usingId);
|
|
|
- device.setStartTime(deviceOperator.getStartTime());
|
|
|
+ if(!newInfusion.get()){
|
|
|
+ device.setStartTime(deviceOperator.getStartTime());
|
|
|
+ }
|
|
|
}
|
|
|
suppliers.add(()->{
|
|
|
//更新设备缓存数据
|
|
|
if(newInfusion.get()){
|
|
|
deviceOperator.setUndo(false);
|
|
|
+// patientOperator.setFinished(false);
|
|
|
}
|
|
|
deviceOperator.setClassification(device.getClassification());
|
|
|
+
|
|
|
deviceOperator.setTenantId(device.getTenantId());
|
|
|
deviceOperator.setUsingId(device.getId());
|
|
|
deviceOperator.setStatus(device.getRunState());
|
|
|
@@ -347,7 +367,8 @@ public class DeviceInfoListener {
|
|
|
//检测数据库是否存在该输注信息
|
|
|
infusionHistory.setId(String.valueOf(IdWorker.getId()));
|
|
|
infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
|
|
|
- .eq(BusInfusionHistoryEntity::getId,originInfusionId)
|
|
|
+ .eq(BusInfusionHistoryEntity::getDeviceId,device.getDeviceId())
|
|
|
+ .eq(BusInfusionHistoryEntity::getFinished,false)
|
|
|
.set(BusInfusionHistoryEntity::getFinished,true));
|
|
|
infusionHistoryService.save(infusionHistory);
|
|
|
}else {
|
|
|
@@ -362,28 +383,27 @@ public class DeviceInfoListener {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 对输注参数进行判断处理
|
|
|
+ * 处理输注信息
|
|
|
* @param device 设备运行数据
|
|
|
* @param deviceOperator 设备操作符
|
|
|
* @param newInfusion 是否为新的输注记录
|
|
|
* @param cacheOperation 缓存操作
|
|
|
*/
|
|
|
- private void handleInfusionParam(BusDeviceRunningEntity device, DeviceOperator<DeviceCacheInfo> deviceOperator, AtomicBoolean newInfusion,List<Supplier<?>> cacheOperation) {
|
|
|
+ private void handleInfusion(BusDeviceRunningEntity device, DeviceOperator<DeviceCacheInfo> deviceOperator, AtomicBoolean newInfusion, List<Supplier<?>> cacheOperation) {
|
|
|
+ handleInfusionHistory(device,deviceOperator,newInfusion,cacheOperation);
|
|
|
BusInfusionModifyEntity busInfusionModify = BusInfusionModifyEntity.parseRunningInfo(device);
|
|
|
String signHex = busInfusionModify.signParam(sign);
|
|
|
- if(newInfusion.get()){
|
|
|
- //新的输注记录直接生成新的输注参数
|
|
|
- infusionModifyService.save(busInfusionModify);
|
|
|
- cacheOperation.add(()->{
|
|
|
- deviceOperator.setInfusionParam(signHex);
|
|
|
- return null;
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
String infusionParam = deviceOperator.getInfusionParam();
|
|
|
- if(StrUtil.isEmpty(infusionParam)||!infusionParam.equals(signHex)){
|
|
|
- //输注参数发生变化, todo 则根据参数修改时间 进行主副泵的判别
|
|
|
+ //输注参数已发生变化
|
|
|
+ if(ObjectUtil.notEqual(signHex,infusionParam)){
|
|
|
+ //输注参数改变
|
|
|
infusionModifyService.save(busInfusionModify);
|
|
|
+ //输注参数变化后重启临床并且主副泵判断 todo
|
|
|
+ if (CollectionUtil.isNotEmpty(deviceInfoHooks)) {
|
|
|
+ deviceInfoHooks.forEach(hook->hook.infusionParamModify(device,deviceOperator,cacheOperation,newInfusion.get()));
|
|
|
+ }
|
|
|
+ handlePatient(device,cacheOperation);
|
|
|
+ //todo 输注参数发生变化
|
|
|
cacheOperation.add(()->{
|
|
|
deviceOperator.setInfusionParam(signHex);
|
|
|
return null;
|
|
|
@@ -443,7 +463,7 @@ public class DeviceInfoListener {
|
|
|
}
|
|
|
|
|
|
public static int count=1;
|
|
|
- public static int mark=0;
|
|
|
+ public static long mark=System.currentTimeMillis();
|
|
|
@Scheduled(cron = "0/20 * * * * ?")
|
|
|
public void send() throws InterruptedException {
|
|
|
// List<BusDeviceRunningEntity> list = deviceUsingService.list();
|
|
|
@@ -452,10 +472,9 @@ public class DeviceInfoListener {
|
|
|
return;
|
|
|
}
|
|
|
++count;
|
|
|
- mark=mark+1;
|
|
|
BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
|
|
|
pump.setType(DeviceEnum.continuous);
|
|
|
- pump.setClassification("1");
|
|
|
+ pump.setClassification(String.valueOf(mark));
|
|
|
pump.setDeviceId("123");
|
|
|
pump.setPatientCode("456");
|
|
|
pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
@@ -471,7 +490,7 @@ public class DeviceInfoListener {
|
|
|
BusDeviceRunningEntity pump1 = new BusDeviceRunningEntity();
|
|
|
pump1.setDeviceId("456");
|
|
|
pump1.setType(DeviceEnum.continuous);
|
|
|
- pump1.setClassification("1");
|
|
|
+ pump1.setClassification(String.valueOf(mark));
|
|
|
pump1.setPatientCode("456");
|
|
|
pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
@@ -486,7 +505,7 @@ public class DeviceInfoListener {
|
|
|
BusDeviceRunningEntity pump2 = new BusDeviceRunningEntity();
|
|
|
pump2.setType(DeviceEnum.continuous);
|
|
|
pump2.setDeviceId("456");
|
|
|
- pump2.setClassification("2");
|
|
|
+ pump2.setClassification(String.valueOf(mark));
|
|
|
pump2.setPatientCode("789");
|
|
|
pump2.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
pump2.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
@@ -502,7 +521,7 @@ public class DeviceInfoListener {
|
|
|
|
|
|
BusDeviceRunningEntity pump3 = new BusDeviceRunningEntity();
|
|
|
pump3.setDeviceId("456");
|
|
|
- pump3.setClassification("3");
|
|
|
+ pump3.setClassification(String.valueOf(mark));
|
|
|
pump3.setType(DeviceEnum.continuous);
|
|
|
pump3.setPatientCode("456");
|
|
|
pump3.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|