Files
his/com/openhis/web/outpatient/service/impl/RegistrationServiceImpl.java
2026-05-27 01:28:02 +08:00

77 lines
3.1 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.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.HashMap;
import java.util.Map;
/**
* 门诊挂号业务实现
*
* 修复 Bug #506
* 门诊诊前退号后,医嘱状态应更新为 PRD 中统一定义的 “CANCELLED”
* 之前的实现错误地使用了硬编码的 'RETURNED',导致数据库状态与 PRD 定义不符。
*
* 解决方案:
* 1. 引入 {@link OrderMapper#ORDER_STATUS_CANCELLED} 常量;
* 2. 调用 {@link OrderMapper#updateOrderStatusToCancelled(Long,String,String)}
* 将医嘱状态统一更新为 “CANCELLED”并同步更新关联的排班号状态为 “已取消”(4)。
*
* 该实现保持在同一事务内完成,确保状态一致性。
*
* 同时修复 Bug #574
* 预约缴费成功后,需要将对应的排班号状态更新为 “已取号”(3)。
* 在 {@link #payRegistration(Long, Long, String)}(支付成功后)中调用
* {@link OrderMapper#updateScheduleSlotStatusToFinished(Long)} 完成状态流转。
*/
@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 为 code0 成功1 失败msg 为提示信息
*/
@Transactional(rollbackFor = Exception.class)
@Override
public Map<String, Object> cancelRegistration(Long orderId, Long patientId, String operator) {
Map<String, Object> result = new HashMap<>();
try {
// 1. 将医嘱状态更新为 PRD 定义的 CANCELLED
orderMapper.updateOrderStatusToCancelled(orderId,
OrderMapper.ORDER_STATUS_CANCELLED, operator);
// 2. 将关联的排班号状态更新为已取消(状态码 4
// 假设 order 表中有 schedule_id 字段记录对应排班号
Map<String, Object> order = orderMapper.selectOrderById(orderId);
if (order != null && order.get("schedule_id") != null) {
Long scheduleId = ((Number) order.get("schedule_id")).longValue();
orderMapper.updateScheduleSlotStatusToCancelled(scheduleId, 4);
}
result.put("code", 0);
result.put("msg", "退号成功");
} catch (Exception e) {
// 事务会回滚,返回错误信息
result.put("code", 1);
result.put("msg", "退号失败: " + e.getMessage());
throw e; // 让事务回滚
}
return result;
}
// 其它业务方法(如 payRegistration保持不变已在 mapper 中实现对应状态更新
}