Переглянути джерело

add 接受医院His信息

18339543638 3 роки тому
батько
коміт
8f500f2daa

+ 1 - 1
coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java

@@ -32,7 +32,7 @@ public class DefaultMessageListener implements MessageListener {
     public void onMessage(Message message, byte[] pattern) {
         if (CollectionUtil.isNotEmpty(channelContexts)) {
             channelContexts.parallelStream()
-//                    .filter(channelContext -> !channelContext.isClosed)
+                    .filter(channelContext -> !channelContext.isClosed)
                     .forEach(channel -> Tio.send(channel,
                             WsResponse.fromText(JSONUtil.toJsonStr(R.success(
                                     new String(message.getBody())))

+ 89 - 0
coffee-system/src/main/java/com/coffee/bus/bean/HisInfo.java

@@ -0,0 +1,89 @@
+package com.coffee.bus.bean;
+
+import com.coffee.common.enums.SexEnum;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName HisInfo.java
+ * @Description his系统接收信息
+ * @createTime 2022年03月29日 16:39:00
+ */
+@Data
+public class HisInfo {
+    /**
+     * 医院id
+     */
+    private String hospitalId;
+    /**
+     * 住院号
+     */
+    private String patientCode;
+    /**
+     * 姓名
+     */
+    private String patientName;
+    /**
+     * 性别
+     */
+    private SexEnum gender;
+    /**
+     * 生日
+     */
+    private String birthday;
+    /**
+     * 年龄
+     */
+    private String age;
+    /**
+     * 身高
+     */
+    private String height;
+    /**
+     * 体重
+     */
+    private String weight;
+    /**
+     * 病区
+     */
+    private String ward;
+    /**
+     * 床号
+     */
+    private String bedNo;
+    /**
+     * 手术名称
+     */
+    private String operation;
+    /**
+     * 手术医生
+     */
+    private String surgeon;
+    /**
+     * 手术开始时间
+     */
+    private Date operationTime;
+    /**
+     * asa分级
+     */
+    private String asa;
+    /**
+     * PCA镇痛模式
+     */
+    private String easeMode;
+    /**
+     * 配方
+     */
+    private String formula;
+    /**
+     * 麻醉医生
+     */
+    private String doctor;
+    /**
+     * 配置医生(配置人员、配药医生)
+     */
+    private String configPerson;
+}

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/controller/BusNetPumpController.java

@@ -29,8 +29,8 @@ import org.springframework.web.bind.annotation.RestController;
 public class BusNetPumpController extends BaseCrudController<BusNetPumpEntity, String> {
     private final LocalBusNetPumpService netPumpService;
 
-    @GetMapping("/alarm/dict")
-    @Operation(summary = "网络泵报警信息枚举,无权限配置")
+    @GetMapping("/warn/dict")
+    @Operation(summary = "网络泵提醒信息枚举,无权限配置")
     public R alarm(){
         return R.success(NetPumpWarnEnum.values());
     }

+ 28 - 2
coffee-system/src/main/java/com/coffee/bus/entity/BusClinicEntity.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.coffee.bus.bean.HisInfo;
 import com.coffee.common.config.mybatis.DateToBigIntHandler;
 import com.coffee.common.entity.TenantGenericEntity;
 import com.coffee.common.enums.SexEnum;
@@ -83,7 +84,6 @@ public class BusClinicEntity extends TenantGenericEntity<String,String> {
     @Length(max = 255,message = "麻醉医生不得超过255个字节")
     private String anaDoctor;
 
-
     @ApiModelProperty(value = "麻醉方式")
     private String anaType;
 
@@ -94,16 +94,42 @@ public class BusClinicEntity extends TenantGenericEntity<String,String> {
     @Length(max = 255,message = "手术医生不得超过255个字节")
     private String surgeryDoctor;
 
-
     @ApiModelProperty(value = "手术名称")
     @Length(max = 255,message = "手术名称不得超过255个字节")
     private String surgeryName;
 
+    @ApiModelProperty(value = "配置人员")
+    private String configPerson;
+
     @ApiModelProperty(value = "配方")
     private String formula;
 
+    @ApiModelProperty(value = "临床是否结束")
+    private Boolean finished;
 
     @TableField(fill = FieldFill.INSERT)
     @TableLogic(value = "0",delval = "1")
     private Integer isDelete;
+
+    public static BusClinicEntity of(HisInfo hisInfo){
+        BusClinicEntity clinic = new BusClinicEntity();
+        clinic.setTenantId(hisInfo.getHospitalId());
+        clinic.setPatientCode(hisInfo.getPatientCode());
+        clinic.setPatientName(hisInfo.getPatientName());
+        clinic.setPatientGender(hisInfo.getGender());
+        clinic.setPatientAge(Integer.valueOf(hisInfo.getAge()));
+        clinic.setWeight(hisInfo.getWeight());
+        clinic.setHeight(hisInfo.getHeight());
+        //病区 需新增 todo
+        clinic.setDept(hisInfo.getWard());
+        clinic.setBedNo(hisInfo.getBedNo());
+        clinic.setName(hisInfo.getOperation());
+        clinic.setSurgeryDoctor(hisInfo.getSurgeon());
+        clinic.setStartTime(hisInfo.getOperationTime());
+        //asa分级 todo
+        //easymode todo
+        clinic.setFormula(hisInfo.getFormula());
+        clinic.setConfigPerson(hisInfo.getConfigPerson());
+        return clinic;
+    }
 }

+ 10 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusPatientEntity.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.coffee.bus.bean.HisInfo;
 import com.coffee.common.entity.TenantGenericEntity;
 import com.coffee.common.enums.SexEnum;
 import io.swagger.annotations.ApiModel;
@@ -40,4 +41,13 @@ public class BusPatientEntity extends TenantGenericEntity<String,String> {
     @TableField(fill = FieldFill.INSERT)
     @TableLogic(value = "0",delval = "1")
     private Integer isDelete;
+
+    public static BusPatientEntity of(HisInfo hisInfo){
+        BusPatientEntity patient = new BusPatientEntity();
+        patient.setCode(hisInfo.getPatientCode());
+        patient.setGender(hisInfo.getGender());
+        patient.setName(hisInfo.getPatientName());
+        patient.setTenantId(hisInfo.getHospitalId());
+        return patient;
+    }
 }

+ 8 - 2
coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceAlarmEvent.java

@@ -1,5 +1,7 @@
 package com.coffee.bus.listener.event.bean;
 
+import com.coffee.bus.entity.BusNetPumpEntity;
+import lombok.Data;
 import org.springframework.context.ApplicationEvent;
 
 import java.time.Clock;
@@ -11,13 +13,17 @@ import java.time.Clock;
  * @Description TODO
  * @createTime 2022年03月21日 16:44:00
  */
+@Data
 public class DeviceAlarmEvent extends ApplicationEvent {
 
-    public DeviceAlarmEvent(Object source) {
+    private final BusNetPumpEntity content;
+    public DeviceAlarmEvent(Object source,BusNetPumpEntity content) {
         super(source);
+        this.content=content;
     }
 
-    public DeviceAlarmEvent(Object source, Clock clock) {
+    public DeviceAlarmEvent(Object source, BusNetPumpEntity content,Clock clock) {
         super(source, clock);
+        this.content=content;
     }
 }

+ 10 - 2
coffee-system/src/main/java/com/coffee/bus/listener/event/bean/HistoryInfoEvent.java

@@ -1,5 +1,6 @@
 package com.coffee.bus.listener.event.bean;
 
+import lombok.Data;
 import org.springframework.context.ApplicationEvent;
 import java.time.Clock;
 
@@ -10,12 +11,19 @@ import java.time.Clock;
  * @Description TODO
  * @createTime 2022年03月21日 16:30:00
  */
+@Data
 public class HistoryInfoEvent extends ApplicationEvent {
-    public HistoryInfoEvent(Object source) {
+    private final String content;
+    private final String historyId;
+    public HistoryInfoEvent(Object source,String content,String historyId) {
         super(source);
+        this.content=content;
+        this.historyId=historyId;
     }
 
-    public HistoryInfoEvent(Object source, Clock clock) {
+    public HistoryInfoEvent(Object source, Clock clock,String content,String historyId) {
         super(source, clock);
+        this.content=content;
+        this.historyId=historyId;
     }
 }

+ 5 - 0
coffee-system/src/main/java/com/coffee/bus/service/LocalBusNetPumpService.java

@@ -1,5 +1,6 @@
 package com.coffee.bus.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.coffee.bus.entity.BusDoctorEntity;
 import com.coffee.bus.entity.BusNetPumpEntity;
 import com.coffee.bus.mapper.BusDoctorMapper;
@@ -30,4 +31,8 @@ public class LocalBusNetPumpService extends BaseService<BusNetPumpMapper, BusNet
     public void validateBeforeDelete(String id) {
 
     }
+
+    public boolean firstRegister(String deviceId){
+        return this.getOne(new QueryWrapper<BusNetPumpEntity>().lambda().eq(BusNetPumpEntity::getDeviceId,deviceId))!=null;
+    }
 }

+ 11 - 0
coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java

@@ -1,5 +1,6 @@
 package com.coffee.bus.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.coffee.bus.entity.BusDoctorEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.mapper.BusDoctorMapper;
@@ -30,4 +31,14 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
     public void validateBeforeDelete(String id) {
 
     }
+
+    public boolean exist(String patientCode,String hospitalId){
+        return this.getOne(new QueryWrapper<BusPatientEntity>().lambda().
+                eq(BusPatientEntity::getCode,patientCode).eq(BusPatientEntity::getTenantId,hospitalId))!=null;
+    }
+
+    public BusPatientEntity getByCode(String patientCode,String hospitalId){
+        return this.getOne(new QueryWrapper<BusPatientEntity>().lambda().
+                eq(BusPatientEntity::getCode,patientCode).eq(BusPatientEntity::getTenantId,hospitalId));
+    }
 }

+ 35 - 5
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -3,6 +3,7 @@ package com.coffee.bus.websocket.listener;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import com.coffee.bus.entity.BusNetPumpEntity;
+import com.coffee.bus.enums.NetPumpStatusEnum;
 import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
 import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
 import com.coffee.bus.service.LocalBusNetPumpService;
@@ -12,9 +13,7 @@ import org.springframework.context.event.EventListener;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
-
 import java.math.BigDecimal;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -31,6 +30,7 @@ public class DeviceInfoListener {
     private final RedisTemplate redisTemplate;
 
     private final LocalBusNetPumpService netPumpService;
+
     /**
      * 监听上传的数据信息,
      * 若设备详情发生变化,则及时通知相应的ws通道
@@ -38,10 +38,40 @@ public class DeviceInfoListener {
      */
     @EventListener
     public void deviceInfoDetail(DeviceInfoEvent infoEvent){
+        boolean first=false;
         BusNetPumpEntity pump = infoEvent.getContent();
-        //设备信息发生变化
-        String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, pump.getId(), pump.getTenantId());
-        redisTemplate.convertAndSend(topic, pump);
+        //1、判断设备是否为首次注册
+        first = netPumpService.firstRegister(infoEvent.getDeviceId());
+        //2、设备信息发生变化
+        if(first){
+            //3、将设备和医院、病人进行绑定 todo
+        }
+
+        NetPumpStatusEnum runState = pump.getRunState();
+        //发送设备报警
+
+        if(!first){
+            //非首次注册,则推送设备消息
+            String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, pump.getId(), pump.getTenantId());
+            redisTemplate.convertAndSend(topic, pump);
+        }
+        SpringUtil.publishEvent(new DeviceAlarmEvent(this,pump));
+    }
+
+
+    /**
+     * 监听设备的报警信息,
+     * @param alarmEvent
+     */
+    @EventListener
+    public void deviceAlarm(DeviceAlarmEvent alarmEvent){
+        BusNetPumpEntity pump = alarmEvent.getContent();
+        //获取医院配置,对医院功能配置进行过滤筛选
+        NetPumpStatusEnum runState = pump.getRunState();
+        if(runState!=null&&Boolean.TRUE.equals(runState.getAlarm())){
+            //设备发生报警
+        }
+
     }
 
 

+ 94 - 0
coffee-system/src/main/java/com/coffee/bus/websocket/listener/HistoryInfoListener.java

@@ -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);
+        }
+        //发送临床信息
+
+    }
+}