Browse Source

update 删除重复报警和提醒

A17404李放 3 years ago
parent
commit
097f81c20b

+ 6 - 3
nb-system/src/main/java/com/nb/bus/controller/BusPatientController.java

@@ -5,6 +5,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.stp.StpLogic;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.text.CharSequenceUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -271,10 +272,12 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
         BusClinicEntity clinic =null;
         Boolean monitorType = vo.getMonitorType();
         if(Boolean.TRUE.equals(monitorType)){
-            String infusionId = vo.getInfusionId();
+            if (StrUtil.isEmpty(vo.getPatientId())) {
+                throw new CustomException("病号id不能为空");
+            }
+            String infusionId=vo.getInfusionId();
             if(CharSequenceUtil.isAllBlank(infusionId)){
-                String patientCode = vo.getPatientCode();
-                BusPatientEntity patient = patientService.findByFormatCode(patientCode);
+                BusPatientEntity patient = patientService.getById(vo.getPatientId());
                 if(patient==null){
                     throw new CustomException("该病号信息不存在,请刷新后重试");
                 }

+ 5 - 2
nb-system/src/main/java/com/nb/bus/controller/vo/MonitorDetailVo.java

@@ -22,10 +22,13 @@ public class MonitorDetailVo {
     @ApiModelProperty("临床id,若传入infusionId,即查该次此输注的数据;若不传入infusionId,即查询病人最新的输注数据")
     @NotNull(message = "临床id不能为空")
     private String clinicId;
-    @ApiModelProperty("病号")
-    @NotNull(message = "病号不能为空")
+
+    @ApiModelProperty("病号,无泵监控时使用")
     private String patientCode;
 
+    @ApiModelProperty("住院号所属id,输注监控时使用")
+    private String patientId;
+
     @ApiModelProperty("输注id,当输注id存在时,以输注id为主,在输注历史查询时使用")
     private String infusionId;
 }

+ 19 - 1
nb-system/src/main/java/com/nb/bus/entity/BusDeviceAlarmEntity.java

@@ -18,6 +18,7 @@ import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import org.tio.utils.crypto.Md5;
 
+import javax.validation.constraints.NotNull;
 import java.util.Date;
 
 /**
@@ -35,6 +36,7 @@ import java.util.Date;
 public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
 
     @ApiModelProperty(value = "设备唯一编码",accessMode = ApiModelProperty.AccessMode.READ_ONLY)
+    @NotNull(message = "设备唯一标识不能为空")
     private String deviceId;
 
     @ApiModelProperty(value = "报警时间")
@@ -145,7 +147,23 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
         if (Boolean.TRUE.equals(history.getWarnWillFinished())) {
             return true;
         }
-        return history.getWarnFlow()!=null;
+        return history.getWarnFlow()!=null&&history.getWarnFlow()!=FlowStatusEnum.None;
+    }
+
+    public boolean alarmOrWarn(){
+        if (this.getAlarm() != null && !DeviceAlarmEnum.None.equals(this.getAlarm())) {
+            return true;
+        }
+        if (Boolean.TRUE.equals(this.getWarnAnalgesicPoor())) {
+            return true;
+        }
+        if (Boolean.TRUE.equals(this.getWarnLowBattery())) {
+            return true;
+        }
+        if (Boolean.TRUE.equals(this.getWarnWillFinished())) {
+            return true;
+        }
+        return this.getWarnFlow()!=null&&this.getWarnFlow()!=FlowStatusEnum.None;
     }
 
 

+ 0 - 2
nb-system/src/main/java/com/nb/bus/hospital/config/handler/AnalPoorDisappearHandler.java

@@ -7,7 +7,6 @@ import com.nb.bus.hospital.config.HospitalFunctionAnalConfigHandler;
 import com.nb.bus.registry.device.DeviceRegistry;
 import com.nb.bus.service.LocalBusInfusionHistoryService;
 import com.nb.bus.utils.WsPublishUtils;
-import com.nb.common.cache.value.Value;
 import com.nb.common.delay_queue.handler.DelayMessageHandler;
 import com.nb.common.delay_queue.message.DelayMessage;
 import lombok.AllArgsConstructor;
@@ -63,7 +62,6 @@ public class AnalPoorDisappearHandler implements DelayMessageHandler {
                     .eq(BusInfusionHistoryEntity::getFlowRestricted,false)
                     .eq(BusInfusionHistoryEntity::getAnalPoorMsgId,source.getIotMsgId())
                     .set(BusInfusionHistoryEntity::getWarnAnalgesicPoor,false));
-            deviceRegistry.getOperator(deviceId).setAlarmOrWarn(null);
             //发布推送
             wsPublishUtils.publishPatientMonitor(infusionHistory.getPatientId(),infusionHistory.getTenantId());
         }

+ 0 - 23
nb-system/src/main/java/com/nb/bus/registry/device/ClusterDeviceOperator.java

@@ -164,29 +164,6 @@ public class ClusterDeviceOperator implements DeviceOperator {
         return value.asString();
     }
 
-    @Override
-    public void setAlarmOrWarn(String alarm) {
-        put(DeviceKeyConstant.ALARM,wrapperValue(alarm) );
-    }
-
-    @Override
-    public String getAlarmOrWarn() {
-        Value value = getValue(DeviceKeyConstant.ALARM);
-        if(value==null){
-            BusInfusionHistoryEntity lastInfusion = getLastInfusion();
-            if(lastInfusion==null){
-                value=Value.simple(null);
-                setAlarmOrWarn(null);
-            }else {
-                String signParm = BusDeviceAlarmEntity.parseRunning(lastInfusion).signParm();
-                value=Value.simple(signParm);
-                setAlarmOrWarn(signParm);
-            }
-
-        }
-        return value.asString();
-    }
-
     @Override
     public void setInfusionId(String infusionId) {
         put(DeviceKeyConstant.INFUSION_ID,wrapperValue(infusionId) );

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

@@ -112,17 +112,6 @@ public interface DeviceOperator extends Operator {
      */
     String getInfusionId();
 
-    /**
-     * 设置当前设备报警(提醒)信息
-     * @param alarm
-     */
-    void setAlarmOrWarn(String alarm);
-
-    /**
-     * 获取当前设备报警(提醒)信息
-     * @return
-     */
-    String getAlarmOrWarn();
 
     /**
      * 设置当前设备输注参数

+ 53 - 7
nb-system/src/main/java/com/nb/bus/service/LocalBusDeviceAlarmService.java

@@ -6,13 +6,16 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.nb.bus.entity.BusDeviceAlarmEntity;
 import com.nb.bus.entity.BusHospitalEntity;
+import com.nb.bus.entity.BusInfusionHistoryEntity;
 import com.nb.bus.enums.DeviceAlarmEnum;
+import com.nb.bus.enums.FlowStatusEnum;
 import com.nb.bus.mapper.BusDeviceAlarmMapper;
-import com.nb.bus.mapper.BusHospitalMapper;
 import com.nb.bus.service.dto.*;
 import com.nb.common.crud.BaseService;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -29,18 +32,61 @@ import java.util.Map;
  * @createTime 2022年03月19日 09:27:00
  */
 @Service
+@Slf4j
 @AllArgsConstructor
 public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper, BusDeviceAlarmEntity,String> {
+
     @Autowired
-    private BusDeviceAlarmMapper busDeviceAlarmMapper;
+    @Lazy
+    private LocalBusHospitalService hospitalService;
+
     @Autowired
-    private BusHospitalMapper hospitalMapper;
+    @Lazy
+    private LocalBusInfusionHistoryService infusionHistoryService;
 
     @Override
     public void validateBeforeSave(BusDeviceAlarmEntity entity) {
 
     }
 
+    @Override
+    public boolean save(BusDeviceAlarmEntity entity) {
+        BusInfusionHistoryEntity infusionHistoryEntity = infusionHistoryService.getById(entity.getInfusionId());
+        if(entity.getDeviceType()==null){
+            entity.setDeviceType(infusionHistoryEntity.getType());
+        }
+        if(entity.getAlarmState()==null){
+            entity.setAlarmState(DeviceAlarmEnum.None);
+        }
+        if(entity.getWarnAnalgesicPoor()==null){
+            entity.setWarnAnalgesicPoor(false);
+        }
+        if(entity.getWarnFlow()==null){
+            entity.setWarnFlow(FlowStatusEnum.None);
+        }
+        if(entity.getWarnWillFinished()==null){
+            entity.setWarnWillFinished(false);
+        }
+        if(entity.getWarnLowBattery()==null){
+            entity.setWarnLowBattery(false);
+        }
+        if(entity.getWarnAnalgesicPoor()==null){
+            entity.setWarnAnalgesicPoor(false);
+        }
+       if(!entity.alarmOrWarn()){
+           //无警报信息,存储失败
+           return false;
+       }
+
+        BusDeviceAlarmEntity existAlarm = BusDeviceAlarmEntity.parseRunning(infusionHistoryEntity);
+        if (entity.signParm().equalsIgnoreCase(existAlarm.signParm())) {
+            return false;
+        }
+        //再判断是否报警或提示是否发生重复
+        //满足以上条件进行保存
+        return super.save(entity);
+    }
+
     @Override
     public void validateBeforeUpdate(BusDeviceAlarmEntity entity) {
 
@@ -86,12 +132,12 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
         if(query.getTenantId()!=null){
             busHospitalEntityQueryWrapper.getEntity().setId(query.getTenantId());
         }
-        List<BusHospitalEntity> hospitalEntities = hospitalMapper.selectList(busHospitalEntityQueryWrapper);
+        List<BusHospitalEntity> hospitalEntities = hospitalService.getBaseMapper().selectList(busHospitalEntityQueryWrapper);
 
         List<DeviceUse> deviceUseList = new ArrayList<>();
 
         // 获取 报警所有信息数量
-        List<DeviceAlarmCountResult> alarmResults = busDeviceAlarmMapper.selectAlarmCount(query);
+        List<DeviceAlarmCountResult> alarmResults = this.baseMapper.selectAlarmCount(query);
 
         //处理报警信息
         Map<String,Map<String,String>> alarmMap= new HashMap<>();
@@ -113,7 +159,7 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
 
 
         // 获取告警信息
-        List<DeviceWarnCountResult> warnResults = busDeviceAlarmMapper.selectWarnCount(query);
+        List<DeviceWarnCountResult> warnResults = this.baseMapper.selectWarnCount(query);
         //处理告警信息
         for (DeviceWarnCountResult deviceWarnCountResult : warnResults
         ) {
@@ -166,7 +212,7 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
     @Transactional(rollbackFor = Exception.class)
     public List<DeviceCountResult> selectUseDetail(BusDeviceAlarmEntity query){
 
-        return busDeviceAlarmMapper.selectDeviceCount(query);
+        return this.baseMapper.selectDeviceCount(query);
 
     }
 

+ 2 - 0
nb-system/src/main/java/com/nb/bus/stats/entity/AlarmTotalPieResult.java

@@ -135,6 +135,8 @@ public class AlarmTotalPieResult extends HashMap<String,PieContent> {
         getMachine();
         getOutOfControl();
         getLowBattery();
+        getBubble();
+        getInfusionMax();
     }
 
     public void handle(CombineAlarmResult alarmResult) {

+ 3 - 49
nb-system/src/main/java/com/nb/bus/websocket/listener/DeviceInfoListener.java

@@ -127,7 +127,7 @@ public class DeviceInfoListener {
                 log.debug("消息【{}】,设备号【{}】处理历史运行数据成功,处理后结果为【{}】",device.getMsgId(),device.getDeviceId(),JSONUtil.toJsonStr(device));
             }
             //处理报警、提醒信息
-            handleAlarmOrWarn(history,deviceOperator,cacheOperation);
+            handleAlarmOrWarn(history);
             if(log.isDebugEnabled()){
                 log.debug("消息【{}】,设备号【{}】处理报警、提醒信息成功,处理后结果为【{}】",device.getMsgId(),device.getDeviceId(),JSONUtil.toJsonStr(device));
             }
@@ -516,57 +516,11 @@ public class DeviceInfoListener {
     /**
      * 判断是否为报警信息并处理
      * @param history 设备当前数据的历史数据
-     * @param deviceOperator 设备操作符
      */
-    private void handleAlarmOrWarn(BusDeviceHistoryEntity history, DeviceOperator deviceOperator, List<Supplier<?>> cacheOperation){
+    private void handleAlarmOrWarn(BusDeviceHistoryEntity history){
         if (BusDeviceAlarmEntity.alarmOrWarn(history)) {
-            //获取上一状态下的报警信息
-            String lastAlarmSign = deviceOperator.getAlarmOrWarn();
             BusDeviceAlarmEntity alarm = BusDeviceAlarmEntity.parseHistory(history);
-            String alarmSign = alarm.signParm();
-
-            if(StrUtil.isBlank(lastAlarmSign)||!alarmSign.equals(lastAlarmSign)){
-                //报警及提示发生变化,判断具体变化是由报警引起还是由提示引起
-                BusInfusionHistoryEntity lastInfusion = infusionHistoryService.lastInfusion(history.getDeviceId());
-
-                int change=5;
-                if(ObjectUtil.isNotNull(lastInfusion)){
-                    //防止重复插入
-                    if(ObjectUtil.equal(lastInfusion.getAlarm(),history.getAlarm())){
-                        alarm.setAlarm(false);
-                        alarm.setAlarmState(null);
-                        --change;
-                    }
-                    if (ObjectUtil.equal(lastInfusion.getWarnAnalgesicPoor(), history.getWarnAnalgesicPoor())) {
-                        alarm.setWarnAnalgesicPoor(false);
-                        --change;
-                    }
-                    if (ObjectUtil.equal(lastInfusion.getWarnFlow(), history.getWarnFlow())) {
-                        alarm.setWarnFlow(null);
-                        --change;
-                    }
-                    if (ObjectUtil.equal(lastInfusion.getWarnLowBattery(), history.getWarnLowBattery())) {
-                        alarm.setWarnLowBattery(false);
-                        --change;
-                    }
-                    if (ObjectUtil.equal(lastInfusion.getWarnWillFinished(), history.getWarnWillFinished())) {
-                        alarm.setWarnWillFinished(false);
-                        --change;
-                    }
-                }
-                if(change!=0){
-                    alarmService.save(alarm);
-                    cacheOperation.add(()->{
-                        deviceOperator.setAlarmOrWarn(alarmSign);
-                        return null;
-                    });
-                }
-            }
-        }else {
-            cacheOperation.add(()->{
-                deviceOperator.setAlarmOrWarn(null);
-                return null;
-            });
+            alarmService.save(alarm);
         }
     }
 }