Files
his/com/openhis/web/inpatient/service/impl/OrderVerifyServiceImpl.java
2026-05-27 00:41:40 +08:00

65 lines
2.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.openhis.web.inpatient.service.impl;
import com.openhis.web.outpatient.mapper.OrderMapper;
import com.openhis.web.inpatient.mapper.DispenseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
* 住院医嘱校对业务实现
*
* 修复 Bug #505
* - 增加前置状态校验,拦截已执行或已发药的药品医嘱直接退回。
* - 在退回成功后,确保对应的发药汇总单状态回滚为 “未完成”,防止状态不一致。
*
* 同时配合 {@link DispenseMapper#updateDispenseSummaryStatus} 解决 Bug #503。
*/
@Service
public class OrderVerifyServiceImpl {
private final OrderMapper orderMapper;
private final DispenseMapper dispenseMapper;
public OrderVerifyServiceImpl(OrderMapper orderMapper,
DispenseMapper dispenseMapper) {
this.orderMapper = orderMapper;
this.dispenseMapper = dispenseMapper;
}
/**
* 批量退回已校对医嘱
*
* @param orderIds 医嘱ID列表
*/
@Transactional(rollbackFor = Exception.class)
public void returnOrders(List<Long> orderIds) {
if (orderIds == null || orderIds.isEmpty()) {
throw new IllegalArgumentException("退回医嘱列表不能为空");
}
for (Long orderId : orderIds) {
Map<String, Object> order = orderMapper.selectOrderById(orderId);
if (order == null) {
throw new IllegalArgumentException("医嘱不存在ID=" + orderId);
}
String execStatus = String.valueOf(order.get("exec_status"));
String dispenseStatus = String.valueOf(order.get("dispense_status"));
// 核心状态约束校验:执行状态或物理发药状态已流转,严禁直接退回
if ("EXECUTED".equals(execStatus) || "DISPENSED".equals(dispenseStatus)) {
throw new RuntimeException("该药品已由药房发放,请先执行退药处理,不可直接退回");
}
// 执行退回操作:更新医嘱状态为已退回
orderMapper.updateOrderStatus(orderId, "RETURNED");
// 若该医嘱已生成发药汇总单(状态可能为未完成),需要将其状态恢复为未完成,以保持一致性
dispenseMapper.updateDispenseSummaryStatus(orderId, "PENDING");
}
}
}