|
|
@@ -4,11 +4,10 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.coffee.bus.bean.HisInfo;
|
|
|
import com.coffee.bus.entity.BusClinicEntity;
|
|
|
-import com.coffee.bus.entity.BusNetPumpHistoryEntity;
|
|
|
+import com.coffee.bus.entity.BusPumpHistoryEntity;
|
|
|
import com.coffee.bus.entity.BusPatientEntity;
|
|
|
import com.coffee.bus.listener.event.bean.HistoryInfoEvent;
|
|
|
import com.coffee.bus.script.ExecuteResult;
|
|
|
@@ -43,9 +42,7 @@ public class HistoryInfoListener {
|
|
|
|
|
|
private final LocalBusClinicService clinicService;
|
|
|
|
|
|
- private final LocalBusNetPumpHistoryService historyService;
|
|
|
-
|
|
|
- private final LocalBusNetPumpService netPumpService;
|
|
|
+ private final LocalBusPumpHistoryService historyService;
|
|
|
|
|
|
private final RedisTemplate redisTemplate;
|
|
|
|
|
|
@@ -62,7 +59,7 @@ public class HistoryInfoListener {
|
|
|
List<HisInfo> hisInfos = resultArray.parallelStream()
|
|
|
.map(result -> JSONUtil.toBean(JSONUtil.toJsonStr(result), HisInfo.class))
|
|
|
.peek(info-> info.setHospitalId(historyId))
|
|
|
- .peek(this::handle)
|
|
|
+ .peek(hisInfo -> this.handle(hisInfo,infoEvent.getRequestId()))
|
|
|
.collect(Collectors.toList());
|
|
|
//获取到his信息进行处理 todo
|
|
|
}else {
|
|
|
@@ -75,7 +72,7 @@ public class HistoryInfoListener {
|
|
|
* @param hisInfo
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void handle(HisInfo hisInfo){
|
|
|
+ public void handle(HisInfo hisInfo,Long requestId){
|
|
|
//获取病人信息
|
|
|
BusPatientEntity patient = BusPatientEntity.of(hisInfo);
|
|
|
if(!patientService.exist(patient.getCode(),patient.getTenantId())){
|
|
|
@@ -87,37 +84,41 @@ public class HistoryInfoListener {
|
|
|
//判断临床的唯一性
|
|
|
BusClinicEntity currentClinic = clinicService.getCurrentClinic(hisInfo.getHospitalId(), hisInfo.getPatientCode());
|
|
|
if (currentClinic==null) {
|
|
|
- clinic.setId(String.valueOf(IdWorker.getId()));
|
|
|
- //不存在此次临床信息,保存新的临床信息记录
|
|
|
- clinicService.update(
|
|
|
- new UpdateWrapper<BusClinicEntity>().lambda()
|
|
|
- .eq(BusClinicEntity::getStartTime,clinic.getStartTime())
|
|
|
- .eq(BusClinicEntity::getPatientCode,clinic.getPatientCode())
|
|
|
- .eq(BusClinicEntity::getTenantId,clinic.getTenantId())
|
|
|
- .set(BusClinicEntity::getFinished,true));
|
|
|
- //找到此病号信息且未绑定临床号,获取临床绑定设备号,并将临床信息与此次信息进行绑定 todo
|
|
|
- List<BusNetPumpHistoryEntity> historyList = historyService.list(
|
|
|
- new QueryWrapper<BusNetPumpHistoryEntity>()
|
|
|
- .lambda()
|
|
|
- .select(BusNetPumpHistoryEntity::getId)
|
|
|
- .select(BusNetPumpHistoryEntity::getDeviceId)
|
|
|
- .eq(BusNetPumpHistoryEntity::getTenantId, clinic.getTenantId())
|
|
|
- .eq(BusNetPumpHistoryEntity::getPatientCode, clinic.getPatientCode())
|
|
|
- .isNull(BusNetPumpHistoryEntity::getClinicId));
|
|
|
- if (CollectionUtil.isNotEmpty(historyList)) {
|
|
|
- //历史信息与临床号绑定
|
|
|
- historyList.forEach(history->history.setClinicId(clinic.getId()));
|
|
|
- historyService.updateBatchById(historyList);
|
|
|
- clinic.setDeviceCodes(historyList.stream().map(BusNetPumpHistoryEntity::getDeviceId).collect(Collectors.toSet()));
|
|
|
- }
|
|
|
- clinicService.save(clinic);
|
|
|
- log.info("新增临床信息,[{}]",clinic);
|
|
|
+ updateClinic(clinic,requestId);
|
|
|
}else {
|
|
|
//临床信息已存在,判断上传信息是否发生重复,是否为最新临床信息
|
|
|
-
|
|
|
+ if(currentClinic.getName().equals(clinic.getName())&¤tClinic.getStartTime().equals(clinic.getStartTime())){
|
|
|
+ //判断为同一临床信息,不予处理
|
|
|
+ return ;
|
|
|
+ }else {
|
|
|
+ //不同的临床信息,则进行更新
|
|
|
+ updateClinic(clinic,requestId);
|
|
|
+ }
|
|
|
}
|
|
|
//发送临床信息
|
|
|
String topic = WebSocketConstant.getClinicInfoTopic(null, clinic.getPatientCode(), clinic.getTenantId());
|
|
|
redisTemplate.convertAndSend(topic, clinic);
|
|
|
}
|
|
|
+
|
|
|
+ private void updateClinic(BusClinicEntity clinic,Long requestId){
|
|
|
+ clinic.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ //找到此病号信息且未绑定临床号,获取临床绑定设备号,并将临床信息与此次信息进行绑定
|
|
|
+ List<BusPumpHistoryEntity> historyList = historyService.list(
|
|
|
+ new QueryWrapper<BusPumpHistoryEntity>()
|
|
|
+ .lambda()
|
|
|
+ .select(BusPumpHistoryEntity::getId)
|
|
|
+ .select(BusPumpHistoryEntity::getDeviceId)
|
|
|
+ .eq(BusPumpHistoryEntity::getTenantId, clinic.getTenantId())
|
|
|
+ .eq(BusPumpHistoryEntity::getPatientCode, clinic.getPatientCode())
|
|
|
+ .le(requestId!=null, BusPumpHistoryEntity::getRequestId,requestId)
|
|
|
+ .isNull(BusPumpHistoryEntity::getClinicId));
|
|
|
+ if (CollectionUtil.isNotEmpty(historyList)) {
|
|
|
+ //历史信息与临床号绑定
|
|
|
+ historyList.forEach(history->history.setClinicId(clinic.getId()));
|
|
|
+ historyService.updateBatchById(historyList);
|
|
|
+ clinic.setDeviceCodes(historyList.stream().map(BusPumpHistoryEntity::getDeviceId).collect(Collectors.toSet()));
|
|
|
+ }
|
|
|
+ clinicService.save(clinic);
|
|
|
+ log.info("新增临床信息,[{}]",clinic);
|
|
|
+ }
|
|
|
}
|