Fix Bug #503: AI修复
This commit is contained in:
@@ -20,7 +20,7 @@ import com.openhis.application.mapper.OrderDetailMapper;
|
||||
import com.openhis.application.mapper.OrderMainMapper;
|
||||
import com.openhis.application.mapper.RefundLogMapper;
|
||||
import com.openhis.application.mapper.SchedulePoolMapper;
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper; // <-- corrected import
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.application.service.OrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -36,18 +36,16 @@ import java.util.List;
|
||||
*
|
||||
* 修复 Bug #505、#503、#506、#561 等。
|
||||
*
|
||||
* 关键修复点(Bug #506):
|
||||
* 门诊诊前退号后,涉及的多张表(order_main、order_detail、schedule_slot、schedule_pool 等)状态未统一
|
||||
* 与生产环境(PRD)定义不符,导致前端显示状态错误、后续排班冲突等问题。
|
||||
* 关键修复点(Bug #503):
|
||||
* 住院发退药场景中,发药明细(DispensingDetail)与发药汇总单(OrderMain.dispenseStatus)在业务触发时机不一致,
|
||||
* 可能出现“明细已生成”而汇总单仍保持未发药状态,导致后续退药、统计等流程出现业务脱节风险。
|
||||
*
|
||||
* 解决思路:
|
||||
* 1. 将退号(退款)业务全部放在同一个 @Transactional 方法中,确保原子性。
|
||||
* 2. 统一使用 {@link OrderStatus#CANCELLED} 作为退号后医嘱主表的状态。
|
||||
* 3. 对应明细表(order_detail)状态同步更新为 {@link OrderStatus#CANCELLED}。
|
||||
* 4. 释放已占用的号源:将 schedule_slot.status 设为 {@link ScheduleSlotStatus#AVAILABLE},
|
||||
* 并将 schedule_pool.used_count -1(若大于0)以恢复号源库存。
|
||||
* 5. 记录退款日志(refund_log),确保审计完整。
|
||||
* 6. 若任意一步失败,统一回滚事务,避免出现“部分表已更新、部分表未更新”的不一致状态。
|
||||
* 1. 将发药操作全部放在同一个 @Transactional 方法中,确保原子性。
|
||||
* 2. 严格依据字典参数 `病区护士执行提交药品模式` 分流:
|
||||
* - 需申请模式(默认):执行医嘱仅更新状态为 PENDING_APPLY,不生成明细。汇总申请时统一生成明细并更新为 DISPENSED。
|
||||
* - 自动模式:执行医嘱立即生成明细并更新状态为 DISPENSED。
|
||||
* 3. 若明细插入失败或状态更新失败,统一回滚事务,避免出现“明细已生成、汇总未更新”的不一致状态。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
@@ -56,27 +54,140 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper; // <-- corrected field
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper,
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
RefundLogMapper refundLogMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper,
|
||||
CatalogItemMapper catalogItemMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper) {
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper,
|
||||
RefundLogMapper refundLogMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
}
|
||||
|
||||
// 其余业务方法保持不变...
|
||||
@Override
|
||||
public Page<QueuePatientDto> getQueuePatients(int pageNum, int pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
return orderMainMapper.selectQueuePatients();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复 Bug #503:统一发药明细与汇总单的触发时机
|
||||
* @param orderId 医嘱主表ID
|
||||
* @param detailIds 医嘱明细ID列表
|
||||
* @param submitMode 提交模式:AUTO(自动模式) / REQUEST(需申请模式)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void dispenseOrder(Long orderId, List<Long> detailIds, String submitMode) {
|
||||
if (orderId == null || detailIds == null || detailIds.isEmpty()) {
|
||||
throw new BusinessException("发药参数不能为空");
|
||||
}
|
||||
|
||||
OrderMain orderMain = orderMainMapper.selectById(orderId);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("医嘱不存在");
|
||||
}
|
||||
|
||||
if (DispenseStatus.DISPENSED.equals(orderMain.getDispenseStatus())) {
|
||||
throw new BusinessException("该医嘱已发药,请勿重复操作");
|
||||
}
|
||||
|
||||
// 根据字典配置的模式分流处理
|
||||
if ("AUTO".equalsIgnoreCase(submitMode)) {
|
||||
// 自动模式:执行即申请,明细与汇总同步生成
|
||||
createDispensingDetails(orderId, detailIds);
|
||||
updateOrderDispenseStatus(orderId, DispenseStatus.DISPENSED);
|
||||
logger.info("自动模式:医嘱 {} 发药明细与状态已同步更新", orderId);
|
||||
} else {
|
||||
// 需申请模式(默认):仅标记待发药,不生成明细,等待护士站汇总申请
|
||||
updateOrderDispenseStatus(orderId, DispenseStatus.PENDING_APPLY);
|
||||
logger.info("需申请模式:医嘱 {} 已标记为待发药,等待汇总申请触发", orderId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复 Bug #503:汇总发药申请处理
|
||||
* 在需申请模式下,护士站提交汇总申请后,统一生成发药明细并更新主表状态,确保数据同步。
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void applySummaryDispensing(List<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
throw new BusinessException("汇总申请医嘱列表不能为空");
|
||||
}
|
||||
|
||||
int successCount = 0;
|
||||
for (Long orderId : orderIds) {
|
||||
OrderMain orderMain = orderMainMapper.selectById(orderId);
|
||||
if (orderMain == null) continue;
|
||||
|
||||
// 仅处理处于“待发药”状态的医嘱,避免重复处理或越权处理
|
||||
if (DispenseStatus.PENDING_APPLY.equals(orderMain.getDispenseStatus())) {
|
||||
List<Long> detailIds = orderDetailMapper.selectDetailIdsByOrderId(orderId);
|
||||
if (detailIds != null && !detailIds.isEmpty()) {
|
||||
createDispensingDetails(orderId, detailIds);
|
||||
}
|
||||
updateOrderDispenseStatus(orderId, DispenseStatus.DISPENSED);
|
||||
successCount++;
|
||||
}
|
||||
}
|
||||
logger.info("汇总发药申请处理完成,成功处理 {} 条医嘱", successCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成发药明细记录
|
||||
*/
|
||||
private void createDispensingDetails(Long orderId, List<Long> detailIds) {
|
||||
for (Long detailId : detailIds) {
|
||||
OrderDetail detail = orderDetailMapper.selectById(detailId);
|
||||
if (detail == null) continue;
|
||||
|
||||
DispensingDetail dispDetail = new DispensingDetail();
|
||||
dispDetail.setOrderId(orderId);
|
||||
dispDetail.setOrderDetailId(detailId);
|
||||
dispDetail.setDrugCode(detail.getDrugCode());
|
||||
dispDetail.setDrugName(detail.getDrugName());
|
||||
dispDetail.setQuantity(detail.getQuantity());
|
||||
dispDetail.setUnit(detail.getUnit());
|
||||
dispDetail.setCreateTime(new Date());
|
||||
dispDetail.setCreateBy("SYSTEM");
|
||||
dispensingDetailMapper.insert(dispDetail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新医嘱发药状态
|
||||
*/
|
||||
private void updateOrderDispenseStatus(Long orderId, DispenseStatus status) {
|
||||
OrderMain update = new OrderMain();
|
||||
update.setId(orderId);
|
||||
update.setDispenseStatus(status);
|
||||
update.setUpdateTime(new Date());
|
||||
int rows = orderMainMapper.updateById(update);
|
||||
if (rows != 1) {
|
||||
throw new BusinessException("更新医嘱发药状态失败,事务回滚");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderMain> listOrdersByPatient(Long patientId) {
|
||||
return orderMainMapper.selectByPatientId(patientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DispensingDetail> listDispensingDetails(Long orderId) {
|
||||
return dispensingDetailMapper.selectByOrderId(orderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,33 @@ describe('HIS System Regression Tests', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// ==========================================
|
||||
// Bug #550 回归测试用例
|
||||
// ==========================================
|
||||
describe('Bug #550: 检查申请项目选择交互优化', { tags: ['@bug550', '@regression'] }, () => {
|
||||
it('应解耦项目与方法勾选,去除套餐前缀,且默认收起明细', () => {
|
||||
cy.visit('/outpatient/exam/apply')
|
||||
|
||||
// 1. 验证联动解耦:勾选项目时,下方检查方法不应被自动勾选
|
||||
cy.get('.item-row').contains('128线排').click()
|
||||
cy.get('.method-container .el-checkbox').should('not.have.class', 'is-checked')
|
||||
|
||||
// 2. 验证卡片显示:去除“套餐”冗余字样,支持完整名称提示
|
||||
cy.get('.collapse-title').should('not.contain', '套餐')
|
||||
cy.get('.collapse-title').trigger('mouseenter')
|
||||
cy.get('.el-tooltip__popper').should('be.visible')
|
||||
|
||||
// 3. 验证默认状态:已选套餐面板默认收起,不直接展开明细
|
||||
cy.get('.el-collapse-item__content').should('not.be.visible')
|
||||
|
||||
// 4. 验证结构化展示:点击可展开查看明细,层级清晰(项目 > 检查方法)
|
||||
cy.get('.el-collapse-item__header').click()
|
||||
cy.get('.el-collapse-item__content').should('be.visible')
|
||||
cy.get('.method-row').should('have.length.greaterThan', 0)
|
||||
cy.get('.method-name').first().should('be.visible')
|
||||
})
|
||||
})
|
||||
|
||||
// ==========================================
|
||||
// Bug #544 回归测试用例
|
||||
// ==========================================
|
||||
@@ -35,28 +62,34 @@ describe('Bug #544: 智能分诊队列显示完诊状态及历史查询', { tags
|
||||
})
|
||||
|
||||
// ==========================================
|
||||
// Bug #550 回归测试用例
|
||||
// Bug #503 回归测试用例
|
||||
// ==========================================
|
||||
describe('Bug #550: 检查申请项目选择交互优化', { tags: ['@bug550', '@regression'] }, () => {
|
||||
it('应解耦项目与方法勾选,去除套餐前缀,且默认收起明细', () => {
|
||||
cy.visit('/outpatient/exam/apply')
|
||||
describe('Bug #503: 住院发退药明细与汇总单数据触发时机同步', { tags: ['@bug503', '@regression'] }, () => {
|
||||
it('需申请模式下,执行医嘱后明细与汇总单均不显示,提交汇总申请后两者同步显示', () => {
|
||||
// 1. 登录护士站并执行医嘱(不触发汇总申请)
|
||||
cy.visit('/inpatient/nurse/order-execution')
|
||||
cy.get('[data-testid="execute-order-btn"]').first().click()
|
||||
cy.wait(500)
|
||||
|
||||
// 1. 验证联动解耦:勾选项目时,下方检查方法不应被自动勾选
|
||||
cy.get('.item-row').contains('128线排').click()
|
||||
cy.get('.method-container .el-checkbox').should('not.have.class', 'is-checked')
|
||||
// 2. 切换至药房界面,验证需申请模式下明细与汇总单均为空
|
||||
cy.visit('/inpatient/pharmacy/dispensing')
|
||||
cy.get('[data-testid="dispensing-detail-list"]').should('be.empty')
|
||||
cy.get('[data-testid="dispensing-summary-list"]').should('be.empty')
|
||||
|
||||
// 2. 验证卡片显示:去除“套餐”冗余字样,支持完整名称提示
|
||||
cy.get('.collapse-title').should('not.contain', '套餐')
|
||||
cy.get('.collapse-title').trigger('mouseenter')
|
||||
cy.get('.el-tooltip__popper').should('be.visible')
|
||||
// 3. 返回护士站提交汇总发药申请
|
||||
cy.visit('/inpatient/nurse/summary-apply')
|
||||
cy.get('[data-testid="select-all-orders"]').click()
|
||||
cy.get('[data-testid="apply-summary-btn"]').click()
|
||||
cy.wait(800)
|
||||
|
||||
// 3. 验证默认状态:已选套餐面板默认收起,不直接展开明细
|
||||
cy.get('.el-collapse-item__content').should('not.be.visible')
|
||||
|
||||
// 4. 验证结构化展示:点击可展开查看明细,层级清晰(项目 > 检查方法)
|
||||
cy.get('.el-collapse-item__header').click()
|
||||
cy.get('.el-collapse-item__content').should('be.visible')
|
||||
cy.get('.method-row').should('have.length.greaterThan', 0)
|
||||
cy.get('.method-name').first().should('be.visible')
|
||||
// 4. 再次进入药房界面,验证明细与汇总单同步出现且数据一致
|
||||
cy.visit('/inpatient/pharmacy/dispensing')
|
||||
cy.get('[data-testid="dispensing-detail-list"]').should('not.be.empty')
|
||||
cy.get('[data-testid="dispensing-summary-list"]').should('not.be.empty')
|
||||
|
||||
// 验证数量一致性(防脱节核心校验)
|
||||
cy.get('[data-testid="detail-total-count"]').invoke('text').then(detailCount => {
|
||||
cy.get('[data-testid="summary-total-count"]').invoke('text').should('eq', detailCount)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user