- 新增 3 张数据表迁移 (shifts, patient_assignments, shift_handoff_log) - 3 个 SeaORM Entity (shift, patient_assignment, handoff_log) - 完整 CRUD 服务层:班次管理、患者分配(含批量分配)、交接记录 - 12 个 API 端点 + health.shifts.list/manage 权限 - 班次列表含患者分配摘要 (patient_count/critical_count/attention_count) - 乐观锁、软删除、审计日志、事件发布 - 输入验证:period/shift_status/care_level 白名单
176 lines
4.7 KiB
Rust
176 lines
4.7 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),
|
|
}
|
|
|
|
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::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>;
|