|
|
@@ -55,186 +55,11 @@ public class HisInfoListener {
|
|
|
this.patientService = patientService;
|
|
|
}
|
|
|
|
|
|
- private HisInfoListener hisInfoListener;
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- public void init(){
|
|
|
- hisInfoListener = SpringUtil.getBean(HisInfoListener.class);
|
|
|
- }
|
|
|
|
|
|
@EventListener
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void historyInfoListener(HisEvent infoEvent){
|
|
|
List<BusClinicEntity> clinics = infoEvent.getClinics();
|
|
|
- if(CollectionUtil.isEmpty(clinics)){
|
|
|
- return;
|
|
|
- }
|
|
|
- //处理病人信息
|
|
|
- BusPatientEntity patient = clinics.stream().map(clinicEntity -> {
|
|
|
- BusPatientEntity patientEntity = new BusPatientEntity();
|
|
|
- patientEntity.setName(clinicEntity.getPatientName());
|
|
|
- patientEntity.setGender(clinicEntity.getPatientGender());
|
|
|
- patientEntity.setCode(clinicEntity.getPatientCode());
|
|
|
- patientEntity.setTenantId(clinicEntity.getTenantId());
|
|
|
- return patientEntity;
|
|
|
- }).findFirst().get();
|
|
|
- PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(patient.getTenantId(), patient.getCode());
|
|
|
- String name = patientOperator.getName();
|
|
|
- if(StrUtil.isNullOrUndefined(name)){
|
|
|
- patientService.update(new UpdateWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode,patient.getCode())
|
|
|
- .eq(BusPatientEntity::getTenantId,patient.getTenantId())
|
|
|
- .set(BusPatientEntity::getName,patient.getName())
|
|
|
- .set(BusPatientEntity::getGender,patient.getGender()));
|
|
|
- patientOperator.setName(patient.getName());
|
|
|
- patientOperator.setGender(patient.getGender());
|
|
|
- }
|
|
|
- //处理病人手术信息
|
|
|
- clinics.parallelStream().forEach(hisInfoListener::handle);
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void handle(BusClinicEntity clinic){
|
|
|
- //判断病人手术信息是否存在
|
|
|
- BusClinicEntity existClinic = lookUpClinic(clinic);
|
|
|
- //同一手术信息病号、床号是否发生了变化
|
|
|
- Boolean changed=null;
|
|
|
- if(existClinic==null){
|
|
|
- //找到该次病人首次监控开始时间
|
|
|
- //手术信息不存在
|
|
|
- clinicService.save(clinic);
|
|
|
- //常量信息异步处理,失败了无需关注
|
|
|
- hisInfoListener.handleConstant(clinic);
|
|
|
- // 输注开始时间>手术开始时间>输注绑定的手术开始时间 找到与输注时间最为相近的手术
|
|
|
- infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>()
|
|
|
- .lambda()
|
|
|
- .set(BusInfusionHistoryEntity::getClinicId,clinic.getId())
|
|
|
- .set(BusInfusionHistoryEntity::getClinicStartTime,clinic.getStartTime())
|
|
|
- .eq(BusInfusionHistoryEntity::getTenantId,clinic.getTenantId())
|
|
|
- .ge(BusInfusionHistoryEntity::getStartTime,clinic.getStartTime())
|
|
|
- .le(BusInfusionHistoryEntity::getClinicStartTime,clinic.getStartTime())
|
|
|
- );
|
|
|
- }else {
|
|
|
- clinic.setId(existClinic.getId());
|
|
|
- //判断手术的病区床号是否发生了变化
|
|
|
- if(!existClinic.getWard().equals(clinic.getWard())||!existClinic.getBedNo().equals(clinic.getBedNo())){
|
|
|
- changed=true;
|
|
|
- //更新手术信息
|
|
|
- clinicService.update(new UpdateWrapper<BusClinicEntity>().lambda()
|
|
|
- .eq(BusClinicEntity::getId,existClinic.getId())
|
|
|
- .set(BusClinicEntity::getWard,clinic.getWard())
|
|
|
- .set(BusClinicEntity::getBedNo,clinic.getBedNo()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- handleRunningClinic(clinic,changed);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取手术信息
|
|
|
- * @param clinic
|
|
|
- * @return
|
|
|
- */
|
|
|
- private BusClinicEntity lookUpClinic(BusClinicEntity clinic){
|
|
|
- return clinicService.getOne(new QueryWrapper<BusClinicEntity>().lambda().eq(BusClinicEntity::getPatientCode, clinic.getPatientCode())
|
|
|
- .eq(BusClinicEntity::getName, clinic.getName())
|
|
|
- .eq(BusClinicEntity::getStartTime, clinic.getStartTime()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理手术信息中的常量信息数据 todo
|
|
|
- * @param clinic 接收到的临床数据
|
|
|
- */
|
|
|
- @Async
|
|
|
- public void handleConstant(BusClinicEntity clinic){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断并处理正在进行的临床信息
|
|
|
- * @param clinic 接收到的临床数据
|
|
|
- * @param changed 临床数据存在且已发生改变, null 时表示该临床数据不存在
|
|
|
- */
|
|
|
- private void handleRunningClinic(BusClinicEntity clinic,Boolean changed){
|
|
|
- //判断是否为当前最新手术信息
|
|
|
- PatientOperator<PatientCacheInfo> patientOperator = patientRegistry.getOperator(clinic.getTenantId(), clinic.getPatientCode());
|
|
|
- String clinicId = patientOperator.getClinicId();
|
|
|
- if(StrUtil.isNullOrUndefined(clinicId)){
|
|
|
- //临床数据尚未存在,则将该临床数据设置为最新的临床数据
|
|
|
- changedRunningClinic(clinic,patientOperator);
|
|
|
- Boolean finished = patientOperator.getFinished();
|
|
|
- if(Boolean.TRUE.equals(finished)){
|
|
|
- clinicService.update(new UpdateWrapper<BusClinicEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(BusClinicEntity::getId,clinic.getId())
|
|
|
- .set(BusClinicEntity::getFinished,true));
|
|
|
- }
|
|
|
- return ;
|
|
|
- }
|
|
|
- //判断临床信息是否一样
|
|
|
- if(clinicId.equals(clinic.getId())){
|
|
|
- if(Boolean.TRUE.equals(changed)){
|
|
|
- changedRunningClinic(clinic,patientOperator);
|
|
|
- return;
|
|
|
- }
|
|
|
- }else {
|
|
|
- //临床id不一致,找开始时间最晚的为当前的临床id
|
|
|
- Date startTime = patientOperator.getStartTime();
|
|
|
- if(startTime==null||clinic.getStartTime().after(startTime)){
|
|
|
- //更新临床信息
|
|
|
- changedRunningClinic(clinic,patientOperator);
|
|
|
- clinicService.update(new UpdateWrapper<BusClinicEntity>()
|
|
|
- .lambda()
|
|
|
- .ne(BusClinicEntity::getId,clinic.getId())
|
|
|
- .eq(BusClinicEntity::getPatientCode,clinic.getPatientCode())
|
|
|
- .eq(BusClinicEntity::getTenantId,clinic.getTenantId())
|
|
|
- .set(BusClinicEntity::getFinished,true));
|
|
|
- return;
|
|
|
- }else {
|
|
|
- //运行临床信息不发生变化,将该次临床置为结束状态, 进行撤泵操作 todo
|
|
|
- clinicService.update(new UpdateWrapper<BusClinicEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(BusClinicEntity::getId,clinic.getId())
|
|
|
- .set(BusClinicEntity::getFinished,true));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void changedRunningClinic(BusClinicEntity clinic,PatientOperator<PatientCacheInfo> patientOperator){
|
|
|
- String originClinic = patientOperator.getClinicId();
|
|
|
- if(!clinic.getId().equals(originClinic)){
|
|
|
- //找到该临床的最新输注数据并更新
|
|
|
- BusInfusionHistoryEntity infusion =
|
|
|
- infusionHistoryService.getOne(new QueryWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getClinicId, clinic.getId())
|
|
|
- .orderByAsc(BusInfusionHistoryEntity::getStartTime).last("limit 1"));
|
|
|
- if(infusion!=null){
|
|
|
- //临床信息发生变化
|
|
|
- if(Boolean.TRUE.equals(patientOperator.getFinished())){
|
|
|
- clinicService.update(new UpdateWrapper<BusClinicEntity>().lambda()
|
|
|
- .eq(BusClinicEntity::getId,clinic.getId())
|
|
|
- .set(BusClinicEntity::getFinished,false)
|
|
|
- );
|
|
|
- patientOperator.setFinished(false);
|
|
|
- }else {
|
|
|
- //重新计算病人该次临床的开始时间
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- patientOperator.setClinicId(clinic.getId());
|
|
|
- patientOperator.setWard(clinic.getWard());
|
|
|
- patientOperator.setBedNo(clinic.getBedNo());
|
|
|
- patientOperator.setStartTime(clinic.getStartTime());
|
|
|
- Set<DeviceTimeSmallInfo> allDevice = patientOperator.getAllDevice();
|
|
|
- if(CollectionUtil.isNotEmpty(allDevice)){
|
|
|
- //病人有相关的泵绑定
|
|
|
- List<String> deviceIds = allDevice.stream().map(DeviceTimeSmallInfo::getDeviceId).collect(Collectors.toList());
|
|
|
- deviceRunningService.updateClinicInfo(deviceIds,clinic);
|
|
|
- }
|
|
|
-
|
|
|
- log.error("临床信息发生改变:[{}],[{}]",clinic.getPatientCode(),clinic.toString());
|
|
|
- //todo 实时传输病人临床数据
|
|
|
|
|
|
}
|
|
|
}
|