|
|
@@ -1,11 +1,14 @@
|
|
|
package com.coffee.bus.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.coffee.bus.entity.BusPatientEntity;
|
|
|
+import com.coffee.bus.registry.device.DeviceOperator;
|
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
+import com.coffee.bus.registry.device.bean.DeviceCacheInfo;
|
|
|
import com.coffee.bus.registry.patient.PatientOperator;
|
|
|
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.dto.UndoDeviceConfig;
|
|
|
import com.coffee.bus.service.dto.DeviceShiftConfig;
|
|
|
@@ -15,15 +18,13 @@ import com.coffee.bus.entity.BusDeviceRunningEntity;
|
|
|
import com.coffee.bus.entity.BusInfusionHistoryEntity;
|
|
|
import com.coffee.bus.mapper.BusDeviceRunningMapper;
|
|
|
import com.coffee.common.crud.BaseService;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
+import com.coffee.common.exception.CustomException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -37,13 +38,17 @@ import java.util.stream.Collectors;
|
|
|
public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMapper, BusDeviceRunningEntity,String> {
|
|
|
private final LocalBusInfusionHistoryService infusionHistoryService;
|
|
|
private final PatientRegistry patientRegistry;
|
|
|
+ private final LocalBusPatientService patientService;
|
|
|
+ private final LocalBusClinicService clinicService;
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private DeviceRegistry deviceRegistry;
|
|
|
|
|
|
- public LocalBusDeviceRunningService(LocalBusInfusionHistoryService infusionHistoryService, PatientRegistry patientRegistry) {
|
|
|
+ public LocalBusDeviceRunningService(LocalBusInfusionHistoryService infusionHistoryService, PatientRegistry patientRegistry,LocalBusPatientService patientService, LocalBusClinicService clinicService) {
|
|
|
this.infusionHistoryService = infusionHistoryService;
|
|
|
this.patientRegistry = patientRegistry;
|
|
|
+ this.patientService=patientService;
|
|
|
+ this.clinicService=clinicService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -61,23 +66,43 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量撤泵
|
|
|
+ * @param undoConfigs 批量撤泵配置
|
|
|
+ * @param finishClinic 撤泵后是否结束相关临床
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void batchUndo(List<ManualUndoConfig> undoConfigs,boolean finishClinic){
|
|
|
+ undoConfigs.forEach(undoConfig -> this.undo(undoConfig,false));
|
|
|
+ //批量结束临床
|
|
|
+ if(finishClinic){
|
|
|
+ Map<String, List<ManualUndoConfig>> configsMap = undoConfigs.stream().collect(Collectors.groupingBy(ManualUndoConfig::getTenantId));
|
|
|
+ configsMap.forEach((k,v)-> {
|
|
|
+ clinicService.finish(v.stream().map(ManualUndoConfig::getPatientCode).collect(Collectors.toList()),v.get(0).getUndo().getUndoTime() ,k);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 结束病患监控操作
|
|
|
* @param manualUndoConfig
|
|
|
+ * @param finishClinic 撤泵后是否结束相关临床
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void undo(ManualUndoConfig manualUndoConfig) {
|
|
|
- List<String> ids = manualUndoConfig.getIds();
|
|
|
- if(CollectionUtil.isEmpty(ids)){
|
|
|
+ public void undo(ManualUndoConfig manualUndoConfig,boolean finishClinic) {
|
|
|
+ List<String> deviceIds = manualUndoConfig.getDeviceIds();
|
|
|
+ if(CollectionUtil.isEmpty(deviceIds)){
|
|
|
return;
|
|
|
}
|
|
|
/****************将撤泵记录存入到泵的使用历史记录中***************/
|
|
|
- List<BusDeviceRunningEntity> devices = this.listByIds(ids);
|
|
|
+ List<BusDeviceRunningEntity> devices = this.list(new QueryWrapper<BusDeviceRunningEntity>().lambda().in(BusDeviceRunningEntity::getDeviceId,deviceIds));
|
|
|
if(CollectionUtil.isEmpty(devices)){
|
|
|
return;
|
|
|
}
|
|
|
+ if (devices.stream().anyMatch(BusDeviceRunningEntity::getMaster)) {
|
|
|
+ throw new CustomException("主泵不可撤除,请在【结束管理】处操作");
|
|
|
+ }
|
|
|
//对所有运行中的泵进行撤泵操作
|
|
|
- this.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda().in(BusDeviceRunningEntity::getId,ids).set(BusDeviceRunningEntity::getIsUndo,true));
|
|
|
+ this.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda().in(BusDeviceRunningEntity::getDeviceId,deviceIds).set(BusDeviceRunningEntity::getIsUndo,true));
|
|
|
//无泵监护,不需要监护输注数据
|
|
|
if(!Boolean.TRUE.equals(manualUndoConfig.getMonitorType())){
|
|
|
//输注结束,更新撤泵信息
|
|
|
@@ -90,9 +115,13 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
|
|
|
.set(BusInfusionHistoryEntity::getDestroyer,undo.getDestroyer())
|
|
|
.set(BusInfusionHistoryEntity::getWitnesses,undo.getWitnesses()));
|
|
|
//将缓存设置为已撤泵状态
|
|
|
- ids.stream().map(deviceRegistry::getOperator)
|
|
|
+ deviceIds.stream().map(deviceRegistry::getOperator)
|
|
|
.forEach(operator->operator.setUndo(true));
|
|
|
}
|
|
|
+ //结束临床
|
|
|
+ if(finishClinic){
|
|
|
+ clinicService.finish(Collections.singletonList(manualUndoConfig.getPatientCode()),manualUndoConfig.getTenantId());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -113,14 +142,38 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void shift(DeviceShiftConfig shiftConfig) {
|
|
|
- PatientOperator<PatientCacheInfo> operator = patientRegistry.getOperator(shiftConfig.getTenantId(), shiftConfig.getPatientCode());
|
|
|
- List<String> replicaIds = shiftConfig.getReplicaIds();
|
|
|
- if(CollectionUtil.isNotEmpty(replicaIds)){
|
|
|
- ManualUndoConfig manualUndoConfig = ManualUndoConfig.of(replicaIds,true,shiftConfig.getUndo());
|
|
|
- //对副泵进行撤泵操作
|
|
|
- undo(manualUndoConfig);
|
|
|
+ PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(shiftConfig.getTenantId(), shiftConfig.getPatientCode());
|
|
|
+ String bindDeviceId = patientOperator.getBindDeviceId();
|
|
|
+ List<String> replicaDeviceIds = shiftConfig.getReplicaDeviceIds();
|
|
|
+ String masterDeviceId = shiftConfig.getMasterDeviceId();
|
|
|
+ if (masterDeviceId.equals(bindDeviceId)) {
|
|
|
+ //主泵未发生切换
|
|
|
+ return;
|
|
|
}
|
|
|
- operator.setBindDeviceId(shiftConfig.getMasterId());
|
|
|
- operator.setAllDevice(Arrays.asList(DeviceTimeSmallInfo.of(shiftConfig.getMasterId(),shiftConfig.getStartTime())));
|
|
|
+ //切换副泵
|
|
|
+ this.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda()
|
|
|
+ .in(BusDeviceRunningEntity::getDeviceId,replicaDeviceIds).set(BusDeviceRunningEntity::getMaster,false));
|
|
|
+ //切换主泵
|
|
|
+ this.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda()
|
|
|
+ .eq(BusDeviceRunningEntity::getDeviceId,masterDeviceId).set(BusDeviceRunningEntity::getMaster,true));
|
|
|
+
|
|
|
+ DeviceOperator<DeviceCacheInfo> masterOperator = deviceRegistry.getOperator(masterDeviceId);
|
|
|
+ String currentInfusionId = masterOperator.getInfusionId();
|
|
|
+
|
|
|
+ //病患绑定主泵信息
|
|
|
+ patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
|
|
|
+ .eq(BusPatientEntity::getCode,shiftConfig.getPatientCode())
|
|
|
+ .eq(BusPatientEntity::getTenantId,shiftConfig.getTenantId())
|
|
|
+ .set(BusPatientEntity::getInfusionId,currentInfusionId));
|
|
|
+
|
|
|
+ //刷新缓存信息
|
|
|
+ replicaDeviceIds.stream().map(deviceRegistry::getOperator).forEach(deviceOperator->{
|
|
|
+ deviceOperator.setMaster(false);
|
|
|
+ //切换后也标注为暂时撤泵,即后续该泵发来的数据不再做主副泵切换的判断
|
|
|
+ deviceOperator.setUndo(true);
|
|
|
+ });
|
|
|
+
|
|
|
+ masterOperator.setMaster(true);
|
|
|
+ patientOperator.setBindDeviceId(shiftConfig.getMasterDeviceId());
|
|
|
}
|
|
|
}
|