Files
hms/crates/erp-health/src/error.rs
iven 16c63925ce
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled
feat(health): V2 血透专科数据模型 — dialysis_record + lab_report 审阅流程
- 新增 dialysis_record 表和完整 CRUD API(透析日期/体重/血压/超滤量/透析类型/症状)
- ALTER lab_report 增加 source/status/reviewed_by/reviewed_at 字段
- 重命名 lab_report: indicators→items, doctor_interpretation→doctor_notes
- 新增透析记录审阅端点 PUT /dialysis-records/{id}/review
- 新增化验报告审阅端点 PUT /patients/{id}/lab-reports/{rid}/review
- 化验报告 items JSON 支持 V2 结构(name/value/unit/reference/is_abnormal)
- 迁移 m000051 含完整 up/down 回滚
- 94 个后端测试全部通过,API 全链路验证通过
2026-04-25 13:45:11 +08:00

98 lines
2.6 KiB
Rust

use erp_core::error::AppError;
#[derive(Debug, thiserror::Error)]
pub enum HealthError {
#[error("{0}")]
Validation(String),
#[error("患者不存在")]
PatientNotFound,
#[error("医护档案不存在")]
DoctorNotFound,
#[error("预约不存在")]
AppointmentNotFound,
#[error("排班不存在")]
ScheduleNotFound,
#[error("体征记录不存在")]
VitalSignsNotFound,
#[error("化验报告不存在")]
LabReportNotFound,
#[error("透析记录不存在")]
DialysisRecordNotFound,
#[error("健康档案不存在")]
HealthRecordNotFound,
#[error("家庭成员不存在")]
FamilyMemberNotFound,
#[error("标签不存在")]
TagNotFound,
#[error("排班已满,无法预约")]
ScheduleFull,
#[error("随访任务不存在")]
FollowUpTaskNotFound,
#[error("会话不存在")]
ConsultationNotFound,
#[error("文章不存在")]
ArticleNotFound,
#[error("状态转换无效: {0}")]
InvalidStatusTransition(String),
#[error("版本冲突: 数据已被其他操作修改,请刷新后重试")]
VersionMismatch,
#[error("数据库操作失败: {0}")]
DbError(String),
}
impl From<HealthError> for AppError {
fn from(err: HealthError) -> Self {
match err {
HealthError::Validation(s) => AppError::Validation(s),
HealthError::PatientNotFound
| HealthError::DoctorNotFound
| HealthError::AppointmentNotFound
| HealthError::ScheduleNotFound
| HealthError::VitalSignsNotFound
| HealthError::LabReportNotFound
| HealthError::DialysisRecordNotFound
| HealthError::HealthRecordNotFound
| HealthError::FamilyMemberNotFound
| HealthError::TagNotFound
| HealthError::FollowUpTaskNotFound
| HealthError::ConsultationNotFound
| HealthError::ArticleNotFound => AppError::NotFound(err.to_string()),
HealthError::ScheduleFull => AppError::Validation(err.to_string()),
HealthError::InvalidStatusTransition(s) => AppError::Validation(s),
HealthError::VersionMismatch => AppError::VersionMismatch,
HealthError::DbError(_) => AppError::Internal(err.to_string()),
}
}
}
impl From<sea_orm::DbErr> for HealthError {
fn from(err: sea_orm::DbErr) -> Self {
HealthError::DbError(err.to_string())
}
}
impl From<AppError> for HealthError {
fn from(err: AppError) -> Self {
HealthError::Validation(err.to_string())
}
}
pub type HealthResult<T> = Result<T, HealthError>;