|
|
@@ -1,5 +1,6 @@
|
|
|
package com.coffee.bus.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -74,10 +75,6 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
@Lazy
|
|
|
private LocalBusPatientService patientService;
|
|
|
|
|
|
- @Autowired
|
|
|
- @Lazy
|
|
|
- private DeviceRegistry deviceRegistry;
|
|
|
-
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private LocalBusHospitalService hospitalService;
|
|
|
@@ -86,10 +83,10 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
|
|
|
@Override
|
|
|
public void validateBeforeSave(BusPatientEntity entity) {
|
|
|
- if(entity.getGender()==null){
|
|
|
+ if (entity.getGender() == null) {
|
|
|
entity.setGender(SexEnum.UNKNOW);
|
|
|
}
|
|
|
- if(entity.getAlarm()==null){
|
|
|
+ if (entity.getAlarm() == null) {
|
|
|
entity.setAlarm(PatientAlarmEnum.NONE);
|
|
|
}
|
|
|
}
|
|
|
@@ -108,60 +105,63 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
public void postSave(BusPatientEntity entity) {
|
|
|
super.postSave(entity);
|
|
|
//新增病人后推送主题,延迟推送,保证处理逻辑已全部完成
|
|
|
- executorService.schedule(()->{
|
|
|
- wsPublishUtils.publishPatientAdd(entity.getCode(),entity.getTenantId());
|
|
|
+ executorService.schedule(() -> {
|
|
|
wsPublishUtils.publishMonitorTotalCount(entity.getTenantId());
|
|
|
}
|
|
|
- ,2, TimeUnit.SECONDS);
|
|
|
+ , 2, TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取病人信息
|
|
|
+ *
|
|
|
* @param hospitalId 医院id
|
|
|
* @param patientCode 病号
|
|
|
- * @param sync 是否为同步操作
|
|
|
+ * @param sync 是否为同步操作
|
|
|
*/
|
|
|
- public DeferredResult<R<BusClinicEntity>> getPatientInfoFromHis(String hospitalId, String patientCode, long timeout,boolean sync){
|
|
|
+ public DeferredResult<R<BusClinicEntity>> getPatientInfoFromHis(String hospitalId, String patientCode, long timeout, boolean sync) {
|
|
|
BusHospitalEntity hospital = hospitalService.getById(hospitalId);
|
|
|
HospitalManager hospitalManager = hospitalManagerRegister.get(hospitalId);
|
|
|
HisScriptSession hisScriptSession = hospitalManager.getScriptSession();
|
|
|
HisStrategyEnum strategy = hospital.getStrategy();
|
|
|
- if(null==strategy||HisStrategyEnum.NONE.equals(strategy)){
|
|
|
+ if (null == strategy || HisStrategyEnum.NONE.equals(strategy)) {
|
|
|
throw new CustomException("医院未对接his,请到【信息维护】->【HIS对接】配置his策略");
|
|
|
}
|
|
|
- log.info("医院【{}】,开始拉取病号【{}】信息,拉取方式【{}】",hospitalId,patientCode,sync?"同步":"异步");
|
|
|
- return sync?hisScriptSession.syncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS):hisScriptSession.asyncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS,true);
|
|
|
+ log.info("医院【{}】,开始拉取病号【{}】信息,拉取方式【{}】", hospitalId, patientCode, sync ? "同步" : "异步");
|
|
|
+ return sync ? hisScriptSession.syncGetPatientInfo(patientCode, timeout, TimeUnit.SECONDS) : hisScriptSession.asyncGetPatientInfo(patientCode, timeout, TimeUnit.SECONDS, true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 描述: 对病人报警数量进行统计
|
|
|
- * @author lifang
|
|
|
- * @date 2022/5/20 16:42
|
|
|
+ *
|
|
|
* @param tenantId
|
|
|
* @param alarm
|
|
|
* @return long
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/20 16:42
|
|
|
*/
|
|
|
- public long patientAlarmCount(String tenantId,PatientAlarmEnum alarm){
|
|
|
- return this.baseMapper.selectAlarmCount(tenantId,alarm.getValue());
|
|
|
+ public long patientAlarmCount(String tenantId, PatientAlarmEnum alarm) {
|
|
|
+ return this.baseMapper.selectAlarmCount(tenantId, alarm.getValue());
|
|
|
}
|
|
|
|
|
|
- public long patientAlarmCount(PatientAlarmEnum alarm){
|
|
|
- return patientAlarmCount(null,alarm);
|
|
|
+ public long patientAlarmCount(PatientAlarmEnum alarm) {
|
|
|
+ return patientAlarmCount(null, alarm);
|
|
|
}
|
|
|
|
|
|
- public long monitorTotalCount(String tenantId){
|
|
|
- return this.baseMapper.monitorTotalCount(tenantId);
|
|
|
+ public long monitorTotalCount(String tenantId) {
|
|
|
+ PatientMonitorQuery patientMonitorQuery = new PatientMonitorQuery();
|
|
|
+ patientMonitorQuery.setTenantId(tenantId);
|
|
|
+ return CollUtil.size(this.baseMapper.selectMonitor(Page.of(0,500,false),patientMonitorQuery).getRecords());
|
|
|
+// return this.baseMapper.monitorTotalCount(tenantId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取给定医院下所有的挂载多个设备的病人信息
|
|
|
- *
|
|
|
*/
|
|
|
public List<PatientDeviceRepeatResult> repeatDevice() {
|
|
|
List<PatientDeviceRepeatDomain> patientDeviceRepeats = this.baseMapper.selectRepeatDevice();
|
|
|
Map<String, PatientDeviceRepeatResult> resultMap = new HashMap<>();
|
|
|
- patientDeviceRepeats.forEach(deviceRepeat->{
|
|
|
- PatientDeviceRepeatResult repeatResult = resultMap.computeIfAbsent(deviceRepeat.getCode()+deviceRepeat.getClinicId(),k->
|
|
|
+ patientDeviceRepeats.forEach(deviceRepeat -> {
|
|
|
+ PatientDeviceRepeatResult repeatResult = resultMap.computeIfAbsent(deviceRepeat.getCode() + deviceRepeat.getClinicId(), k ->
|
|
|
PatientDeviceRepeatResult.of(
|
|
|
deviceRepeat.getName(),
|
|
|
deviceRepeat.getGender(),
|
|
|
@@ -189,6 +189,7 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
|
|
|
/**
|
|
|
* 获取无设备绑定的临床手术信息
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
public List<PatientDeviceNoneResult> noneDevice() {
|
|
|
@@ -197,25 +198,27 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
|
|
|
public List<PatientMonitorResult> selectAll(PatientMonitorQuery query) {
|
|
|
Page<PatientMonitorResult> page = new Page<>(0, 500, false);
|
|
|
- IPage<PatientMonitorResult> result = this.baseMapper.selectMonitor(page,query);
|
|
|
- if(CollectionUtil.isNotEmpty(result.getRecords())){
|
|
|
+ IPage<PatientMonitorResult> result = this.baseMapper.selectMonitor(page, query);
|
|
|
+ if (CollectionUtil.isNotEmpty(result.getRecords())) {
|
|
|
result.getRecords().forEach(PatientMonitorResult::handleWarn);
|
|
|
}
|
|
|
return result.getRecords();
|
|
|
}
|
|
|
|
|
|
- /**t
|
|
|
+ /**
|
|
|
+ * t
|
|
|
* 根据医院和住院号获取一个患者
|
|
|
+ *
|
|
|
* @param tenantId
|
|
|
* @param patientCode
|
|
|
* @return
|
|
|
*/
|
|
|
public BusPatientEntity getOneByHospitalAndPatientCode(String tenantId, String patientCode) {
|
|
|
BusPatientEntity patient = this.getOne(new QueryWrapper<BusPatientEntity>().lambda()
|
|
|
- .eq(BusPatientEntity::getTenantId,tenantId)
|
|
|
- .eq(BusPatientEntity::getCode,patientCode));
|
|
|
+ .eq(BusPatientEntity::getTenantId, tenantId)
|
|
|
+ .eq(BusPatientEntity::getCode, patientCode));
|
|
|
// 如果患者不存在则新增一个患者
|
|
|
- if (Objects.isNull(patient)){
|
|
|
+ if (Objects.isNull(patient)) {
|
|
|
patient = new BusPatientEntity();
|
|
|
patient.setTenantId(tenantId);
|
|
|
patient.setCode(patientCode);
|
|
|
@@ -225,18 +228,18 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* 病人手动更新当前监控的临床信息
|
|
|
+ *
|
|
|
* @param clinic
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void manualEdit(BusClinicEntity clinic) {
|
|
|
BusClinicEntity originClinicInfo = clinicService.getById(clinic.getId());
|
|
|
- if(originClinicInfo==null){
|
|
|
+ if (originClinicInfo == null) {
|
|
|
throw new CustomException("该住院号临床信息不存在,请刷新后重试");
|
|
|
}
|
|
|
BusPatientEntity originPatientInfo = patientService.getById(originClinicInfo.getPatientId());
|
|
|
- if(originPatientInfo==null){
|
|
|
+ if (originPatientInfo == null) {
|
|
|
throw new CustomException("该住院号信息不存在,请刷新后重试");
|
|
|
}
|
|
|
//先更新手术信息
|
|
|
@@ -249,62 +252,64 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
this.updateById(patient);
|
|
|
patientOperator.setClinicId(patient.getClinicId());
|
|
|
|
|
|
- CompletableFuture.runAsync(()->{
|
|
|
- wsPublishUtils.publishPatientMonitor(originPatientInfo.getId(),patient.getTenantId());
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ wsPublishUtils.publishPatientMonitor(originPatientInfo.getId(), patient.getTenantId());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据病号查询临床监控记录
|
|
|
- * @author lifang
|
|
|
+ *
|
|
|
* @param patientId 病号id
|
|
|
- * @param tenantId 医院id
|
|
|
+ * @param tenantId 医院id
|
|
|
* @return
|
|
|
+ * @author lifang
|
|
|
*/
|
|
|
- public PatientMonitorResult lookMonitorByPatientCode(String patientId,String tenantId) {
|
|
|
+ public PatientMonitorResult lookMonitorByPatientCode(String patientId, String tenantId) {
|
|
|
try {
|
|
|
return this.baseMapper.findByPatientId(tenantId, patientId);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("根据病号查询临床失败,",e.getMessage());
|
|
|
+ log.error("根据病号查询临床失败,", e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 描述: 设备状态数量统计
|
|
|
- * @author lifang
|
|
|
- * @date 2022/5/8 21:52
|
|
|
+ *
|
|
|
* @param tenantId 医院id 用户请求时传输null
|
|
|
* @return MonitorStatusStatsCountResult
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/8 21:52
|
|
|
*/
|
|
|
public MonitorStatusStatsCountResult statusStats(String tenantId) {
|
|
|
PatientMonitorQuery query = new PatientMonitorQuery();
|
|
|
query.setTenantId(tenantId);
|
|
|
List<PatientMonitorResult> patientMonitorResults = this.selectAll(query);
|
|
|
MonitorStatusStatsCountResult result = new MonitorStatusStatsCountResult();
|
|
|
- if(CollectionUtil.isNotEmpty(patientMonitorResults)){
|
|
|
- patientMonitorResults.forEach(monitor->{
|
|
|
+ if (CollectionUtil.isNotEmpty(patientMonitorResults)) {
|
|
|
+ patientMonitorResults.forEach(monitor -> {
|
|
|
//运行数量
|
|
|
- if(!Boolean.TRUE.equals(monitor.getInfusionFinished())&&
|
|
|
- DeviceStatusEnum.Running.equals(monitor.getDeviceRunState())){
|
|
|
- result.setRunningCount(result.getRunningCount()+1);
|
|
|
+ if (!Boolean.TRUE.equals(monitor.getInfusionFinished()) &&
|
|
|
+ DeviceStatusEnum.Running.equals(monitor.getDeviceRunState())) {
|
|
|
+ result.setRunningCount(result.getRunningCount() + 1);
|
|
|
}
|
|
|
- if((Boolean.TRUE.equals(monitor.getInfusionFinished()))||
|
|
|
- (DeviceStatusEnum.Shutdown.equals(monitor.getDeviceRunState())||DeviceStatusEnum.NoSignal.equals(monitor.getDeviceRunState()))){
|
|
|
- result.setWaitingFinish(result.getWaitingFinish()+1);
|
|
|
+ if ((Boolean.TRUE.equals(monitor.getInfusionFinished())) ||
|
|
|
+ (DeviceStatusEnum.Shutdown.equals(monitor.getDeviceRunState()) || DeviceStatusEnum.NoSignal.equals(monitor.getDeviceRunState()))) {
|
|
|
+ result.setWaitingFinish(result.getWaitingFinish() + 1);
|
|
|
}
|
|
|
//报警数量
|
|
|
- if(!Boolean.TRUE.equals(monitor.getInfusionFinished())&&
|
|
|
- monitor.getDeviceAlarm()!=null&&!monitor.getDeviceAlarm().equals(DeviceAlarmEnum.None)){
|
|
|
- result.setAlarmCount(result.getAlarmCount()+1);
|
|
|
+ if (!Boolean.TRUE.equals(monitor.getInfusionFinished()) &&
|
|
|
+ monitor.getDeviceAlarm() != null && !monitor.getDeviceAlarm().equals(DeviceAlarmEnum.None)) {
|
|
|
+ result.setAlarmCount(result.getAlarmCount() + 1);
|
|
|
}
|
|
|
//提醒数量
|
|
|
- if(!Boolean.TRUE.equals(monitor.getInfusionFinished())&&
|
|
|
+ if (!Boolean.TRUE.equals(monitor.getInfusionFinished()) &&
|
|
|
(Boolean.TRUE.equals(monitor.getWarnAnalgesicPoor())
|
|
|
- ||Boolean.TRUE.equals(monitor.getWarnLowBattery())
|
|
|
- ||Boolean.TRUE.equals(monitor.getWarnWillFinished())
|
|
|
- ||monitor.getWarnFlow()!=null)){
|
|
|
- result.setWarnCount(result.getWarnCount()+1);
|
|
|
+ || Boolean.TRUE.equals(monitor.getWarnLowBattery())
|
|
|
+ || Boolean.TRUE.equals(monitor.getWarnWillFinished())
|
|
|
+ || monitor.getWarnFlow() != null)) {
|
|
|
+ result.setWarnCount(result.getWarnCount() + 1);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -313,38 +318,39 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
|
|
|
/**
|
|
|
* 描述: 按照时间对输注监控进行统计
|
|
|
- * @author lifang
|
|
|
- * @date 2022/5/8 22:40
|
|
|
+ *
|
|
|
* @param tenantId 医院id
|
|
|
* @return MonitorTimeStatsCountResult
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/8 22:40
|
|
|
*/
|
|
|
public MonitorTimeStatsCountResult timeStats(String tenantId) {
|
|
|
PatientMonitorQuery query = new PatientMonitorQuery();
|
|
|
query.setTenantId(tenantId);
|
|
|
List<PatientMonitorResult> patientMonitorResults = this.selectAll(query);
|
|
|
MonitorTimeStatsCountResult result = new MonitorTimeStatsCountResult();
|
|
|
- patientMonitorResults.forEach(monitor->{
|
|
|
+ patientMonitorResults.forEach(monitor -> {
|
|
|
Date startTime = monitor.getMonitorStartTime();
|
|
|
- if(startTime==null){
|
|
|
+ if (startTime == null) {
|
|
|
return;
|
|
|
}
|
|
|
if (includeTimes(startTime, 0)) {
|
|
|
- result.setToday(result.getToday()+1);
|
|
|
+ result.setToday(result.getToday() + 1);
|
|
|
return;
|
|
|
}
|
|
|
if (includeTimes(startTime, -1)) {
|
|
|
- result.setOneDay(result.getOneDay()+1);
|
|
|
+ result.setOneDay(result.getOneDay() + 1);
|
|
|
return;
|
|
|
}
|
|
|
if (includeTimes(startTime, -2)) {
|
|
|
- result.setTwoDay(result.getTwoDay()+1);
|
|
|
+ result.setTwoDay(result.getTwoDay() + 1);
|
|
|
return;
|
|
|
}
|
|
|
if (includeTimes(startTime, -3)) {
|
|
|
- result.setThreeDay(result.getThreeDay()+1);
|
|
|
+ result.setThreeDay(result.getThreeDay() + 1);
|
|
|
return;
|
|
|
}
|
|
|
- result.setBeyondThreeDay(result.getBeyondThreeDay()+1);
|
|
|
+ result.setBeyondThreeDay(result.getBeyondThreeDay() + 1);
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
@@ -352,62 +358,63 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
|
|
|
|
|
|
/**
|
|
|
* 描述: 判断所给时间是否在存在于某一时间段内
|
|
|
- * @author lifang
|
|
|
- * @date 2022/5/8 22:47
|
|
|
- * @param time 时间
|
|
|
+ *
|
|
|
+ * @param time 时间
|
|
|
* @param offset 时间偏移量,单位:天 以当天时间为基准进行偏移
|
|
|
* @return boolean
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/8 22:47
|
|
|
*/
|
|
|
- private boolean includeTimes(Date time,int offset){
|
|
|
- if(time==null){
|
|
|
+ private boolean includeTimes(Date time, int offset) {
|
|
|
+ if (time == null) {
|
|
|
return false;
|
|
|
}
|
|
|
LocalDateTime dateTime = LocalDateTime.now().plusDays(offset);
|
|
|
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(dateTime);
|
|
|
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(dateTime);
|
|
|
- return beginTime.toInstant(ZoneOffset.of("+8")).toEpochMilli()<time.getTime()
|
|
|
- && time.getTime()<endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
+ return beginTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() < time.getTime()
|
|
|
+ && time.getTime() < endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 切换主泵
|
|
|
+ *
|
|
|
* @param shiftConfig 切换配置
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void shift(DeviceShiftConfig shiftConfig) {
|
|
|
String formatCode = shiftConfig.getPatientCode();
|
|
|
BusPatientEntity patient = patientService.getOne(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode, formatCode));
|
|
|
- if(patient==null){
|
|
|
- throw new CustomException(String.format("住院号【%s】不存在,请刷新后重试",shiftConfig.getPatientCode()));
|
|
|
+ if (patient == null) {
|
|
|
+ throw new CustomException(String.format("住院号【%s】不存在,请刷新后重试", shiftConfig.getPatientCode()));
|
|
|
}
|
|
|
shiftConfig.setPatientId(patient.getId());
|
|
|
PatientOperator patientOperator = patientRegistry.getOperator(shiftConfig.getTenantId(), shiftConfig.getPatientCode());
|
|
|
- List<String> replicaDeviceIds = shiftConfig.getReplicaDeviceIds();
|
|
|
+
|
|
|
String masterDeviceId = shiftConfig.getMasterDeviceId();
|
|
|
|
|
|
BusInfusionHistoryEntity masterInfusion = infusionHistoryService.lastInfusion(masterDeviceId);
|
|
|
|
|
|
//病患绑定主泵信息
|
|
|
this.update(new UpdateWrapper<BusPatientEntity>().lambda()
|
|
|
- .eq(BusPatientEntity::getCode,shiftConfig.getPatientCode())
|
|
|
- .eq(BusPatientEntity::getTenantId,shiftConfig.getTenantId())
|
|
|
- .set(BusPatientEntity::getInfusionId,masterInfusion.getId()));
|
|
|
-
|
|
|
- //刷新缓存信息
|
|
|
- replicaDeviceIds.stream()
|
|
|
- .map(deviceRegistry::getOperator).forEach(deviceOperator->{
|
|
|
- deviceOperator.setMaster(false);
|
|
|
- });
|
|
|
+ .eq(BusPatientEntity::getCode, shiftConfig.getPatientCode())
|
|
|
+ .eq(BusPatientEntity::getTenantId, shiftConfig.getTenantId())
|
|
|
+ .set(BusPatientEntity::getInfusionId, masterInfusion.getId()));
|
|
|
|
|
|
patientOperator.setBindDeviceId(shiftConfig.getMasterDeviceId());
|
|
|
}
|
|
|
|
|
|
- public BusPatientEntity findByFormatCode(String patientCode, String tenantId){
|
|
|
- return this.getOne(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode,patientCode)
|
|
|
- .eq(StrUtil.isNotBlank(tenantId),BusPatientEntity::getTenantId,tenantId));
|
|
|
+ public BusPatientEntity findByFormatCode(String patientCode, String tenantId) {
|
|
|
+ return this.getOne(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode, patientCode)
|
|
|
+ .eq(StrUtil.isNotBlank(tenantId), BusPatientEntity::getTenantId, tenantId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public BusPatientEntity findByFormatCode(String patientCode) {
|
|
|
+ return findByFormatCode(patientCode, null);
|
|
|
}
|
|
|
|
|
|
- public BusPatientEntity findByFormatCode(String patientCode){
|
|
|
- return findByFormatCode(patientCode,null);
|
|
|
+ public BusPatientEntity findByOriginCode(String patientCode, String tenantId) {
|
|
|
+ return this.getOne(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getOriginCode, patientCode)
|
|
|
+ .eq(StrUtil.isNotBlank(tenantId), BusPatientEntity::getTenantId, tenantId));
|
|
|
}
|
|
|
}
|