|
|
@@ -0,0 +1,94 @@
|
|
|
+package com.coffee.bus.websocket.listener;
|
|
|
+
|
|
|
+import cn.hutool.json.JSON;
|
|
|
+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.coffee.bus.bean.HisInfo;
|
|
|
+import com.coffee.bus.entity.BusClinicEntity;
|
|
|
+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 lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+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
|
|
|
+@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class HistoryInfoListener {
|
|
|
+
|
|
|
+ private final ScriptManager scriptManager;
|
|
|
+
|
|
|
+ private final LocalBusHospitalLogService hospitalLogService;
|
|
|
+
|
|
|
+ private final LocalBusPatientService patientService;
|
|
|
+
|
|
|
+ private final LocalBusClinicService clinicService;
|
|
|
+
|
|
|
+ private final LocalBusNetPumpHistoryService historyService;
|
|
|
+
|
|
|
+ private final LocalBusNetPumpService netPumpService;
|
|
|
+ @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()){
|
|
|
+ //成功
|
|
|
+ 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(this::handle)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //获取到his信息进行处理 todo
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理医院传来的his信息
|
|
|
+ * @param hisInfo
|
|
|
+ */
|
|
|
+ @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);
|
|
|
+ }
|
|
|
+ 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) {
|
|
|
+ //不存在此次临床信息,保存新的临床信息记录
|
|
|
+ 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.save(clinic);
|
|
|
+ }
|
|
|
+ //发送临床信息
|
|
|
+
|
|
|
+ }
|
|
|
+}
|