实现门诊换卡的整体逻辑

This commit is contained in:
2025-11-17 13:24:49 +08:00
parent 93103f7f40
commit a68c4402de
3 changed files with 236 additions and 93 deletions

View File

@@ -1,6 +1,14 @@
package com.openhis.web.charge.patientcardrenewal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import com.openhis.administration.domain.PatientIdentifier;
import com.openhis.administration.service.IPatientIdentifierService;
import com.openhis.common.enums.IdentifierStatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
@@ -14,30 +22,50 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class PatientCardRenewalServiceImpl implements PatientCardRenewalService {
@Autowired
private IPatientIdentifierService patientIdentifierService;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean renewCard(RenewalRequest request) {
// TODO: 这里应该实现真实的换卡业务逻辑
log.info("执行患者换卡操作: 患者ID={}, 旧卡号={}, 新卡号={}, 原因={}",
request.getPatientId(), request.getOldCardNo(), request.getNewCardNo(), request.getReason());
// 1. 验证参数合法性
if (StringUtils.isEmpty(request.getPatientId())) {
throw new IllegalArgumentException("患者ID不能为空");
}
if (StringUtils.isEmpty(request.getNewCardNo())) {
throw new IllegalArgumentException("新卡号不能为空");
}
// 2. 检查新卡号是否已被使用
// 3. 更新患者主表中的卡号信息
// 4. 记录换卡日志
// 5. 处理相关业务系统的卡号更新
// 目前返回模拟结果
log.info("模拟执行患者换卡操作: 旧卡号={}, 新卡号={}, 原因={}",
request.getOldCardNo(), request.getNewCardNo(), request.getReason());
// 简单验证:确保旧卡号和新卡号不为空且不相同
if (request.getOldCardNo() == null || request.getNewCardNo() == null ||
request.getOldCardNo().isEmpty() || request.getNewCardNo().isEmpty()) {
throw new IllegalArgumentException("卡号不能为空");
LambdaQueryWrapper<PatientIdentifier> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PatientIdentifier::getIdentifierNo, request.getNewCardNo());
PatientIdentifier existingIdentifier = patientIdentifierService.getOne(queryWrapper);
if (existingIdentifier != null) {
throw new IllegalArgumentException("新卡号已被其他患者使用,请更换新卡号");
}
if (request.getOldCardNo().equals(request.getNewCardNo())) {
throw new IllegalArgumentException("新卡号不能与旧卡号相同");
// 3. 直接使用患者ID作为查询条件
Long patientId = Long.parseLong(request.getPatientId());
// 4. 通过患者ID查询现有标识信息
PatientIdentifier patientIdentifier = patientIdentifierService.selectByPatientId(patientId);
if (patientIdentifier != null) {
// 5. 只更新就诊卡号这一个参数
patientIdentifier.setIdentifierNo(request.getNewCardNo());
patientIdentifierService.updateById(patientIdentifier);
log.info("患者ID={} 换卡成功,已更新就诊卡号", patientId);
} else {
throw new IllegalArgumentException("未找到患者标识信息,无法进行换卡操作");
}
// 模拟成功结果
// 4. 记录换卡日志 - 可以根据需要扩展日志记录功能
// 5. 处理相关业务系统的卡号更新 - 可以根据需要扩展
return true;
}
}

View File

@@ -12,7 +12,7 @@ spring:
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
enabled:
url:
username:
password: