feat(health): 添加 erp-health 健康管理模块骨架
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

新建 erp-health 原生 Rust crate,覆盖设计规格中定义的 5 大业务域:

- 16 个 SeaORM Entity(患者/家属/标签/医生/健康档案/体征/化验单/预约/排班/随访/咨询等)
- 16 表数据库迁移(含索引、外键、默认值、可回滚)
- 40+ API 路由骨架(患者管理/健康数据/预约排班/随访/咨询/医生管理)
- 12 个权限声明(health.patient/health-data/appointment/follow-up/consultation/doctor 各 .list/.manage)
- DTO / Service / Handler / Event 四层架构,Service 使用 todo!() 占位
- erp-server 集成:模块注册 + AppState FromRef 桥接 + 路由挂载

同步更新 CLAUDE.md 项目进度、wiki 知识库、设计规格文档。
This commit is contained in:
iven
2026-04-23 19:59:22 +08:00
parent 5ac8e18d74
commit ca50d32f6e
61 changed files with 6853 additions and 1208 deletions

View File

@@ -0,0 +1,311 @@
use axum::Extension;
use axum::extract::{FromRef, Json, Path, Query, State};
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};
use uuid::Uuid;
use erp_core::error::AppError;
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
use crate::state::HealthState;
// ---------------------------------------------------------------------------
// DTO — 患者管理
// ---------------------------------------------------------------------------
/// 患者列表查询参数
#[derive(Debug, Deserialize, IntoParams)]
pub struct PatientListParams {
pub page: Option<u64>,
pub page_size: Option<u64>,
/// 按姓名/身份证号模糊搜索
pub search: Option<String>,
/// 按标签筛选
pub tag_id: Option<Uuid>,
/// 按负责医生筛选
pub doctor_id: Option<Uuid>,
}
/// 创建患者请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct CreatePatientReq {
pub name: String,
pub id_card: Option<String>,
pub phone: Option<String>,
pub gender: Option<String>,
pub birth_date: Option<String>,
pub address: Option<String>,
pub emergency_contact: Option<String>,
pub emergency_phone: Option<String>,
pub medical_notes: Option<String>,
}
/// 更新患者请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct UpdatePatientReq {
pub name: Option<String>,
pub id_card: Option<String>,
pub phone: Option<String>,
pub gender: Option<String>,
pub birth_date: Option<String>,
pub address: Option<String>,
pub emergency_contact: Option<String>,
pub emergency_phone: Option<String>,
pub medical_notes: Option<String>,
pub version: i32,
}
/// 患者标签管理请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct ManagePatientTagsReq {
pub tag_ids: Vec<Uuid>,
}
/// 患者响应
#[derive(Debug, Serialize, ToSchema)]
pub struct PatientResp {
pub id: Uuid,
pub name: String,
pub id_card: Option<String>,
pub phone: Option<String>,
pub gender: Option<String>,
pub birth_date: Option<String>,
pub address: Option<String>,
pub emergency_contact: Option<String>,
pub emergency_phone: Option<String>,
pub medical_notes: Option<String>,
pub tags: Vec<PatientTagResp>,
pub created_at: String,
pub updated_at: String,
}
/// 患者标签响应
#[derive(Debug, Serialize, ToSchema)]
pub struct PatientTagResp {
pub id: Uuid,
pub name: String,
pub color: Option<String>,
}
/// 健康摘要响应
#[derive(Debug, Serialize, ToSchema)]
pub struct HealthSummaryResp {
pub patient_id: Uuid,
pub latest_vital_signs: Option<serde_json::Value>,
pub latest_lab_report: Option<serde_json::Value>,
pub upcoming_appointments: u64,
pub pending_follow_ups: u64,
}
/// 家庭成员请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct CreateFamilyMemberReq {
pub name: String,
pub relationship: String,
pub phone: Option<String>,
pub id_card: Option<String>,
}
/// 更新家庭成员请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct UpdateFamilyMemberReq {
pub name: Option<String>,
pub relationship: Option<String>,
pub phone: Option<String>,
pub id_card: Option<String>,
}
/// 家庭成员响应
#[derive(Debug, Serialize, ToSchema)]
pub struct FamilyMemberResp {
pub id: Uuid,
pub patient_id: Uuid,
pub name: String,
pub relationship: String,
pub phone: Option<String>,
pub id_card: Option<String>,
}
/// 分配医生请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct AssignDoctorReq {
pub doctor_id: Uuid,
}
// ---------------------------------------------------------------------------
// Handler — 患者管理 (13 个端点)
// ---------------------------------------------------------------------------
/// GET /api/v1/health/patients — 患者列表
pub async fn list_patients<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Query(_params): Query<PatientListParams>,
) -> Result<Json<ApiResponse<PaginatedResponse<PatientResp>>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// POST /api/v1/health/patients — 创建患者
pub async fn create_patient<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Json(_req): Json<CreatePatientReq>,
) -> Result<Json<ApiResponse<PatientResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// GET /api/v1/health/patients/{id} — 获取患者详情
pub async fn get_patient<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
) -> Result<Json<ApiResponse<PatientResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// PUT /api/v1/health/patients/{id} — 更新患者
pub async fn update_patient<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
Json(_req): Json<UpdatePatientReq>,
) -> Result<Json<ApiResponse<PatientResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// DELETE /api/v1/health/patients/{id} — 删除患者(软删除)
pub async fn delete_patient<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// POST /api/v1/health/patients/{id}/tags — 管理患者标签
pub async fn manage_patient_tags<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
Json(_req): Json<ManagePatientTagsReq>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// GET /api/v1/health/patients/{id}/health-summary — 获取患者健康摘要
pub async fn get_health_summary<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
) -> Result<Json<ApiResponse<HealthSummaryResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// GET /api/v1/health/patients/{id}/family-members — 家庭成员列表
pub async fn list_family_members<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
) -> Result<Json<ApiResponse<Vec<FamilyMemberResp>>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// POST /api/v1/health/patients/{id}/family-members — 创建家庭成员
pub async fn create_family_member<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
Json(_req): Json<CreateFamilyMemberReq>,
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// PUT /api/v1/health/patients/{patient_id}/family-members/{member_id} — 更新家庭成员
pub async fn update_family_member<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path((_patient_id, _member_id)): Path<(Uuid, Uuid)>,
Json(_req): Json<UpdateFamilyMemberReq>,
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// DELETE /api/v1/health/patients/{patient_id}/family-members/{member_id} — 删除家庭成员
pub async fn delete_family_member<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path((_patient_id, _member_id)): Path<(Uuid, Uuid)>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// POST /api/v1/health/patients/{id}/doctors — 分配负责医生
pub async fn assign_doctor<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
Json(_req): Json<AssignDoctorReq>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}
/// DELETE /api/v1/health/patients/{patient_id}/doctors/{doctor_id} — 移除负责医生
pub async fn remove_doctor<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path((_patient_id, _doctor_id)): Path<(Uuid, Uuid)>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
}