|
|
@@ -0,0 +1,220 @@
|
|
|
+package com.coffee.bus.hospital.config;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.coffee.bus.enums.ConfigEnum;
|
|
|
+import com.coffee.bus.hospital.config.bean.FunctionExtraConfig;
|
|
|
+import com.coffee.bus.entity.BusDeviceRunningEntity;
|
|
|
+import com.coffee.bus.entity.BusInfusionHistoryEntity;
|
|
|
+import com.coffee.bus.enums.DeviceStatusEnum;
|
|
|
+import com.coffee.bus.enums.DeviceTypeEnum;
|
|
|
+import com.coffee.bus.hospital.enums.ConfigHandlerEnums;
|
|
|
+import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
+import com.coffee.bus.registry.patient.PatientRegistry;
|
|
|
+import com.coffee.bus.service.LocalBusDeviceRunningService;
|
|
|
+import com.coffee.bus.service.LocalBusInfusionHistoryService;
|
|
|
+import com.coffee.bus.utils.WsPublishUtils;
|
|
|
+import com.coffee.common.cache.ConfigStorage;
|
|
|
+import com.coffee.common.util.RedissonUtil;
|
|
|
+import lombok.Builder;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.redisson.api.RDelayedQueue;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author lifang
|
|
|
+ * @version 1.0.0
|
|
|
+ * @ClassName HospitalFunctionLowInfusionConfigHandler.java
|
|
|
+ * @Description 低输注判断处理
|
|
|
+ * 不在服务区处理:当设备下线时,且最后一个包不为关机包,则开启延迟任务进行不在服务区处理判断
|
|
|
+ * 低输注处理:当设备持续发送输注下限时,开启低输注延迟任务,当输注>输注下限时,撤销所有延迟任务
|
|
|
+ * @createTime 2022年05月19日 15:13:00
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class HospitalFunctionExtraConfigHandler extends AbstractHospitalConfigHandler<FunctionExtraConfig, BusDeviceRunningEntity>{
|
|
|
+
|
|
|
+ private HospitalFinishMonitorConfigHandler monitorConfigHandler;
|
|
|
+ private HospitalAutoUndoConfigHandler autoUndoConfigHandler;
|
|
|
+ public HospitalFunctionExtraConfigHandler(ConfigStorage configStorage, String hospitalId, RedissonUtil redissonUtil, LocalBusDeviceRunningService deviceRunningService, LocalBusInfusionHistoryService infusionHistoryService, DeviceRegistry deviceRegistry, WsPublishUtils wsPublishUtils, PatientRegistry patientRegistry
|
|
|
+ , HospitalFinishMonitorConfigHandler monitorConfigHandler,HospitalAutoUndoConfigHandler autoUndoConfigHandler) {
|
|
|
+ super(configStorage, hospitalId, redissonUtil, deviceRunningService, infusionHistoryService, deviceRegistry, wsPublishUtils, patientRegistry);
|
|
|
+ this.monitorConfigHandler=monitorConfigHandler;
|
|
|
+ this.autoUndoConfigHandler=autoUndoConfigHandler;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ConfigHandlerEnums getId() {
|
|
|
+ return ConfigHandlerEnums.extra;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getDescription() {
|
|
|
+ return "医院其他配置处理,不在服务区设置、低输注设置";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handler(BusDeviceRunningEntity source) {
|
|
|
+ FunctionExtraConfig config = this.getConfig().as(FunctionExtraConfig.class);
|
|
|
+ if(config==null){
|
|
|
+ log.warn("id:{},配置名称:{},不存在",getId(),hospitalId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (config.getNoSignal()!=null&&config.getNoSignal()>0) {
|
|
|
+ judgeNoSignal(source,config.getNoSignal());
|
|
|
+ }
|
|
|
+ if (config.getLowInfusion()!=null&&config.getLowInfusion()>0) {
|
|
|
+ judgeLowInfusion(source,config.getLowInfusion());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述: 不在服务区处理
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/19 15:52
|
|
|
+ * @param source
|
|
|
+ * @param interval
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void judgeNoSignal(BusDeviceRunningEntity source,int interval){
|
|
|
+ RDelayedQueue delayedQueue = redissonUtil.getDelayedQueue(getId() +"-signal"+ "-" + source.getTenantId() + "-" + source.getDeviceId(), e -> {
|
|
|
+ if(e instanceof NoSignalEntity){
|
|
|
+ this.handleNoSignal((NoSignalEntity) e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //清空延迟队列消息
|
|
|
+ delayedQueue.clear();
|
|
|
+
|
|
|
+ NoSignalEntity noSignal = NoSignalEntity.builder()
|
|
|
+ .deviceId(source.getDeviceId())
|
|
|
+ .patientCode(source.getPatientCode())
|
|
|
+ .tenantId(source.getTenantId())
|
|
|
+ .timestamp(new Date())
|
|
|
+ .timeout(interval)
|
|
|
+ .unit(TimeUnit.MINUTES)
|
|
|
+ .build();
|
|
|
+ //将该次消息视为最后一次消息放入队列中
|
|
|
+ delayedQueue.offer(noSignal,noSignal.getTimeout(),noSignal.getUnit());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述: 不在服务区处理
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/19 16:02
|
|
|
+ * @param source
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void handleNoSignal(NoSignalEntity source){
|
|
|
+ String deviceId = source.getDeviceId();
|
|
|
+ String tenantId = source.getTenantId();
|
|
|
+ BusDeviceRunningEntity runningInfo = deviceRunningService.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId, deviceId).eq(BusDeviceRunningEntity::getTenantId, tenantId));
|
|
|
+ if (runningInfo == null) {
|
|
|
+ //泵已换绑医院,无需再处理
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ deviceRunningService.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getId, runningInfo.getId())
|
|
|
+ .set(BusDeviceRunningEntity::getRunState, DeviceStatusEnum.NoSignal));
|
|
|
+ infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getId, runningInfo.getInfusionId())
|
|
|
+ .set(BusInfusionHistoryEntity::getRunState, DeviceStatusEnum.NoSignal));
|
|
|
+ //报警/提醒缓存重置
|
|
|
+ deviceRegistry.getOperator(deviceId)
|
|
|
+ .setStatus(DeviceStatusEnum.NoSignal);
|
|
|
+ if (Boolean.TRUE.equals(runningInfo.getMaster())) {
|
|
|
+ //发布推送
|
|
|
+ wsPublishUtils.publishPatientMonitor(runningInfo.getPatientCode(), runningInfo.getTenantId());
|
|
|
+ }
|
|
|
+ //不在服务区
|
|
|
+ monitorConfigHandler.judgeNoSignal(deviceId,source.getPatientCode(),source.getTenantId());
|
|
|
+ autoUndoConfigHandler.judgeNoSignal(deviceId,source.getPatientCode(),source.getTenantId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述: 低输注判断
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/19 15:52
|
|
|
+ * @param source
|
|
|
+ * @param interval
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void judgeLowInfusion(BusDeviceRunningEntity source,int interval){
|
|
|
+ RDelayedQueue delayedQueue = redissonUtil.getDelayedQueue(getId() +"-lowFusion"+ "-" + source.getTenantId() + "-" + source.getDeviceId(), e -> {
|
|
|
+ if(e instanceof LowInfusionEntity){
|
|
|
+ handleLowInfusion((LowInfusionEntity)e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //仅智能泵存在
|
|
|
+ if(DeviceTypeEnum.intelligent.equals(source.getType())){
|
|
|
+ if (source.getFlowDownLimit()!=null&&source.getFlowDownLimit().compareTo(BigDecimal.valueOf(0.1))<1) {
|
|
|
+ //输注量超过阈值,进行低输注判定
|
|
|
+ LowInfusionEntity lowInfusionEntity = LowInfusionEntity.builder()
|
|
|
+ .deviceId(source.getDeviceId())
|
|
|
+ .timeout(interval)
|
|
|
+ .unit(TimeUnit.MINUTES)
|
|
|
+ .tenantId(source.getTenantId())
|
|
|
+ .timestamp(new Date())
|
|
|
+ .build();
|
|
|
+ delayedQueue.offer(lowInfusionEntity,lowInfusionEntity.getTimeout(),lowInfusionEntity.getUnit());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }else {
|
|
|
+ //输注量未超过阈值,取消低输注状态
|
|
|
+ source.setWarnLowBattery(false);
|
|
|
+ delayedQueue.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述: 低输注状态处理
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/19 16:08
|
|
|
+ * @param source
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void handleLowInfusion(LowInfusionEntity source) {
|
|
|
+ String deviceId = source.getDeviceId();
|
|
|
+ String tenantId = source.getTenantId();
|
|
|
+ BusDeviceRunningEntity runningInfo = deviceRunningService.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId, deviceId).eq(BusDeviceRunningEntity::getTenantId, tenantId));
|
|
|
+ if (runningInfo == null) {
|
|
|
+ //泵已换绑医院,无需再处理
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ deviceRunningService.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getId, runningInfo.getId())
|
|
|
+ .set(BusDeviceRunningEntity::getWarnLowBattery, true));
|
|
|
+ infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getId, runningInfo.getInfusionId())
|
|
|
+ .set(BusInfusionHistoryEntity::getWarnLowBattery, true));
|
|
|
+ //报警/提醒缓存重置
|
|
|
+ deviceRegistry.getOperator(deviceId).setAlarmOrWarn(null);
|
|
|
+ if (Boolean.TRUE.equals(runningInfo.getMaster())) {
|
|
|
+ //发布推送
|
|
|
+ wsPublishUtils.publishPatientMonitor(runningInfo.getPatientCode(), runningInfo.getTenantId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ @Builder
|
|
|
+ static class NoSignalEntity implements Serializable {
|
|
|
+ private String deviceId;
|
|
|
+ private String patientCode;
|
|
|
+ private Integer timeout;
|
|
|
+ private TimeUnit unit;
|
|
|
+ private String tenantId;
|
|
|
+ private Date timestamp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ @Builder
|
|
|
+ static class LowInfusionEntity implements Serializable {
|
|
|
+ private String deviceId;
|
|
|
+ private Integer timeout;
|
|
|
+ private TimeUnit unit;
|
|
|
+ private String tenantId;
|
|
|
+ private Date timestamp;
|
|
|
+ }
|
|
|
+}
|