- 创建 erp-dialysis crate(DialysisState + DialysisError + DialysisModule) - 迁移 2 Entity + 2 Service + 2 Handler + 2 DTO 共 8 个文件 - Entity 移除跨 crate patient Relation(FK 列保留) - Service 内联 validation 逻辑,移除 patient 存在性检查(FK 约束保证) - erp-health 的 stats/consultation 中 dialysis 查询改为 raw SQL - ReviewLabReportReq 从 dialysis_dto 移至 health_data_dto(正确归属) - workspace 全量编译通过
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
use erp_core::error::AppError;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum DialysisError {
|
|
#[error("{0}")]
|
|
Validation(String),
|
|
|
|
#[error("患者不存在")]
|
|
PatientNotFound,
|
|
|
|
#[error("透析记录不存在")]
|
|
DialysisRecordNotFound,
|
|
|
|
#[error("透析方案不存在")]
|
|
DialysisPrescriptionNotFound,
|
|
|
|
#[error("状态转换无效: {0}")]
|
|
InvalidStatusTransition(String),
|
|
|
|
#[error("版本冲突: 数据已被其他操作修改,请刷新后重试")]
|
|
VersionMismatch,
|
|
|
|
#[error("数据库操作失败: {0}")]
|
|
DbError(String),
|
|
}
|
|
|
|
impl From<DialysisError> for AppError {
|
|
fn from(err: DialysisError) -> Self {
|
|
match err {
|
|
DialysisError::Validation(s) => AppError::Validation(s),
|
|
DialysisError::PatientNotFound
|
|
| DialysisError::DialysisRecordNotFound
|
|
| DialysisError::DialysisPrescriptionNotFound => AppError::NotFound(err.to_string()),
|
|
DialysisError::InvalidStatusTransition(s) => AppError::Validation(s),
|
|
DialysisError::VersionMismatch => AppError::VersionMismatch,
|
|
DialysisError::DbError(_) => AppError::Internal(err.to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<sea_orm::DbErr> for DialysisError {
|
|
fn from(err: sea_orm::DbErr) -> Self {
|
|
DialysisError::DbError(err.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<AppError> for DialysisError {
|
|
fn from(err: AppError) -> Self {
|
|
DialysisError::Validation(err.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<String> for DialysisError {
|
|
fn from(err: String) -> Self {
|
|
DialysisError::Validation(err)
|
|
}
|
|
}
|
|
|
|
pub type DialysisResult<T> = Result<T, DialysisError>;
|