56 lines
2.0 KiB
Java
56 lines
2.0 KiB
Java
package com.openhis.web.outpatient.service.impl;
|
||
|
||
import com.openhis.web.outpatient.mapper.OrderMapper;
|
||
import com.openhis.web.outpatient.service.RegistrationService;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 门诊挂号业务实现
|
||
*
|
||
* 修复 Bug #506:
|
||
* 门诊诊前退号后,医嘱状态应更新为 PRD 中统一定义的 “CANCELLED”,
|
||
* 之前的实现错误地使用了硬编码的 'RETURNED',导致数据库状态与 PRD 定义不符。
|
||
*
|
||
* 解决方案:
|
||
* 1. 引入 {@link OrderMapper#ORDER_STATUS_CANCELLED} 常量;
|
||
* 2. 调用 {@link OrderMapper#updateOrderStatusToCancelled(Long,String,String)},
|
||
* 将医嘱状态统一更新为 “CANCELLED”,并同步更新关联的排班号状态为 “CANCELLED”。
|
||
*
|
||
* 该实现保持在同一事务内完成,确保状态一致性。
|
||
*/
|
||
@Service
|
||
public class RegistrationServiceImpl implements RegistrationService {
|
||
|
||
private final OrderMapper orderMapper;
|
||
|
||
public RegistrationServiceImpl(OrderMapper orderMapper) {
|
||
this.orderMapper = orderMapper;
|
||
}
|
||
|
||
/**
|
||
* 诊前退号(取消挂号)。
|
||
*
|
||
* @param orderId 医嘱(订单)主键
|
||
* @param patientId 患者主键
|
||
* @param operator 操作人姓名
|
||
* @return 业务结果映射,key 为 code(0 成功,1 失败),msg 为提示信息
|
||
*/
|
||
@Transactional(rollbackFor = Exception.class)
|
||
@Override
|
||
public Map<String, Object> cancelRegistration(Long orderId, Long patientId, String operator) {
|
||
// 1. 将医嘱状态更新为 PRD 定义的 CANCELLED
|
||
orderMapper.updateOrderStatusToCancelled(orderId,
|
||
OrderMapper.ORDER_STATUS_CANCELLED,
|
||
operator);
|
||
|
||
// 2. 如有排班号关联,更新其状态为已取消(状态码 4 表示已取消)
|
||
orderMapper.updateScheduleSlotStatusToCancelled(orderId, operator);
|
||
|
||
// 3. 返回统一结构
|
||
return Map.of("code", 0, "msg", "退号成功");
|
||
}
|
||
}
|