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("健康档案不存在")] 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 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::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 for HealthError { fn from(err: sea_orm::DbErr) -> Self { HealthError::DbError(err.to_string()) } } impl From for HealthError { fn from(err: AppError) -> Self { HealthError::Validation(err.to_string()) } } pub type HealthResult = Result;