| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- 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.PatientCacheInfo;
- import com.coffee.bus.service.dto.UndoDeviceConfig;
- import com.coffee.bus.service.dto.DeviceShiftConfig;
- import com.coffee.bus.service.dto.ManualUndoConfig;
- import com.coffee.bus.entity.BusClinicEntity;
- 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 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.*;
- import java.util.stream.Collectors;
- /**
- * @author lifang
- * @version 1.0.0
- * @ClassName LocalBusHospitalService.java
- * @Description TODO
- * @createTime 2022年03月19日 09:27:00
- */
- @Service
- public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMapper, BusDeviceRunningEntity,String> {
- @Autowired
- @Lazy
- private LocalBusInfusionHistoryService infusionHistoryService;
- @Autowired
- @Lazy
- private PatientRegistry patientRegistry;
- @Autowired
- @Lazy
- private LocalBusPatientService patientService;
- @Autowired
- @Lazy
- private LocalBusClinicService clinicService;
- @Autowired
- @Lazy
- private DeviceRegistry deviceRegistry;
- public LocalBusDeviceRunningService(LocalBusInfusionHistoryService infusionHistoryService, PatientRegistry patientRegistry,LocalBusPatientService patientService, LocalBusClinicService clinicService) {
- this.infusionHistoryService = infusionHistoryService;
- this.patientRegistry = patientRegistry;
- this.patientService=patientService;
- this.clinicService=clinicService;
- }
- @Override
- public void validateBeforeSave(BusDeviceRunningEntity entity) {
- }
- @Override
- public void validateBeforeUpdate(BusDeviceRunningEntity entity) {
- }
- @Override
- public void validateBeforeDelete(String id) {
- }
- /**
- * 批量撤泵
- * @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,boolean finishClinic) {
- List<String> deviceIds = manualUndoConfig.getDeviceIds();
- if(CollectionUtil.isNotEmpty(deviceIds)){
- /****************将撤泵记录存入到泵的使用历史记录中***************/
- List<BusDeviceRunningEntity> devices = this.list(new QueryWrapper<BusDeviceRunningEntity>().lambda().in(BusDeviceRunningEntity::getDeviceId,deviceIds));
- if(CollectionUtil.isEmpty(devices)){
- return;
- }
- // //主泵撤除且没有结束临床
- // if (devices.stream().anyMatch(BusDeviceRunningEntity::getMaster)&&!finishClinic) {
- // throw new CustomException("主泵不可撤除,请在【结束管理】处操作");
- // }
- //对所有运行中的泵进行撤泵操作
- this.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda().in(BusDeviceRunningEntity::getDeviceId,deviceIds).set(BusDeviceRunningEntity::getIsUndo,true));
- //无泵监护,不需要监护输注数据
- if(Boolean.TRUE.equals(manualUndoConfig.getMonitorType())){
- //输注结束,更新撤泵信息
- Set<String> infusionIds = devices.stream().map(BusDeviceRunningEntity::getInfusionId).collect(Collectors.toSet());
- UndoDeviceConfig undo = manualUndoConfig.getUndo();
- infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
- .in(BusInfusionHistoryEntity::getId,infusionIds)
- .set(BusInfusionHistoryEntity::getIsUndo,true)
- .set(BusInfusionHistoryEntity::getUndoBy,undo.getUndoBy())
- .set(BusInfusionHistoryEntity::getUndoTime,undo.getUndoTime())
- .set(BusInfusionHistoryEntity::getDestroyer,undo.getDestroyer())
- .set(BusInfusionHistoryEntity::getWitnesses,undo.getWitnesses()));
- //将缓存设置为已撤泵状态
- deviceIds.stream().map(deviceRegistry::getOperator)
- .forEach(operator->operator.setUndo(true));
- }
- }
- //结束临床
- if(finishClinic){
- clinicService.finish(Collections.singletonList(manualUndoConfig.getPatientCode()),manualUndoConfig.getTenantId());
- }
- }
- @Transactional(rollbackFor = Exception.class)
- public void updateClinicInfo(List<String> deviceIds, BusClinicEntity clinic) {
- this.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda()
- .in(BusDeviceRunningEntity::getDeviceId,deviceIds)
- .set(BusDeviceRunningEntity::getClinicId,clinic.getId())
- .set(BusDeviceRunningEntity::getPatientName,clinic.getPatientName())
- .set(BusDeviceRunningEntity::getWard,clinic.getWard())
- .set(BusDeviceRunningEntity::getPatientSex,clinic.getPatientGender())
- .set(BusDeviceRunningEntity::getBedNo,clinic.getBedNo()));
- }
- /**
- * 切换主泵
- * @param shiftConfig 切换配置
- */
- @Transactional(rollbackFor = Exception.class)
- public void shift(DeviceShiftConfig shiftConfig) {
- 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;
- }
- //切换副泵
- 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());
- }
- }
|