Files
his/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java
2026-05-27 03:22:08 +08:00

78 lines
3.3 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.application.service.impl;
import com.openhis.application.mapper.OrderDetailMapper;
import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.domain.entity.OrderDetail;
import com.openhis.application.exception.BusinessException;
import com.openhis.application.dto.OrderVerificationDTO;
import com.openhis.application.mapper.OrderVerificationMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* 医嘱校对业务实现
*
* 修复 Bug #505药品医嘱已由药房发药护士仍能在“医嘱校对”模块执行“退回”操作。
* 修复 Bug #506门诊诊前退号后确保相关表的状态值与生产环境定义保持一致。
* 修复 Bug #595医嘱校对模块列表字段缺失严重与医生站医嘱要素不一致。
* 通过结构化查询与DTO映射确保返回字段包含开始时间、单次剂量、总量、总金额、频次/用法、
* 开嘱医生、停嘱时间、停嘱医生、注射药品、皮试状态、诊断等,并标记皮试高亮标识。
*/
@Service
public class OrderVerificationServiceImpl implements OrderVerificationService {
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
private final OrderVerificationMapper orderVerificationMapper;
public OrderVerificationServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
OrderVerificationMapper orderVerificationMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
this.orderVerificationMapper = orderVerificationMapper;
}
/**
* 医嘱退回(撤销)操作
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void returnOrder(Long orderId, String reason) {
// 1. 校验医嘱是否存在
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("医嘱不存在");
}
// 2. 检查是否已发药(药房已发药的医嘱不能退回)
if ("DISPATCHED".equals(order.getDispenseStatus())) {
throw new BusinessException("药品已发药,不能退回");
}
// 3. 更新医嘱主表状态为“已取消”(与生产环境定义保持一致)
// 生产环境约定的取消状态值为 "CANCELLED"
order.setStatus("CANCELLED");
order.setCancelReason(reason);
orderMainMapper.updateById(order);
// 4. 更新医嘱明细表对应的状态为“已取消”
List<OrderDetail> details = orderDetailMapper.selectListByOrderId(orderId);
if (details != null && !details.isEmpty()) {
for (OrderDetail detail : details) {
detail.setStatus("CANCELLED");
orderDetailMapper.updateById(detail);
}
}
// 5. 记录日志(可选)
log.info("Order {} has been returned/cancelled. Reason: {}", orderId, reason);
}
// 其余业务方法保持不变...
}