|
|
@@ -1,11 +1,14 @@
|
|
|
package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
+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.BusPatientEntity;
|
|
|
import com.coffee.bus.listener.event.bean.HistoryInfoEvent;
|
|
|
import com.coffee.bus.script.ExecuteResult;
|
|
|
@@ -36,8 +39,6 @@ public class HistoryInfoListener {
|
|
|
|
|
|
private final ScriptManager scriptManager;
|
|
|
|
|
|
- private final LocalBusHospitalLogService hospitalLogService;
|
|
|
-
|
|
|
private final LocalBusPatientService patientService;
|
|
|
|
|
|
private final LocalBusClinicService clinicService;
|
|
|
@@ -47,6 +48,7 @@ public class HistoryInfoListener {
|
|
|
private final LocalBusNetPumpService netPumpService;
|
|
|
|
|
|
private final RedisTemplate redisTemplate;
|
|
|
+
|
|
|
@EventListener
|
|
|
public void historyInfoListener(HistoryInfoEvent infoEvent){
|
|
|
log.info("接收到了医院数据,[{}]",infoEvent.getContent());
|
|
|
@@ -54,6 +56,7 @@ public class HistoryInfoListener {
|
|
|
String content = infoEvent.getContent();
|
|
|
ExecuteResult exec = scriptManager.lookUpHospital(historyId).exec(content);
|
|
|
if(exec.isSuccess()){
|
|
|
+ log.info("医院数据解析成功,[{}]",exec.get());
|
|
|
//成功
|
|
|
JSONArray resultArray = (JSONArray) exec.get();
|
|
|
List<HisInfo> hisInfos = resultArray.parallelStream()
|
|
|
@@ -62,6 +65,8 @@ public class HistoryInfoListener {
|
|
|
.peek(this::handle)
|
|
|
.collect(Collectors.toList());
|
|
|
//获取到his信息进行处理 todo
|
|
|
+ }else {
|
|
|
+ log.info("医院数据解析失败,[{}]",exec.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -71,25 +76,45 @@ public class HistoryInfoListener {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void handle(HisInfo hisInfo){
|
|
|
- //获取病人信息 todo 判断是否为首次病人信息
|
|
|
+ //获取病人信息
|
|
|
BusPatientEntity patient = BusPatientEntity.of(hisInfo);
|
|
|
if(!patientService.exist(patient.getCode(),patient.getTenantId())){
|
|
|
//不存在病人信息则进行保存 ,病人基本信息不变动
|
|
|
patientService.save(patient);
|
|
|
+ log.info("新增病人信息,[{}]",patient);
|
|
|
}
|
|
|
BusClinicEntity clinic = BusClinicEntity.of(hisInfo);
|
|
|
- //判断临床的唯一性,todo 有没有可能同一病人同一时间多个临床信息
|
|
|
- if (clinicService.getOne(new QueryWrapper<BusClinicEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(BusClinicEntity::getStartTime,clinic.getStartTime())
|
|
|
- .eq(BusClinicEntity::getPatientCode,clinic.getPatientCode())
|
|
|
- .eq(BusClinicEntity::getTenantId,clinic.getTenantId()))==null) {
|
|
|
+ //判断临床的唯一性
|
|
|
+ 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));
|
|
|
+ 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);
|
|
|
+ }else {
|
|
|
+ //临床信息已存在,判断上传信息是否发生重复,是否为最新临床信息
|
|
|
+
|
|
|
}
|
|
|
//发送临床信息
|
|
|
String topic = WebSocketConstant.getClinicInfoTopic(null, clinic.getPatientCode(), clinic.getTenantId());
|