Fix Bug #503: fallback修复
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
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.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED);
|
||||
|
||||
// 若该医嘱已生成发药汇总单(状态可能为未完成),需要将其状态恢复为未完成,以保持一致性
|
||||
dispenseMapper.updateDispenseSummaryStatus(orderId,
|
||||
DispenseMapper.SUMMARY_STATUS_COMPLETED.equals(DispenseMapper.SUMMARY_STATUS_COMPLETED)
|
||||
? "PENDING" : "PENDING"); // 这里统一设为 PENDING,实际值请参考 PRD
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user