新增随访模板和模板字段两张表及完整 CRUD: - 迁移 083: follow_up_template + follow_up_template_field - Entity: 模板(名称/类型/适用范围/状态) + 字段(标签/键名/类型/选项/校验) - DTO: 创建时内嵌字段列表、更新支持全量替换字段 - Service: 随访类型+字段类型校验、级联软删除 - Handler: 5 端点 + RBAC 权限 - 路由: /api/v1/health/follow-up-templates
148 lines
3.9 KiB
Rust
148 lines
3.9 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("日常监测记录不存在")]
|
|
DailyMonitoringNotFound,
|
|
|
|
#[error("积分规则不存在")]
|
|
PointsRuleNotFound,
|
|
|
|
#[error("兑换商品不存在")]
|
|
PointsProductNotFound,
|
|
|
|
#[error("兑换订单不存在")]
|
|
PointsOrderNotFound,
|
|
|
|
#[error("线下活动不存在")]
|
|
OfflineEventNotFound,
|
|
|
|
#[error("健康档案不存在")]
|
|
HealthRecordNotFound,
|
|
|
|
#[error("家庭成员不存在")]
|
|
FamilyMemberNotFound,
|
|
|
|
#[error("标签不存在")]
|
|
TagNotFound,
|
|
|
|
#[error("排班已满,无法预约")]
|
|
ScheduleFull,
|
|
|
|
#[error("随访任务不存在")]
|
|
FollowUpTaskNotFound,
|
|
|
|
#[error("会话不存在")]
|
|
ConsultationNotFound,
|
|
|
|
#[error("文章不存在")]
|
|
ArticleNotFound,
|
|
|
|
#[error("危急值阈值不存在")]
|
|
ThresholdNotFound,
|
|
|
|
#[error("知情同意记录不存在")]
|
|
ConsentNotFound,
|
|
|
|
#[error("告警规则不存在")]
|
|
AlertRuleNotFound,
|
|
|
|
#[error("告警记录不存在")]
|
|
AlertNotFound,
|
|
|
|
#[error("透析方案不存在")]
|
|
DialysisPrescriptionNotFound,
|
|
|
|
#[error("随访模板不存在")]
|
|
FollowUpTemplateNotFound,
|
|
|
|
#[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
|
|
| HealthError::PointsRuleNotFound
|
|
| HealthError::PointsProductNotFound
|
|
| HealthError::PointsOrderNotFound
|
|
| HealthError::OfflineEventNotFound
|
|
| HealthError::DailyMonitoringNotFound
|
|
| HealthError::ThresholdNotFound
|
|
| HealthError::ConsentNotFound
|
|
| HealthError::AlertRuleNotFound
|
|
| HealthError::AlertNotFound
|
|
| HealthError::DialysisPrescriptionNotFound
|
|
| HealthError::FollowUpTemplateNotFound => 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())
|
|
}
|
|
}
|
|
|
|
impl From<String> for HealthError {
|
|
fn from(err: String) -> Self {
|
|
HealthError::Validation(err)
|
|
}
|
|
}
|
|
|
|
pub type HealthResult<T> = Result<T, HealthError>;
|