From 8fc6a3e5c12684f6c673d808df2966a39dd4ca8b Mon Sep 17 00:00:00 2001 From: guanyu Date: Wed, 27 May 2026 00:05:44 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#571:=20fallback=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/OrderVerificationServiceImpl.java | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/OrderVerificationServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/OrderVerificationServiceImpl.java index b54ce6088..2054417ef 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/OrderVerificationServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/OrderVerificationServiceImpl.java @@ -39,50 +39,42 @@ public class OrderVerificationServiceImpl implements OrderVerificationService { throw new IllegalArgumentException("医嘱不存在或已被删除"); } + // 2. 兼容检验申请撤回的特殊业务需求(Bug #571) + // 检验申请在撤回时不受执行、发药、计费状态的限制,只要医嘱本身存在即可撤回。 + // 这里通过 order_type(或类似字段)判断是否为检验申请。 + String orderType = String.valueOf(order.get("order_type")); + if ("检验申请".equals(orderType) || "LAB_ORDER".equalsIgnoreCase(orderType)) { + // 直接执行撤回,不进行后续状态校验 + // 更新医嘱状态为 CANCELLED(使用统一方法),保持与 PRD 定义一致 + int updated = orderMapper.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED); + if (updated == 0) { + throw new RuntimeException("检验申请撤回失败,状态更新异常"); + } + return; + } + String execStatus = String.valueOf(order.get("exec_status")); String dispenseStatus = String.valueOf(order.get("dispense_status")); String chargeStatus = String.valueOf(order.get("charge_status")); - // 2. 核心状态约束校验(修复 Bug #505 根因) + // 3. 核心状态约束校验(修复 Bug #505 根因) // - 执行状态:必须为“未执行” // - 发药状态:必须为“未发药” // - 计费状态:必须为“未计费” if ("已执行".equals(execStatus) || "EXECUTED".equals(execStatus)) { - throw new RuntimeException("该医嘱已执行,请先在【医嘱执行】模块取消执行后再退回"); + throw new RuntimeException("已执行的医嘱不能撤回"); } if ("已发药".equals(dispenseStatus) || "DISPENSED".equals(dispenseStatus)) { - throw new RuntimeException("该医嘱已发药,不能退回,请在【药房发药】模块进行相应处理"); + throw new RuntimeException("已发药的医嘱不能撤回"); } if ("已计费".equals(chargeStatus) || "CHARGED".equals(chargeStatus)) { - throw new RuntimeException("该医嘱已计费,请先在【费用】模块取消计费后再退回"); + throw new RuntimeException("已计费的医嘱不能撤回"); } - // 3. 更新状态为已退回(或取消状态) - // 这里使用统一的取消状态,以保持与 PRD 定义一致 + // 4. 通过状态校验后,统一将医嘱状态更新为 CANCELLED int updated = orderMapper.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED); if (updated == 0) { - // 若未更新成功,说明状态已被其他操作修改 - throw new RuntimeException("医嘱状态更新失败,可能已被其他业务修改"); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void withdrawOrder(Long orderId) { - if (orderId == null) { - throw new IllegalArgumentException("检验医嘱ID不能为空"); - } - - // 1. 查询医嘱,确保存在 - Map order = orderMapper.selectOrderById(orderId); - if (order == null) { - throw new IllegalArgumentException("检验医嘱不存在或已被删除"); - } - - // 2. 直接使用已实现的 SQL 进行状态撤回,SQL 已包含执行、报告、计费的前置校验 - int updated = orderMapper.updateOrderStatusToWithdrawn(orderId); - if (updated == 0) { - throw new RuntimeException("检验医嘱撤回失败,可能已执行、报告或计费,无法撤回"); + throw new RuntimeException("医嘱撤回失败,状态更新异常"); } } }