|
|
@@ -1,169 +0,0 @@
|
|
|
-package com.coffee.bus.websocket.listener;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.extra.spring.SpringUtil;
|
|
|
-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.BusDeviceRunningEntity;
|
|
|
-import com.coffee.bus.entity.BusDeviceHistoryEntity;
|
|
|
-import com.coffee.bus.entity.BusPatientEntity;
|
|
|
-import com.coffee.bus.listener.event.bean.HistoryInfoEvent;
|
|
|
-import com.coffee.bus.script.ExecuteResult;
|
|
|
-import com.coffee.bus.script.ScriptManager;
|
|
|
-import com.coffee.bus.service.*;
|
|
|
-import com.coffee.common.config.websocket.WebSocketConstant;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.event.EventListener;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author lifang
|
|
|
- * @version 1.0.0
|
|
|
- * @ClassName HistoryInfoListener.java
|
|
|
- * @Description TODO
|
|
|
- * @createTime 2022年03月29日 15:23:00
|
|
|
- */
|
|
|
-@Component
|
|
|
-@Slf4j
|
|
|
-public class HistoryInfoListener {
|
|
|
-
|
|
|
- private final ScriptManager scriptManager;
|
|
|
-
|
|
|
- private final LocalBusPatientService patientService;
|
|
|
-
|
|
|
- private final LocalBusClinicService clinicService;
|
|
|
-
|
|
|
- private final LocalBusDeviceHistoryService historyService;
|
|
|
-
|
|
|
- private final RedisTemplate redisTemplate;
|
|
|
-
|
|
|
- private final LocalBusDeviceRunningService pumpService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public HistoryInfoListener(ScriptManager scriptManager, LocalBusPatientService patientService, LocalBusClinicService clinicService, LocalBusDeviceHistoryService historyService, RedisTemplate redisTemplate, LocalBusDeviceRunningService pumpService) {
|
|
|
- this.scriptManager = scriptManager;
|
|
|
- this.patientService = patientService;
|
|
|
- this.clinicService = clinicService;
|
|
|
- this.historyService = historyService;
|
|
|
- this.redisTemplate = redisTemplate;
|
|
|
- this.pumpService = pumpService;
|
|
|
- }
|
|
|
-
|
|
|
- private HistoryInfoListener historyInfoListener;
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- public void init(){
|
|
|
- historyInfoListener= SpringUtil.getBean(HistoryInfoListener.class);
|
|
|
- }
|
|
|
-
|
|
|
- @EventListener
|
|
|
- public void historyInfoListener(HistoryInfoEvent infoEvent){
|
|
|
- log.info("接收到了医院数据,[{}]",infoEvent.getContent());
|
|
|
- String historyId = infoEvent.getHistoryId();
|
|
|
- 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()
|
|
|
- .map(result -> JSONUtil.toBean(JSONUtil.toJsonStr(result), HisInfo.class))
|
|
|
- .peek(info-> info.setHospitalId(historyId))
|
|
|
- .peek(hisInfo -> this.handle(hisInfo,infoEvent.getRequestId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- //获取到his信息进行处理 todo
|
|
|
- }else {
|
|
|
- log.info("医院数据解析失败,[{}]",exec.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理医院传来的his信息
|
|
|
- * @param hisInfo
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void handle(HisInfo hisInfo,Long requestId){
|
|
|
- //获取病人信息
|
|
|
- BusPatientEntity patient = BusPatientEntity.of(hisInfo);
|
|
|
- if(!patientService.exist(patient.getCode(),patient.getTenantId())){
|
|
|
- //不存在病人信息则进行保存 ,病人基本信息不变动
|
|
|
- patientService.save(patient);
|
|
|
- log.info("新增病人信息,[{}]",patient);
|
|
|
- }
|
|
|
- BusClinicEntity clinic = BusClinicEntity.of(hisInfo);
|
|
|
- //判断临床的唯一性
|
|
|
- BusClinicEntity currentClinic = clinicService.getCurrentClinic(hisInfo.getHospitalId(), hisInfo.getPatientCode());
|
|
|
- if (currentClinic==null) {
|
|
|
-// historyInfoListener.updateClinic(clinic,requestId);
|
|
|
- }else {
|
|
|
- //临床信息已存在,判断上传信息是否发生重复,是否为最新临床信息
|
|
|
- if(currentClinic.getName().equals(clinic.getName())&¤tClinic.getStartTime().equals(clinic.getStartTime())){
|
|
|
- //判断为同一临床信息,不予处理
|
|
|
- return ;
|
|
|
- }else {
|
|
|
- //不同的临床信息,则进行更新
|
|
|
-// historyInfoListener.updateClinic(clinic,requestId);
|
|
|
- }
|
|
|
- }
|
|
|
- //发送临床信息
|
|
|
- String topic = WebSocketConstant.getClinicInfoTopic(null, clinic.getPatientCode(), clinic.getTenantId());
|
|
|
- redisTemplate.convertAndSend(topic, clinic);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// /**
|
|
|
-// * 针对临床信息更新设备以及设备历史信息
|
|
|
-// * @param clinic
|
|
|
-// * @param clinic
|
|
|
-// */
|
|
|
-//
|
|
|
-// @Async
|
|
|
-// @Transactional(rollbackFor = Exception.class)
|
|
|
-// public void updateClinic(BusClinicEntity clinic,Long requestId){
|
|
|
-// clinic.setId(String.valueOf(IdWorker.getId()));
|
|
|
-// //找到此病号信息且未绑定临床号,获取临床绑定设备号,并将临床信息与此次信息进行绑定
|
|
|
-// List<BusDeviceHistoryEntity> historyList = historyService.list(
|
|
|
-// new QueryWrapper<BusDeviceHistoryEntity>()
|
|
|
-// .lambda()
|
|
|
-// .select(BusDeviceHistoryEntity::getId)
|
|
|
-// .select(BusDeviceHistoryEntity::getDeviceId)
|
|
|
-// .eq(BusDeviceHistoryEntity::getTenantId, clinic.getTenantId())
|
|
|
-// .eq(BusDeviceHistoryEntity::getPatientCode, clinic.getPatientCode())
|
|
|
-// .le(requestId!=null, BusDeviceHistoryEntity::getRequestId,requestId)
|
|
|
-// .isNull(BusDeviceHistoryEntity::getClinicId));
|
|
|
-// if (CollectionUtil.isNotEmpty(historyList)) {
|
|
|
-// //历史信息与临床号绑定
|
|
|
-// historyList.forEach(history-> history.fillClinic(clinic));
|
|
|
-// historyService.updateBatchById(historyList);
|
|
|
-// clinic.setDeviceCodes(historyList.stream().map(BusDeviceHistoryEntity::getDeviceId).collect(Collectors.toSet()));
|
|
|
-// }
|
|
|
-//
|
|
|
-// pumpService.update(new UpdateWrapper<BusDeviceRunningEntity>()
|
|
|
-// .lambda()
|
|
|
-// .eq(BusDeviceRunningEntity::getPatientCode,clinic.getPatientCode())
|
|
|
-// .eq(BusDeviceRunningEntity::getTenantId,clinic.getTenantId())
|
|
|
-// .isNull(BusDeviceRunningEntity::getClinicId)
|
|
|
-// .set(BusDeviceRunningEntity::getClinicId,clinic.getId())
|
|
|
-// .set(BusDeviceRunningEntity::getPatientSex,clinic.getPatientGender())
|
|
|
-// .set(BusDeviceRunningEntity::getWard,clinic.getWard())
|
|
|
-// .set(BusDeviceRunningEntity::getBedNo,clinic.getBedNo())
|
|
|
-// .set(BusDeviceRunningEntity::getPatientName,clinic.getPatientName()));
|
|
|
-//
|
|
|
-// clinicService.save(clinic);
|
|
|
-// log.info("新增临床信息,[{}]",clinic);
|
|
|
-// }
|
|
|
-}
|