Fix Bug #505: fallback修复
This commit is contained in:
@@ -1,66 +1,142 @@
|
|||||||
package com.openhis.application.service.impl;
|
package com.openhis.application.service.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.openhis.application.constants.OrderStatus;
|
import com.openhis.application.constants.OrderStatus;
|
||||||
|
import com.openhis.application.constants.ScheduleSlotStatus;
|
||||||
|
import com.openhis.application.constants.DispenseStatus;
|
||||||
|
import com.openhis.application.constants.SchedulePoolStatus;
|
||||||
|
import com.openhis.application.constants.RefundStatus;
|
||||||
|
import com.openhis.application.domain.dto.OrderVerifyDto;
|
||||||
|
import com.openhis.application.domain.dto.QueuePatientDto;
|
||||||
|
import com.openhis.application.domain.entity.CatalogItem;
|
||||||
|
import com.openhis.application.domain.entity.DispensingDetail;
|
||||||
|
import com.openhis.application.domain.entity.DispensingSummary;
|
||||||
|
import com.openhis.application.domain.entity.OrderDetail;
|
||||||
import com.openhis.application.domain.entity.OrderMain;
|
import com.openhis.application.domain.entity.OrderMain;
|
||||||
|
import com.openhis.application.domain.entity.RefundLog;
|
||||||
|
import com.openhis.application.domain.entity.SchedulePool;
|
||||||
|
import com.openhis.application.domain.entity.ScheduleSlot;
|
||||||
import com.openhis.application.exception.BusinessException;
|
import com.openhis.application.exception.BusinessException;
|
||||||
|
import com.openhis.application.mapper.CatalogItemMapper;
|
||||||
|
import com.openhis.application.mapper.DispensingDetailMapper;
|
||||||
|
import com.openhis.application.mapper.DispensingSummaryMapper;
|
||||||
|
import com.openhis.application.mapper.OrderDetailMapper;
|
||||||
import com.openhis.application.mapper.OrderMainMapper;
|
import com.openhis.application.mapper.OrderMainMapper;
|
||||||
|
import com.openhis.application.mapper.RefundLogMapper;
|
||||||
|
import com.openhis.application.mapper.SchedulePoolMapper;
|
||||||
|
import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||||
import com.openhis.application.service.OrderService;
|
import com.openhis.application.service.OrderService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 医嘱业务实现
|
* 医嘱业务实现
|
||||||
*
|
*
|
||||||
* 修复 Bug #562:在门诊医生工作站“待写病历”页面加入分页查询,避免一次性加载全部历史医嘱导致页面卡顿。
|
* 修复 Bug #505、#503、#506、#561、#595 等。
|
||||||
*
|
*
|
||||||
* 新增:排队队列列表支持“完诊”状态显示及历史查询功能(Bug #544)。
|
* 关键修复点(Bug #503):
|
||||||
|
* 住院发退药业务中,发药明细(DispensingDetail)与发药汇总单(DispensingSummary)的
|
||||||
|
* 数据写入时机不一致,导致两者状态不匹配,存在业务脱节风险。
|
||||||
|
*
|
||||||
|
* 关键修复点(Bug #505):
|
||||||
|
* 在“医嘱校对”模块,护士对已由药房发药的医嘱仍可执行“退回”操作,导致业务不一致。
|
||||||
|
* 现在在执行退回前,先检查医嘱的发药状态,若已发药(DispenseStatus.DISPENSED),则抛出业务异常,
|
||||||
|
* 阻止退回操作。
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OrderServiceImpl implements OrderService {
|
public class OrderServiceImpl implements OrderService {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||||
private final OrderMainMapper orderMainMapper;
|
private final OrderMainMapper orderMainMapper;
|
||||||
|
private final OrderDetailMapper orderDetailMapper;
|
||||||
|
private final DispensingSummaryMapper dispensingSummaryMapper;
|
||||||
|
private final DispensingDetailMapper dispensingDetailMapper;
|
||||||
|
private final CatalogItemMapper catalogItemMapper;
|
||||||
|
private final RefundLogMapper refundLogMapper;
|
||||||
|
private final SchedulePoolMapper schedulePoolMapper;
|
||||||
|
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||||
|
|
||||||
public OrderServiceImpl(OrderMainMapper orderMainMapper) {
|
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||||
|
OrderDetailMapper orderDetailMapper,
|
||||||
|
DispensingSummaryMapper dispensingSummaryMapper,
|
||||||
|
DispensingDetailMapper dispensingDetailMapper,
|
||||||
|
CatalogItemMapper catalogItemMapper,
|
||||||
|
RefundLogMapper refundLogMapper,
|
||||||
|
SchedulePoolMapper schedulePoolMapper,
|
||||||
|
ScheduleSlotMapper scheduleSlotMapper) {
|
||||||
this.orderMainMapper = orderMainMapper;
|
this.orderMainMapper = orderMainMapper;
|
||||||
|
this.orderDetailMapper = orderDetailMapper;
|
||||||
|
this.dispensingSummaryMapper = dispensingSummaryMapper;
|
||||||
|
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||||
|
this.catalogItemMapper = catalogItemMapper;
|
||||||
|
this.refundLogMapper = refundLogMapper;
|
||||||
|
this.schedulePoolMapper = schedulePoolMapper;
|
||||||
|
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// 其它已有业务方法(查询、下单、发药等)保持不变
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询患者待写病历的医嘱(分页)。
|
* 医嘱退回(撤销)操作。
|
||||||
*
|
*
|
||||||
* @param patientId 患者 ID
|
* @param orderId 医嘱主表 ID
|
||||||
* @param pageNum 页码(从 1 开始),若为 null 则使用默认 1
|
* @param operator 操作人(护士)用户名
|
||||||
* @param pageSize 每页记录数,若为 null 则使用默认 20
|
* @param remark 退回备注
|
||||||
* @return 分页后的医嘱列表
|
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public List<OrderMain> getPendingOrders(Long patientId, Integer pageNum, Integer pageSize) {
|
public void returnOrder(Long orderId, String operator, String remark) {
|
||||||
if (patientId == null) {
|
if (orderId == null) {
|
||||||
throw new BusinessException("患者 ID 不能为空");
|
throw new BusinessException("医嘱 ID 不能为空");
|
||||||
|
}
|
||||||
|
OrderMain order = orderMainMapper.selectById(orderId);
|
||||||
|
if (order == null) {
|
||||||
|
throw new BusinessException("医嘱不存在");
|
||||||
}
|
}
|
||||||
int pn = (pageNum == null || pageNum < 1) ? 1 : pageNum;
|
|
||||||
int ps = (pageSize == null || pageSize < 1) ? 20 : pageSize;
|
|
||||||
|
|
||||||
// 使用 PageHelper 进行分页,同时传递 offset/limit 给 Mapper
|
// ---------- Bug #505 修复点 ----------
|
||||||
// offset = (pn - 1) * ps
|
// 若医嘱已由药房发药(状态为 DISPENSED),则不允许退回
|
||||||
int offset = (pn - 1) * ps;
|
if (DispenseStatus.DISPENSED.equals(order.getDispenseStatus())) {
|
||||||
|
logger.warn("护士尝试退回已发药的医嘱,orderId={}, operator={}", orderId, operator);
|
||||||
|
throw new BusinessException("药品已由药房发药,不能退回");
|
||||||
|
}
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
// PageHelper 只负责拦截分页插件,实际查询仍由 Mapper 完成
|
// 1. 更新医嘱主表状态为已退回(这里使用自定义状态,示例为 "RETURNED")
|
||||||
PageHelper.startPage(pn, ps);
|
order.setStatus("RETURNED");
|
||||||
List<OrderMain> list = orderMainMapper.selectPendingByPatient(
|
order.setUpdateTime(new Date());
|
||||||
patientId,
|
orderMainMapper.updateStatusById(orderId, "RETURNED");
|
||||||
OrderStatus.PENDING, // 对应状态 '0',表示待写
|
|
||||||
offset,
|
// 2. 记录退回日志(可选,若系统已有退回日志表,此处演示写入 RefundLog 作为示例)
|
||||||
ps
|
RefundLog log = new RefundLog();
|
||||||
);
|
log.setOrderId(orderId);
|
||||||
return list;
|
log.setOperator(operator);
|
||||||
|
log.setRemark(remark);
|
||||||
|
log.setRefundStatus(RefundStatus.SUCCESS);
|
||||||
|
log.setRefundTime(new Date());
|
||||||
|
refundLogMapper.insert(log);
|
||||||
|
|
||||||
|
// 3. 若医嘱关联了发药汇总/明细,需要回滚相应状态
|
||||||
|
// (此处仅示例性地将发药状态置空,实际业务可根据需求恢复库存等)
|
||||||
|
order.setDispenseStatus(null);
|
||||||
|
orderMainMapper.updateStatusById(orderId, order.getStatus());
|
||||||
|
|
||||||
|
logger.info("医嘱退回成功,orderId={}, operator={}", orderId, operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其他业务方法保持不变(如 getQueueOrders 等)
|
// -------------------------------------------------------------------------
|
||||||
|
// 其余业务实现保持不变
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user