|
|
@@ -1,14 +1,20 @@
|
|
|
package com.coffee.bus.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.coffee.bus.controller.vo.ClinicStatsVo;
|
|
|
import com.coffee.bus.entity.BusClinicEntity;
|
|
|
+import com.coffee.bus.entity.BusDeviceRunningEntity;
|
|
|
+import com.coffee.bus.entity.BusInfusionHistoryEntity;
|
|
|
import com.coffee.bus.entity.BusPatientEntity;
|
|
|
import com.coffee.bus.mapper.BusClinicMapper;
|
|
|
+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.ClinicQuery;
|
|
|
import com.coffee.bus.service.dto.ClinicResult;
|
|
|
import com.coffee.bus.service.dto.ClinicStatsQueryResult;
|
|
|
@@ -20,7 +26,10 @@ import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
/**
|
|
|
* @author lifang
|
|
|
@@ -34,10 +43,16 @@ import java.util.*;
|
|
|
public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClinicEntity,String> {
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
- private LocalBusPatientService patientService;
|
|
|
+ private PatientRegistry patientRegistry;
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
- private PatientRegistry patientRegistry;
|
|
|
+ private LocalBusInfusionHistoryService infusionHistoryService;
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private LocalBusDeviceRunningService deviceRunningService;
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private LocalBusPatientService patientService;
|
|
|
@Override
|
|
|
public void validateBeforeSave(BusClinicEntity entity) {
|
|
|
|
|
|
@@ -94,6 +109,104 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
|
|
|
return this.baseMapper.recentClinic(hospitalId,patientCode);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 描述: 对两场手术进行比较,判断名称、时间是否发生了变化
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/12 9:10
|
|
|
+ * @param source his系统拉取的数据
|
|
|
+ * @param target 数据库存储的数据
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void compareFromHis(BusClinicEntity source,BusClinicEntity target){
|
|
|
+ Assert.hasText(target.getId(),"LocalBusClinicService.compareFromHis方法调用时,target参数id不能为空");
|
|
|
+ Assert.hasText(source.getPatientCode(),"LocalBusClinicService.compareFromHis方法调用时,source参数patientCode不能为空");
|
|
|
+ Assert.notNull(source.getStartTime(),"LocalBusClinicService.compareFromHis方法调用时,source参数startTime不能为空");
|
|
|
+ Assert.hasText(source.getName(),"LocalBusClinicService.compareFromHis方法调用时,source参数name不能为空");
|
|
|
+ source.setId(target.getId());
|
|
|
+ this.updateById(source);
|
|
|
+ //手术开始时间发生变化,重新计算输注数据
|
|
|
+ if(source.getStartTime()!=null&&source.getStartTime()!=target.getStartTime()){
|
|
|
+ infusionHistoryService.adjustInfusionByClinic(source.getId(),source.getPatientCode(),source.getTenantId(),source.getStartTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述: his拉取的新的手术信息,执行插入操作
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/12 10:27
|
|
|
+ * @param source
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void insertFromHis(BusClinicEntity source){
|
|
|
+ Assert.hasText(source.getTenantId(),"LocalBusClinicService.insertFromHis方法调用时,source参数tenantId不能为空");
|
|
|
+ Assert.hasText(source.getPatientCode(),"LocalBusClinicService.insertFromHis方法调用时,source参数patientCode不能为空");
|
|
|
+ Assert.hasText(source.getName(),"LocalBusClinicService.insertFromHis方法调用时,source参数name不能为空");
|
|
|
+ this.save(source);
|
|
|
+ infusionHistoryService.adjustInfusionByClinic(source.getId(),source.getPatientCode(),source.getTenantId(),source.getStartTime());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述: 从his拉去的数据设置为当前临床信息
|
|
|
+ * @author lifang
|
|
|
+ * @date 2022/5/12 10:31
|
|
|
+ * @param source
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void setCurrentClinicByHis(BusClinicEntity source){
|
|
|
+ Assert.hasText(source.getId(),"LocalBusClinicService.setCurrentClinic方法调用时,source参数id不能为空");
|
|
|
+ Assert.hasText(source.getPatientCode(),"LocalBusClinicService.setCurrentClinic方法调用时,source参数patientCode不能为空");
|
|
|
+ Assert.hasText(source.getTenantId(),"LocalBusClinicService.setCurrentClinic方法调用时,source参数tenantId不能为空");
|
|
|
+ Assert.notNull(source.getStartTime(),"LocalBusClinicService.setCurrentClinic方法调用时,source参数startTime不能为空");
|
|
|
+ //处理当前运行的信息
|
|
|
+ deviceRunningService.update(new UpdateWrapper<BusDeviceRunningEntity>().lambda()
|
|
|
+ .eq(BusDeviceRunningEntity::getPatientCode,source.getPatientCode())
|
|
|
+ .eq(BusDeviceRunningEntity::getTenantId,source.getTenantId())
|
|
|
+ .set(BusDeviceRunningEntity::getClinicId,source.getId()));
|
|
|
+
|
|
|
+ //处理当前的输注信息
|
|
|
+ infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
|
|
|
+ .eq(BusInfusionHistoryEntity::getPatientCode,source.getPatientCode())
|
|
|
+ .eq(BusInfusionHistoryEntity::getTenantId,source.getTenantId())
|
|
|
+ .eq(BusInfusionHistoryEntity::getFinished,false)
|
|
|
+ .set(BusInfusionHistoryEntity::getClinicId,source.getId()));
|
|
|
+
|
|
|
+ //更新病人信息
|
|
|
+ patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
|
|
|
+ .eq(BusPatientEntity::getCode,source.getPatientCode())
|
|
|
+ .eq(BusPatientEntity::getTenantId,source.getTenantId())
|
|
|
+ .set(BusPatientEntity::getClinicId,source.getId()));
|
|
|
+ //处理
|
|
|
+ List<BusClinicEntity> clinics = this.list(new QueryWrapper<BusClinicEntity>().lambda()
|
|
|
+ .eq(BusClinicEntity::getPatientCode, source.getPatientCode())
|
|
|
+ .eq(BusClinicEntity::getTenantId, source.getTenantId())
|
|
|
+ .eq(BusClinicEntity::getFinished, false)
|
|
|
+ .ne(BusClinicEntity::getId, source.getId()));
|
|
|
+ //将下一场手术的开始时间作为该场手术监控的结束时间
|
|
|
+ clinics.sort(Comparator.comparing(BusClinicEntity::getStartTime));
|
|
|
+ for (int i = 0; i < clinics.size(); i++) {
|
|
|
+ BusClinicEntity clinic = clinics.get(i);
|
|
|
+ clinic.setFinished(true);
|
|
|
+ if(i==clinics.size()-1){
|
|
|
+ if(clinic.getEndTime()==null){
|
|
|
+ clinic.setEndTime(source.getEndTime());
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(clinic.getEndTime()==null){
|
|
|
+ clinic.setEndTime(clinics.get(i+1).getStartTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateBatchById(clinics);
|
|
|
+
|
|
|
+ PatientOperator<PatientCacheInfo> operator = patientRegistry.getOperator(source.getTenantId(), source.getPatientCode());
|
|
|
+ operator.setClinicId(source.getId());
|
|
|
+ }
|
|
|
/**
|
|
|
* 从his同步病人数据-异步
|
|
|
* @param hospitalId
|