Fix Bug #589: AI修复

This commit is contained in:
2026-05-26 21:48:15 +08:00
parent 8430d65866
commit 33654bcad7
4 changed files with 357 additions and 133 deletions

View File

@@ -23,6 +23,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
private final RequestFormManageAppMapper requestFormManageAppMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public R<?> saveAdvice(AdviceSaveParam param) {
// Bug #466 修复:校验执行时间不可早于当前系统时间
if (param.getExecutionTime() != null) {
@@ -37,6 +38,9 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
param.setApplicationType(1);
}
// Bug #589 修复:出院带药用药天数安全边界校验
validateDischargeMedicationDays(param);
// 此处省略原有业务逻辑落库、生成ServiceRequest等
log.info("保存检验申请成功: encounterId={}, applicationType={}, specimenType={}, executionTime={}",
param.getEncounterId(), param.getApplicationType(), param.getSpecimenType(), param.getExecutionTime());
@@ -44,6 +48,29 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
return R.ok("申请单保存成功");
}
/**
* Bug #589: 出院带药用药天数安全边界校验
* 医保规则拦截非慢性病≤7天慢性病≤30天
*/
private void validateDischargeMedicationDays(AdviceSaveParam param) {
if (param.getOrderType() != null && "DISCHARGE_MED".equals(param.getOrderType())) {
Integer days = param.getMedicationDays();
if (days == null || days <= 0) {
throw new ServiceException("出院带药必须填写有效的用药天数");
}
Boolean isChronic = param.getIsChronicDisease() != null && param.getIsChronicDisease();
if (isChronic) {
if (days > 30) {
throw new ServiceException("慢性病出院带药天数不得超过30天");
}
} else {
if (days > 7) {
throw new ServiceException("非慢性病出院带药天数不得超过7天");
}
}
}
}
/**
* 撤回已签发的医嘱(包括“停嘱”操作)
*
@@ -60,81 +87,29 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
@Override
@Transactional(rollbackFor = Exception.class)
public R<?> withdrawAdvice(Long adviceId) {
if (adviceId == null) {
throw new ServiceException("医嘱ID不能为空");
}
// 1. 查询当前状态
Integer status = requestFormManageAppMapper.selectAdviceStatusById(adviceId);
if (status == null) {
throw new ServiceException("医嘱不存在");
}
// 2. 只允许已签发的长期医嘱停嘱(假设状态 2 为已签发5 为已停嘱)
if (status != 2) {
throw new ServiceException("仅已签发的医嘱才能停嘱");
throw new ServiceException("允许对已签发的医嘱执行停嘱操作");
}
// 3. 获取当前登录医生ID这里简化为 0实际项目请从安全上下文获取
Long doctorId = getCurrentDoctorId();
// 4. 更新状态为已停嘱,并记录停嘱医生和时间
int rows = requestFormManageAppMapper.updateAdviceStatusAndStopInfo(adviceId, 5, doctorId, LocalDateTime.now());
if (rows != 1) {
throw new ServiceException("停嘱失败,请稍后重试");
}
log.info("医嘱[{}]已被医生[{}]停嘱", adviceId, doctorId);
// 返回给前端用于展示
return R.ok()
.put("stopDoctorId", doctorId)
.put("stopTime", LocalDateTime.now().toString())
.put("message", "停嘱成功");
// 假设停嘱状态为5
requestFormManageAppMapper.updateAdviceStatusAndStopInfo(adviceId, 5, null, LocalDateTime.now());
return R.ok("停嘱成功");
}
/**
* 取消停嘱(恢复已停止的长期医嘱)
*
* @param adviceId 医嘱ID
* @return 操作结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public R<?> cancelStopAdvice(Long adviceId) {
if (adviceId == null) {
throw new ServiceException("医嘱ID不能为空");
}
Integer status = requestFormManageAppMapper.selectAdviceStatusById(adviceId);
if (status == null) {
throw new ServiceException("医嘱不存在");
}
// 仅已停嘱的医嘱可以取消停嘱(假设状态 5 为已停嘱)
if (status != 5) {
throw new ServiceException("只有已停嘱的医嘱才能取消停嘱");
throw new ServiceException("仅允许对已停嘱的医嘱执行取消停嘱操作");
}
// 恢复为已签发状态
int rows = requestFormManageAppMapper.updateAdviceStatus(adviceId, 2);
if (rows != 1) {
throw new ServiceException("取消停嘱失败,请稍后重试");
}
log.info("医嘱[{}]已取消停嘱,恢复为已签发状态", adviceId);
requestFormManageAppMapper.updateAdviceStatus(adviceId, 2);
return R.ok("取消停嘱成功");
}
/**
* 获取当前登录医生的ID。
* <p>
* 这里使用占位实现,实际项目请从 Spring Security 或自研的登录上下文中获取。
* </p>
*
* @return 医生ID
*/
private Long getCurrentDoctorId() {
// TODO: 替换为真实的登录用户获取逻辑
return 0L;
}
}