Files
hms/crates/erp-health/src/error.rs
iven 95fa09c383
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): 家庭成员健康代理 — 同意追踪 + 健康摘要查看
Phase 1 Care Engine MVP 最后一项 (#8):
- 迁移: patient_family_member 表新增 user_id/consent_status/access_level/consented_at/consent_revoked_at
- 实体: 更新 patient_family_member Model 含新字段
- DTO: FamilyMemberResp 扩展 + 新增 GrantFamilyAccessReq/FamilyPatientSummaryResp/FamilyHealthSummaryResp
- Service: 授权/撤销访问、家庭成员查看关联患者列表、查看健康摘要(按 access_level 分级)
- Handler: 5 个端点(grant/revoke/list/summary/link-user)
- 路由: /health/patients/{id}/family-members/{fid}/grant-access 等
- 权限: health.family-proxy.list/manage
- 已有 CRUD 适配新字段(list/create/update 返回 consent 状态)
2026-05-04 20:57:24 +08:00

180 lines
4.8 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("日常监测记录不存在")]
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("设备绑定不存在")]
DeviceNotFound,
#[error("告警规则不存在")]
AlertRuleNotFound,
#[error("告警记录不存在")]
AlertNotFound,
#[error("随访模板不存在")]
FollowUpTemplateNotFound,
#[error("危急值告警不存在")]
CriticalAlertNotFound,
#[error("药物提醒不存在")]
MedicationReminderNotFound,
#[error("护理计划不存在")]
CarePlanNotFound,
#[error("护理计划条目不存在")]
CarePlanItemNotFound,
#[error("护理计划预后不存在")]
CarePlanOutcomeNotFound,
#[error("班次不存在")]
ShiftNotFound,
#[error("患者分配不存在")]
PatientAssignmentNotFound,
#[error("交接记录不存在")]
HandoffLogNotFound,
#[error("状态转换无效: {0}")]
InvalidStatusTransition(String),
#[error("版本冲突: 数据已被其他操作修改,请刷新后重试")]
VersionMismatch,
#[error("数据库操作失败: {0}")]
DbError(String),
#[error("权限不足: {0}")]
Forbidden(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::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::DeviceNotFound
| HealthError::AlertNotFound
| HealthError::FollowUpTemplateNotFound
| HealthError::CriticalAlertNotFound
| HealthError::MedicationReminderNotFound
| HealthError::CarePlanNotFound
| HealthError::CarePlanItemNotFound
| HealthError::CarePlanOutcomeNotFound
| HealthError::ShiftNotFound
| HealthError::PatientAssignmentNotFound
| HealthError::HandoffLogNotFound => AppError::NotFound(err.to_string()),
HealthError::ScheduleFull => AppError::Validation(err.to_string()),
HealthError::InvalidStatusTransition(s) => AppError::Validation(s),
HealthError::VersionMismatch => AppError::VersionMismatch,
HealthError::Forbidden(msg) => AppError::Forbidden(msg),
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>;