|
|
@@ -1,26 +1,21 @@
|
|
|
package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.crypto.SignUtil;
|
|
|
-import cn.hutool.crypto.asymmetric.Sign;
|
|
|
-import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.coffee.bus.entity.*;
|
|
|
+import com.coffee.bus.enums.DeviceStatusEnum;
|
|
|
import com.coffee.bus.enums.PatientAlarmEnum;
|
|
|
import com.coffee.bus.hospital.HospitalManagerRegister;
|
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
|
|
|
-import com.coffee.bus.registry.device.bean.DeviceCacheInfo;
|
|
|
import com.coffee.bus.registry.device.DeviceOperator;
|
|
|
import com.coffee.bus.registry.patient.PatientOperator;
|
|
|
import com.coffee.bus.registry.patient.PatientRegistry;
|
|
|
-import com.coffee.bus.registry.patient.bean.PatientCacheInfo;
|
|
|
import com.coffee.bus.service.*;
|
|
|
import com.coffee.bus.utils.WsPublishUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -28,9 +23,10 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.tio.utils.crypto.Md5;
|
|
|
+
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
/**
|
|
|
@@ -45,8 +41,6 @@ import java.util.function.Supplier;
|
|
|
@AllArgsConstructor
|
|
|
public class DeviceInfoListener {
|
|
|
|
|
|
- private final LocalBusDeviceRunningService deviceRunningService;
|
|
|
-
|
|
|
private final DeviceRegistry deviceRegistry;
|
|
|
|
|
|
private final LocalBusDeviceAlarmService alarmService;
|
|
|
@@ -57,8 +51,6 @@ public class DeviceInfoListener {
|
|
|
|
|
|
private final LocalBusInfusionModifyService infusionModifyService;
|
|
|
|
|
|
- public static final Sign sign = SignUtil.sign(SignAlgorithm.MD5withRSA);
|
|
|
-
|
|
|
private final LocalBusDeviceHistoryService historyService;
|
|
|
|
|
|
private final LocalBusPatientService patientService;
|
|
|
@@ -82,58 +74,38 @@ public class DeviceInfoListener {
|
|
|
@EventListener
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
|
- //保证统一设备数据顺序处理,若数据发送过快,为防止冲突,请在此加锁处理 todo
|
|
|
+ //保证统一设备数据顺序处理,若数据发送过快,为防止冲突,请在此加锁处理
|
|
|
synchronized (infoEvent.getDeviceId()){
|
|
|
log.info("接收到设备消息:{}",JSONUtil.toJsonStr(infoEvent.getContent()));
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
- /****************处理泵数据 todo 后续交由上游处理****************/
|
|
|
BusDeviceRunningEntity device = infoEvent.getContent();
|
|
|
-// device=device.startUpHandle();
|
|
|
- device.setMonitorType(true);
|
|
|
-
|
|
|
- //1、判断该设备是否已和医院绑定并开启使用
|
|
|
- String deviceId = device.getDeviceId();
|
|
|
- device.setUploadTime(device.getUploadTime()==null?new Date():device.getUploadTime());
|
|
|
- DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getOperator(deviceId);
|
|
|
- device.setMaster(deviceOperator.getMaster());
|
|
|
- device.setIsUndo(deviceOperator.getUndo());
|
|
|
- device.setTenantId(deviceOperator.getTenantId());
|
|
|
-
|
|
|
- //数据准确性判断
|
|
|
String classification = device.getClassification();
|
|
|
- //默认为主泵,后续判断若不满足主泵条件,则替换为副泵
|
|
|
- if(classification==null){
|
|
|
+ if(StrUtil.isBlank(classification)){
|
|
|
log.error("设备号:[{}]分包标识号为空,无法更新开始时间");
|
|
|
throw new RuntimeException("设备数据中分包标识不能为空");
|
|
|
}
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ //对设备数据的一些参数进行初始化设置
|
|
|
+ init(device);
|
|
|
|
|
|
- log.info("接收到设备数据:[{}]", JSONUtil.toJsonStr(infoEvent.getContent()));
|
|
|
+ String deviceId = device.getDeviceId();
|
|
|
+ DeviceOperator deviceOperator = deviceRegistry.getOperator(deviceId);
|
|
|
//缓存操作
|
|
|
List<Supplier<?>> cacheOperation=new ArrayList<>();
|
|
|
- //处理设备运行数据, 判断是否为注册后第一次开机,判断是否为新的输注信息
|
|
|
- boolean first = handleRunningInfo(device, deviceOperator,cacheOperation);
|
|
|
-
|
|
|
//处理输注参数
|
|
|
- handleInfusion(device, deviceOperator, cacheOperation);
|
|
|
+ BusInfusionHistoryEntity infusionHistory = handleInfusionHistory(device, deviceOperator, cacheOperation);
|
|
|
+ //处理输注修改参数
|
|
|
+ handleInfusionModify(device,deviceOperator,cacheOperation);
|
|
|
//处理历史运行数据
|
|
|
BusDeviceHistoryEntity history=handleRunningHistory(device);
|
|
|
//处理报警、提醒信息
|
|
|
handleAlarmOrWarn(history,deviceOperator,cacheOperation);
|
|
|
//医院相关配置处理
|
|
|
handleHospitalConfig(device,cacheOperation);
|
|
|
- if(first){
|
|
|
- deviceService.update(new UpdateWrapper<BusDeviceEntity>().lambda().eq(BusDeviceEntity::getDeviceId,deviceId).set(BusDeviceEntity::getType,device.getType()));
|
|
|
- //首次上传数据,开启病号监控时长
|
|
|
- clinicService.update(new UpdateWrapper<BusClinicEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(BusClinicEntity::getId,device.getClinicId())
|
|
|
- .set(BusClinicEntity::getWard,device.getWard())
|
|
|
- .set(BusClinicEntity::getBedNo,device.getBedNo())
|
|
|
- .set(BusClinicEntity::getMonitorStartTime,device.getStartTime())
|
|
|
- );
|
|
|
- deviceRunningService.save(device);
|
|
|
+
|
|
|
+ if(device.isNewInfusion()){
|
|
|
+ infusionHistoryService.save(infusionHistory);
|
|
|
}else {
|
|
|
- deviceRunningService.updateById(device);
|
|
|
+ infusionHistoryService.updateById(infusionHistory);
|
|
|
}
|
|
|
|
|
|
cacheOperation.add(()->{
|
|
|
@@ -141,6 +113,13 @@ public class DeviceInfoListener {
|
|
|
wsPublishUtils.publishPatientMonitor(device.getPatientCode(),device.getTenantId());
|
|
|
wsPublishUtils.publishMonitorStateCount(device.getTenantId());
|
|
|
}
|
|
|
+ if (Boolean.TRUE.equals(device.isInfusionModify())) {
|
|
|
+ wsPublishUtils.publishDeviceNone(device.getTenantId());
|
|
|
+ wsPublishUtils.publishDeviceRepeat(device.getTenantId());
|
|
|
+ }
|
|
|
+ if (Boolean.TRUE.equals(device.isResetClinic())) {
|
|
|
+ wsPublishUtils.publishMonitorTotalCount(device.getTenantId());
|
|
|
+ }
|
|
|
return null;
|
|
|
});
|
|
|
|
|
|
@@ -150,56 +129,19 @@ public class DeviceInfoListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void init(BusDeviceRunningEntity device) {
|
|
|
+ String deviceId = device.getDeviceId();
|
|
|
|
|
|
- /**
|
|
|
- * 设备运行数据处理,返回是否为第一次接受数据消息
|
|
|
- * @param device 接收到的设备信息
|
|
|
- * @param deviceOperator 设备缓存信息操作符
|
|
|
- * @return 是否为第一次接收数据消息
|
|
|
- */
|
|
|
- private boolean handleRunningInfo( BusDeviceRunningEntity device,DeviceOperator<DeviceCacheInfo> deviceOperator,List<Supplier<?>> suppliers){
|
|
|
- //判断此条数据的分包标识是否发生了改变
|
|
|
- String originClassify = deviceOperator.getClassification();
|
|
|
- String classification = device.getClassification();
|
|
|
- String usingId = deviceOperator.getUsingId();
|
|
|
- if(!classification.equals(originClassify)){
|
|
|
- device.setNewInfusion(true);
|
|
|
- //启动新的输注,则撤泵标识取消
|
|
|
- device.setIsUndo(false);
|
|
|
- //分包标识发生了改变,设备开机时间重新计算
|
|
|
- device.setStartTime(device.getUploadTime());
|
|
|
- }
|
|
|
- boolean first=false;
|
|
|
- if(StrUtil.isNullOrUndefined(usingId)){
|
|
|
- //设备首次运行,记录开机时间
|
|
|
- device.setId(String.valueOf(IdWorker.getId()));
|
|
|
- device.setStartTime(device.getUploadTime());
|
|
|
- first=true;
|
|
|
- }else {
|
|
|
- device.setId(usingId);
|
|
|
- if(!device.isNewInfusion()){
|
|
|
- device.setStartTime(deviceOperator.getStartTime());
|
|
|
- }
|
|
|
- }
|
|
|
- suppliers.add(()->{
|
|
|
- //更新设备缓存数据
|
|
|
- if(device.isNewInfusion()){
|
|
|
- deviceOperator.setUndo(false);
|
|
|
- }
|
|
|
- deviceOperator.setClassification(device.getClassification());
|
|
|
- deviceOperator.setTenantId(device.getTenantId());
|
|
|
- deviceOperator.setUsingId(device.getId());
|
|
|
- deviceOperator.setStatus(device.getRunState());
|
|
|
- deviceOperator.setStartTime(device.getStartTime());
|
|
|
- deviceOperator.setMaster(device.getMaster());
|
|
|
- deviceOperator.setPatientCode(device.getPatientCode());
|
|
|
- //新输注异步更新
|
|
|
- hospitalManagerRegister.get(device.getTenantId())
|
|
|
- .getScriptSession()
|
|
|
- .asyncGetPatientInfo(device.getPatientCode(),10, TimeUnit.SECONDS,false);
|
|
|
- return null;
|
|
|
- });
|
|
|
- return first;
|
|
|
+ DeviceOperator deviceOperator = deviceRegistry.getOperator(deviceId);
|
|
|
+ device.setMonitorType(true);
|
|
|
+ device.setUploadTime(device.getUploadTime()==null?new Date():device.getUploadTime());
|
|
|
+
|
|
|
+ device.setTenantId(deviceOperator.getTenantId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isNewInFusion(String deviceId, String classification){
|
|
|
+ return ObjectUtil.notEqual(classification,deviceRegistry.getOperator(deviceId).getClassification());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -207,147 +149,56 @@ public class DeviceInfoListener {
|
|
|
* @param device 接收到的设备数据
|
|
|
* @return 是否发生了换泵操作
|
|
|
*/
|
|
|
- private void handlePatient(BusDeviceRunningEntity device,List<Supplier<?>> suppliers){
|
|
|
+ private void handlePatient(BusDeviceRunningEntity device,boolean clinicFinished,List<Supplier<?>> suppliers){
|
|
|
+ device.setMaster(true);
|
|
|
String deviceId = device.getDeviceId();
|
|
|
- DeviceOperator<DeviceCacheInfo> currentDeviceOperator = deviceRegistry.getOperator(deviceId);
|
|
|
- PatientOperator<PatientCacheInfo> currentPatientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode());
|
|
|
- String bindDeviceId = currentPatientOperator.getBindDeviceId();
|
|
|
- //当前病号所绑定的泵发生了改变,对当前病号进行处理
|
|
|
- if(StrUtil.isNullOrUndefined(bindDeviceId)){
|
|
|
- //当前的病号之前为无泵状态,无泵 -》 有泵 做处理 修改缓存信息
|
|
|
- log.warn("病号:【{}】临床发生由无泵转为有泵",device.getPatientCode());
|
|
|
- patientService.update(new UpdateWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode,device.getPatientCode())
|
|
|
- .eq(BusPatientEntity::getTenantId,device.getTenantId())
|
|
|
- .set(device.isNewInfusion(),BusPatientEntity::getInfusionId,device.getInfusionId())
|
|
|
- .set(BusPatientEntity::getAlarm, PatientAlarmEnum.NONE)
|
|
|
- );
|
|
|
- device.setMaster(true);
|
|
|
- suppliers.add(()->{
|
|
|
- wsPublishUtils.publishDeviceNone(device.getTenantId());
|
|
|
- return null;
|
|
|
- });
|
|
|
- }else if(ObjectUtil.notEqual(deviceId,bindDeviceId)){
|
|
|
- handleConflictCurrentPatient(device,suppliers);
|
|
|
- }else {
|
|
|
- //主泵未发生变化,只修改绑定的输注信息
|
|
|
+ PatientOperator currentPatientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode());
|
|
|
+ if(device.isInfusionModify()){
|
|
|
if(device.isNewInfusion()){
|
|
|
- patientService.update(new UpdateWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode,device.getPatientCode())
|
|
|
+ //只有在新开启输注时进行判断,1、判断当前输注的病号是否存在其他正在进行的输注 2、判断该设备上一次输注绑定的病号是否没有任何输注
|
|
|
+ long runningInfusionCount = infusionHistoryService.count(new QueryWrapper<BusInfusionHistoryEntity>().lambda()
|
|
|
+ .eq(BusInfusionHistoryEntity::getFinished, false)
|
|
|
+ .eq(BusInfusionHistoryEntity::getPatientCode, device.getPatientCode())
|
|
|
+ .eq(BusInfusionHistoryEntity::getTenantId, device.getTenantId()));
|
|
|
+ patientService.update(new UpdateWrapper<BusPatientEntity>()
|
|
|
+ .lambda()
|
|
|
+ .eq(BusPatientEntity::getCode,device.getPatientCode())
|
|
|
.eq(BusPatientEntity::getTenantId,device.getTenantId())
|
|
|
- .set(device.isNewInfusion(),BusPatientEntity::getInfusionId,device.getInfusionId()));
|
|
|
- }
|
|
|
- device.setMaster(true);
|
|
|
- }
|
|
|
- //更新泵所绑定当前病人缓存信息
|
|
|
- suppliers.add(()->{
|
|
|
- if(Boolean.TRUE.equals(device.getMaster())){
|
|
|
- currentDeviceOperator.setMaster(true);
|
|
|
- currentPatientOperator.setBindDeviceId(deviceId);
|
|
|
- }
|
|
|
- return null;
|
|
|
- });
|
|
|
- String originPatientCode=currentDeviceOperator.getPatientCode();
|
|
|
- //当前泵所绑定病号发生了改变,对之前所绑定病号进行处理
|
|
|
- if(!StrUtil.isNullOrUndefined(originPatientCode)&&!device.getPatientCode().equals(originPatientCode)){
|
|
|
- handleConflictOriginPatient(deviceId,device.getTenantId(),originPatientCode,suppliers);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 病患信息处理,当泵所绑定病号发生变化时,处理泵原来所绑定病号信息
|
|
|
- */
|
|
|
- private void handleConflictOriginPatient(String deviceId, String hospitalId, String patientCode, List<Supplier<?>> suppliers){
|
|
|
- PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(hospitalId, patientCode);
|
|
|
- //过滤掉已换绑的泵,获取剩余所绑定的泵数据
|
|
|
- List<BusDeviceRunningEntity> currentBindDevices = deviceRunningService.list(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getTenantId, hospitalId)
|
|
|
- .eq(BusDeviceRunningEntity::getTenantId, hospitalId)
|
|
|
- .ne(BusDeviceRunningEntity::getDeviceId, deviceId));
|
|
|
- if(CollectionUtil.isEmpty(currentBindDevices)){
|
|
|
- log.warn("病号:【{}】临床发生无泵报警",patientCode);
|
|
|
- patientService.update(new UpdateWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode,patientCode)
|
|
|
- .eq(BusPatientEntity::getTenantId,hospitalId)
|
|
|
- .set(BusPatientEntity::getAlarm, PatientAlarmEnum.DEVICE_NONE)
|
|
|
- );
|
|
|
- suppliers.add(()->{
|
|
|
- //发起无泵报警,处理原先泵的无泵信息
|
|
|
- patientOperator.setBindDeviceId(null);
|
|
|
- wsPublishUtils.publishDeviceNone(hospitalId);
|
|
|
- wsPublishUtils.publishPatientMonitor(patientCode,hospitalId);
|
|
|
- //发起无泵报警后,将该病人最后一条输注作为显示信息实时传输给前端
|
|
|
- return null;
|
|
|
- });
|
|
|
- }else {
|
|
|
- //将开始时间最大的泵设置为主泵
|
|
|
- Optional<BusDeviceRunningEntity> master = currentBindDevices.stream().max((o1,o2)->
|
|
|
- o1.getStartTime().equals(o2.getStartTime())?0:o1.getStartTime().before(o2.getStartTime()) ? -1 : 1
|
|
|
- );
|
|
|
- UpdateWrapper<BusPatientEntity> update = new UpdateWrapper<>();
|
|
|
- if(master.isPresent()){
|
|
|
- log.warn("病号:[{}],主泵变为[{}]",patientCode,master.get().getDeviceId());
|
|
|
- deviceRunningService
|
|
|
- .update(new UpdateWrapper<BusDeviceRunningEntity>().lambda()
|
|
|
- .eq(BusDeviceRunningEntity::getDeviceId,master.get().getDeviceId())
|
|
|
- .set(BusDeviceRunningEntity::getMaster,true));
|
|
|
- DeviceOperator<DeviceCacheInfo> operator = deviceRegistry.getOperator(master.get().getDeviceId());
|
|
|
- //更换输注信息
|
|
|
- update.lambda().eq(BusPatientEntity::getCode, patientCode)
|
|
|
- .eq(BusPatientEntity::getTenantId, hospitalId)
|
|
|
- .set(BusPatientEntity::getInfusionId, operator.getInfusionId());
|
|
|
+ .set(BusPatientEntity::getInfusionId,device.getInfusionId())
|
|
|
+ .set(runningInfusionCount>0,BusPatientEntity::getAlarm,PatientAlarmEnum.DEVICE_REPEAT)
|
|
|
+ .set(runningInfusionCount==0,BusPatientEntity::getAlarm,PatientAlarmEnum.NONE));
|
|
|
+ BusInfusionHistoryEntity lastInfusion = infusionHistoryService.lastInfusion(deviceId);
|
|
|
+ if(ObjectUtil.notEqual(device.getPatientCode(),lastInfusion.getPatientCode())&&!DeviceStatusEnum.Shutdown.equals(lastInfusion.getRunState())){
|
|
|
+ //处理非正常关机的输注信息,返回处理后的该病号绑定的正常输注信息
|
|
|
+ BusInfusionHistoryEntity normalInfusion = infusionHistoryService.handleAbnormalInfusion(lastInfusion);
|
|
|
+ if(normalInfusion!=null){
|
|
|
+ patientRegistry.getOperator(lastInfusion.getTenantId(), lastInfusion.getPatientCode()).setBindDeviceId(normalInfusion.getDeviceId());
|
|
|
+ suppliers.add(()->{
|
|
|
+ wsPublishUtils.publishPatientMonitor(lastInfusion.getPatientCode(),lastInfusion.getTenantId());
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(clinicFinished){
|
|
|
+ clinicService.resetClinic(device.getClinicId());
|
|
|
+ }
|
|
|
+ device.setMaster(true);
|
|
|
suppliers.add(()->{
|
|
|
- String newMasterId = master.get().getDeviceId();
|
|
|
- patientOperator.setBindDeviceId(newMasterId);
|
|
|
- //更换输注信息后,将最新的输注信息传输实时传输给前端
|
|
|
- wsPublishUtils.publishPatientMonitor(patientCode,hospitalId);
|
|
|
- wsPublishUtils.publishDeviceRepeat(hospitalId);
|
|
|
+ currentPatientOperator.setBindDeviceId(deviceId);
|
|
|
return null;
|
|
|
});
|
|
|
- if(CollectionUtil.size(currentBindDevices)==1){
|
|
|
- //泵重复—>正常
|
|
|
- update.lambda()
|
|
|
- .set(BusPatientEntity::getAlarm, null);
|
|
|
- }
|
|
|
- patientService.update(update);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发生冲突时,病患信息处理,当泵所绑定病号发生变化时,处理泵现在所绑定病号信息
|
|
|
- * @param device 设备运行数据
|
|
|
- */
|
|
|
- private void handleConflictCurrentPatient(BusDeviceRunningEntity device, List<Supplier<?>> suppliers){
|
|
|
- String deviceId = device.getDeviceId();
|
|
|
- PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode());
|
|
|
- String bindDeviceId = patientOperator.getBindDeviceId();
|
|
|
- if(ObjectUtil.notEqual(deviceId,bindDeviceId)){
|
|
|
- //泵号发生改变,获取病号绑定的泵信息,判断绑定的泵开始时间,将开始时间稍后的泵设置为主泵
|
|
|
- DeviceOperator<DeviceCacheInfo> patientCurrentBindDevice = deviceRegistry.getOperator(bindDeviceId);
|
|
|
- Date modifyTime = patientCurrentBindDevice.getModifyTime();
|
|
|
- if (modifyTime==null||modifyTime.before(device.getModifyTime())) {
|
|
|
- log.warn("病号:[{}],之前主泵为:[{}],现在主泵为:[{}]",device.getPatientCode(),bindDeviceId,deviceId);
|
|
|
- //设置当前上传信息的泵为主泵,将旧泵设置为副泵,并更新病人绑定泵的消息
|
|
|
+ }else if(!clinicFinished){
|
|
|
+ //临床未结束,切换当前输注信息为主输注
|
|
|
+ patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
|
|
|
+ .eq(BusPatientEntity::getCode,device.getPatientCode())
|
|
|
+ .eq(BusPatientEntity::getTenantId,device.getTenantId())
|
|
|
+ .set(BusPatientEntity::getInfusionId,device.getInfusionId()));
|
|
|
device.setMaster(true);
|
|
|
- deviceRunningService.update(new UpdateWrapper<BusDeviceRunningEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(BusDeviceRunningEntity::getPatientCode,device.getPatientCode())
|
|
|
- .eq(BusDeviceRunningEntity::getTenantId,device.getTenantId())
|
|
|
- .set(BusDeviceRunningEntity::getMaster,false));
|
|
|
- }else {
|
|
|
- device.setMaster(false);
|
|
|
+ suppliers.add(()->{
|
|
|
+ currentPatientOperator.setBindDeviceId(deviceId);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
}
|
|
|
- log.warn("病号:{}发生了泵重复",device.getPatientCode());
|
|
|
- patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
|
|
|
- .eq(BusPatientEntity::getCode,device.getPatientCode())
|
|
|
- .eq(BusPatientEntity::getTenantId,device.getTenantId())
|
|
|
- .set(Boolean.TRUE.equals(device.getMaster()),BusPatientEntity::getInfusionId,device.getInfusionId())
|
|
|
- .set(BusPatientEntity::getAlarm,PatientAlarmEnum.DEVICE_REPEAT));
|
|
|
- suppliers.add(()->{
|
|
|
- if(Boolean.TRUE.equals(device.getMaster())){
|
|
|
- patientCurrentBindDevice.setMaster(false);
|
|
|
- }
|
|
|
- wsPublishUtils.publishDeviceRepeat(device.getTenantId());
|
|
|
- return null;
|
|
|
- });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -357,76 +208,66 @@ public class DeviceInfoListener {
|
|
|
* @param deviceOperator 设备数据操作符
|
|
|
* @param cacheOperation 缓存操作
|
|
|
*/
|
|
|
- private BusInfusionHistoryEntity handleInfusionHistory(BusDeviceRunningEntity device, DeviceOperator<DeviceCacheInfo> deviceOperator, List<Supplier<?>> cacheOperation) {
|
|
|
+ private BusInfusionHistoryEntity handleInfusionHistory(BusDeviceRunningEntity device, DeviceOperator deviceOperator, List<Supplier<?>> cacheOperation) {
|
|
|
+ PatientOperator patientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode(),MapUtil.of("startTime", device.getStartTime()));
|
|
|
+ device.setClinicId(patientOperator.getClinicId());
|
|
|
+ device.setPatientId(patientOperator.getPatientId());
|
|
|
BusInfusionHistoryEntity infusionHistory = BusInfusionHistoryEntity.parseRunningInfo(device);
|
|
|
String originInfusionId = deviceOperator.getInfusionId();
|
|
|
- if (device.isNewInfusion()) {
|
|
|
- //检测数据库是否存在该输注信息
|
|
|
- infusionHistory.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ if(ObjectUtil.equal(device.getDeviceId(),patientOperator.getBindDeviceId())){
|
|
|
+ device.setMaster(true);
|
|
|
+ }
|
|
|
+ if (isNewInFusion(device.getDeviceId(),device.getClassification())) {
|
|
|
+ //结束其余输注信息
|
|
|
+ infusionHistory.setId(IdWorker.getIdStr());
|
|
|
+ infusionHistory.setFinished(false);
|
|
|
+ device.setNewInfusion(true);
|
|
|
infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
|
|
|
- .eq(BusInfusionHistoryEntity::getDeviceId,device.getDeviceId())
|
|
|
+ .eq(BusInfusionHistoryEntity::getPatientCode,device.getPatientCode())
|
|
|
+ .eq(BusInfusionHistoryEntity::getTenantId,device.getTenantId())
|
|
|
.eq(BusInfusionHistoryEntity::getFinished,false)
|
|
|
.set(BusInfusionHistoryEntity::getFinished,true));
|
|
|
- infusionHistoryService.save(infusionHistory);
|
|
|
}else {
|
|
|
infusionHistory.setId(originInfusionId);
|
|
|
- infusionHistoryService.updateById(infusionHistory);
|
|
|
}
|
|
|
device.setInfusionId(infusionHistory.getId());
|
|
|
cacheOperation.add(()->{
|
|
|
- deviceOperator.setInfusionId(device.getInfusionId());
|
|
|
+ if(device.isNewInfusion()){
|
|
|
+ deviceOperator.setInfusionId(device.getInfusionId());
|
|
|
+ deviceOperator.setClassification(device.getClassification());
|
|
|
+ }
|
|
|
return null;
|
|
|
});
|
|
|
return infusionHistory;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 处理输注信息
|
|
|
- * @param device 设备运行数据
|
|
|
- * @param deviceOperator 设备操作符
|
|
|
- * @param cacheOperation 缓存操作
|
|
|
+ * 描述: 处理输注参数
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/30 14:04
|
|
|
+ * @param device
|
|
|
+ * @param deviceOperator
|
|
|
+ * @param cacheOperation
|
|
|
*/
|
|
|
- private BusInfusionHistoryEntity handleInfusion(BusDeviceRunningEntity device, DeviceOperator<DeviceCacheInfo> deviceOperator, List<Supplier<?>> cacheOperation) {
|
|
|
- PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode(),MapUtil.of("startTime", device.getStartTime()));
|
|
|
- device.setClinicId(patientOperator.getClinicId());
|
|
|
-
|
|
|
- BusInfusionHistoryEntity infusionHistory = handleInfusionHistory(device, deviceOperator, cacheOperation);
|
|
|
+ private void handleInfusionModify(BusDeviceRunningEntity device, DeviceOperator deviceOperator, List<Supplier<?>> cacheOperation){
|
|
|
BusInfusionModifyEntity busInfusionModify = BusInfusionModifyEntity.parseRunningInfo(device);
|
|
|
- String signHex = busInfusionModify.signParam(sign);
|
|
|
+
|
|
|
+ String signHex = busInfusionModify.signParam();
|
|
|
String infusionParam = deviceOperator.getInfusionParam();
|
|
|
- //输注参数已发生变化
|
|
|
if(ObjectUtil.notEqual(signHex,infusionParam)){
|
|
|
- BusClinicEntity clinic = clinicService.getById(device.getClinicId());
|
|
|
+ device.setInfusionModify(true);
|
|
|
+ boolean clinicFinished = clinicService.isFinished(device.getClinicId());
|
|
|
infusionModifyService.save(busInfusionModify);
|
|
|
device.setInfusionModifyId(busInfusionModify.getId());
|
|
|
device.setModifyTime(busInfusionModify.getModifyTime());
|
|
|
- //参数发生变化后,进行判断
|
|
|
- if(clinic!=null&&Boolean.TRUE.equals(clinic.getFinished())&&device.isNewInfusion()){
|
|
|
- //若临床已结束,则只有新的输注能够进行泵冲突处理
|
|
|
- handlePatient(device,cacheOperation);
|
|
|
- clinicService
|
|
|
- .update(new UpdateWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getId,patientOperator.getClinicId())
|
|
|
- .set(BusClinicEntity::getFinished,false));
|
|
|
- cacheOperation.add(()->{
|
|
|
- //重启临床
|
|
|
- wsPublishUtils.publishMonitorTotalCount(device.getTenantId());
|
|
|
- return null;
|
|
|
- });
|
|
|
- } else if(clinic!=null&&!Boolean.TRUE.equals(clinic.getFinished())){
|
|
|
- handlePatient(device,cacheOperation);
|
|
|
- }
|
|
|
+ handlePatient(device,clinicFinished,cacheOperation);
|
|
|
cacheOperation.add(()->{
|
|
|
deviceOperator.setInfusionParam(signHex);
|
|
|
deviceOperator.setModifyTime(device.getUploadTime());
|
|
|
return null;
|
|
|
});
|
|
|
+ device.setIsUndo(false);
|
|
|
}else {
|
|
|
-// String bindDeviceId = patientOperator.getBindDeviceId();
|
|
|
-// if (device.getDeviceId().equals(bindDeviceId)) {
|
|
|
-// device.setMaster(true);
|
|
|
-// }else {
|
|
|
-// device.setMaster(false);
|
|
|
-// }
|
|
|
//填充当前参数修改记录id
|
|
|
BusInfusionModifyEntity modify =infusionModifyService.recentModify(device.getClinicId(),device.getTenantId());
|
|
|
if(modify==null){
|
|
|
@@ -435,7 +276,6 @@ public class DeviceInfoListener {
|
|
|
}
|
|
|
device.setInfusionModifyId(modify.getId());
|
|
|
}
|
|
|
- return infusionHistory;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -473,33 +313,33 @@ public class DeviceInfoListener {
|
|
|
//获取上一状态下的报警信息
|
|
|
String lastAlarmSign = deviceOperator.getAlarmOrWarn();
|
|
|
BusDeviceAlarmEntity alarm = BusDeviceAlarmEntity.parseHistory(history);
|
|
|
- String alarmSign = alarm.signParm(sign);
|
|
|
+ String alarmSign = alarm.signParm();
|
|
|
|
|
|
if(StrUtil.isBlank(lastAlarmSign)||!alarmSign.equals(lastAlarmSign)){
|
|
|
//报警及提示发生变化,判断具体变化是由报警引起还是由提示引起
|
|
|
- BusDeviceRunningEntity lastRunning = deviceRunningService.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId, history.getDeviceId()));
|
|
|
+ BusInfusionHistoryEntity lastInfusion = infusionHistoryService.lastInfusion(history.getDeviceId());
|
|
|
|
|
|
int change=5;
|
|
|
- if(ObjectUtil.isNotNull(lastRunning)){
|
|
|
+ if(ObjectUtil.isNotNull(lastInfusion)){
|
|
|
//防止重复插入
|
|
|
- if(ObjectUtil.equal(lastRunning.getAlarm(),history.getAlarm())){
|
|
|
+ if(ObjectUtil.equal(lastInfusion.getAlarm(),history.getAlarm())){
|
|
|
alarm.setAlarm(false);
|
|
|
alarm.setAlarmState(null);
|
|
|
--change;
|
|
|
}
|
|
|
- if (ObjectUtil.equal(lastRunning.getWarnAnalgesicPoor(), history.getWarnAnalgesicPoor())) {
|
|
|
+ if (ObjectUtil.equal(lastInfusion.getWarnAnalgesicPoor(), history.getWarnAnalgesicPoor())) {
|
|
|
alarm.setWarnAnalgesicPoor(false);
|
|
|
--change;
|
|
|
}
|
|
|
- if (ObjectUtil.equal(lastRunning.getWarnFlow(), history.getWarnFlow())) {
|
|
|
+ if (ObjectUtil.equal(lastInfusion.getWarnFlow(), history.getWarnFlow())) {
|
|
|
alarm.setWarnFlow(null);
|
|
|
--change;
|
|
|
}
|
|
|
- if (ObjectUtil.equal(lastRunning.getWarnLowBattery(), history.getWarnLowBattery())) {
|
|
|
+ if (ObjectUtil.equal(lastInfusion.getWarnLowBattery(), history.getWarnLowBattery())) {
|
|
|
alarm.setWarnLowBattery(false);
|
|
|
--change;
|
|
|
}
|
|
|
- if (ObjectUtil.equal(lastRunning.getWarnWillFinished(), history.getWarnWillFinished())) {
|
|
|
+ if (ObjectUtil.equal(lastInfusion.getWarnWillFinished(), history.getWarnWillFinished())) {
|
|
|
alarm.setWarnWillFinished(false);
|
|
|
--change;
|
|
|
}
|