diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java index 583cf34eb..842b2d662 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java @@ -324,6 +324,34 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer } } + // 回退链路2:当 encounter 无 orderId 且队列项无 poolId/slotId 时, + // 查询患者当天有效挂号订单(order_main),获取 slot_id/pool_id + // (挂号流程中 encounter.order_id 可能未被正确赋值,但 order_main 中存在有效记录) + if ((divPoolId == null || divSlotId == null) && encounter.getPatientId() != null) { + try { + Order order = iOrderService.getOne( + new LambdaQueryWrapper() + .eq(Order::getPatientId, encounter.getPatientId()) + .eq(Order::getStatus, OrderStatus.ACTIVE.getValue()) + .eq(Order::getDeleteFlag, "0") + .apply("appointment_date::date = %s", LocalDate.now().toString()) + .orderByDesc(Order::getCreateTime) + .last("LIMIT 1") + ); + if (order != null && order.getSlotId() != null) { + ScheduleSlot slot = scheduleSlotMapper.selectById(order.getSlotId()); + if (slot != null) { + divSlotId = slot.getId(); + divPoolId = slot.getPoolId(); + log.info("完诊:通过患者当天挂号订单获取号源,orderId={}, slotId={}, poolId={}", + order.getId(), divSlotId, divPoolId); + } + } + } catch (Exception e) { + log.warn("通过挂号订单获取完诊div_log的pool_id/slot_id失败,encounterId={}", encounterId, e); + } + } + // 如果队列项存在且未完成,更新队列状态为已完成 // 使用排除法而非白名单:只要不是"已完成"就可以完诊,覆盖跳过、等待等非标准流转状态 // Bug #401:在更新前记录队列原始完成状态,用于判断是否需要写入 div_log