Fix Bug #505: AI修复
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package com.openhis.application.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.openhis.application.domain.entity.OrderDetail;
|
||||
import com.openhis.application.domain.entity.OrderMain;
|
||||
import com.openhis.application.domain.entity.CatalogItem;
|
||||
import com.openhis.application.domain.entity.ScheduleSlot;
|
||||
import com.openhis.application.mapper.OrderDetailMapper;
|
||||
import com.openhis.application.mapper.OrderMainMapper;
|
||||
import com.openhis.application.mapper.CatalogItemMapper;
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.application.exception.BusinessException;
|
||||
import com.openhis.application.service.OrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 医嘱业务实现
|
||||
*
|
||||
* 修复 Bug #561、#574、#503 同时加入分页优化,解决
|
||||
* “门诊医生工作站‑待写病历”页面加载时间过长的问题。
|
||||
* 修复 Bug #505:增加医嘱退回前置状态校验,阻断已发药/已执行医嘱的直接退回。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
CatalogItemMapper catalogItemMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 其它业务方法(省略)...
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查询待写病历的医嘱列表(分页)。
|
||||
*
|
||||
* @param patientId 患者主键
|
||||
* @param pageNum 页码(1 开始),若为 null 使用默认值 1
|
||||
* @param pageSize 每页记录数,若为 null 使用默认值 20
|
||||
* @return 分页后的 OrderMain 列表
|
||||
*/
|
||||
@Override
|
||||
public List<OrderMain> listPendingOrders(Long patientId, Integer pageNum, Integer pageSize) {
|
||||
pageNum = pageNum == null ? 1 : pageNum;
|
||||
pageSize = pageSize == null ? 20 : pageSize;
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
return orderMainMapper.selectPendingOrders(patientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrder(OrderMain orderMain, List<OrderDetail> details) {
|
||||
orderMainMapper.insert(orderMain);
|
||||
if (details != null && !details.isEmpty()) {
|
||||
for (OrderDetail detail : details) {
|
||||
detail.setOrderId(orderMain.getId());
|
||||
orderDetailMapper.insert(detail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 医嘱退回操作
|
||||
* 修复 Bug #505:增加发药状态与执行状态前置校验
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void returnOrder(Long orderId) {
|
||||
OrderMain order = orderMainMapper.selectById(orderId);
|
||||
if (order == null) {
|
||||
throw new BusinessException("医嘱不存在");
|
||||
}
|
||||
|
||||
// 核心状态约束校验:执行状态必须为“未执行”,物理状态必须为“未发药/未领药”
|
||||
// 注:实际字段名/字典值请根据 hisdev 数据库 order_main 表结构对齐,此处采用通用拦截逻辑
|
||||
String executeStatus = order.getExecuteStatus();
|
||||
String dispenseStatus = order.getDispenseStatus();
|
||||
|
||||
boolean isExecuted = "已执行".equals(executeStatus) || "EXECUTED".equals(executeStatus) || "1".equals(executeStatus);
|
||||
boolean isDispensed = "已发药".equals(dispenseStatus) || "已发放".equals(dispenseStatus) || "DISPENSED".equals(dispenseStatus) || "1".equals(dispenseStatus);
|
||||
|
||||
if (isDispensed || isExecuted) {
|
||||
throw new BusinessException("该药品已由药房发放,请先执行退药处理,不可直接退回");
|
||||
}
|
||||
|
||||
// 原有退回逻辑:状态流转至“已退回”
|
||||
order.setStatus("已退回");
|
||||
orderMainMapper.updateById(order);
|
||||
log.info("医嘱退回成功, orderId: {}", orderId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user