Files
hms/crates/erp-health/src/handler/family_proxy_handler.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

85 lines
3.0 KiB
Rust

//! 家庭成员健康代理 Handler — 同意管理 + 健康摘要查看
use axum::extract::{Json, Path, Query, State};
use axum::Extension;
use erp_core::error::AppError;
use erp_core::rbac::require_permission;
use erp_core::types::{ApiResponse, TenantContext};
use serde::Deserialize;
use uuid::Uuid;
use crate::dto::patient_dto::*;
use crate::service::family_proxy_service;
use crate::state::HealthState;
#[derive(Debug, Clone, Deserialize)]
pub struct VersionQuery {
pub version: i32,
}
/// 授权家庭成员访问健康数据
pub async fn grant_family_access(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path((patient_id, family_member_id)): Path<(Uuid, Uuid)>,
Query(params): Query<VersionQuery>,
Json(req): Json<GrantFamilyAccessReq>,
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError> {
require_permission(&ctx, "health.patient.manage")?;
let result = family_proxy_service::grant_family_access(
&state, ctx.tenant_id, patient_id, family_member_id,
Some(ctx.user_id), req, params.version,
).await?;
Ok(Json(ApiResponse::ok(result)))
}
/// 撤销家庭成员健康数据访问
pub async fn revoke_family_access(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path((patient_id, family_member_id)): Path<(Uuid, Uuid)>,
Query(params): Query<VersionQuery>,
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError> {
require_permission(&ctx, "health.patient.manage")?;
let result = family_proxy_service::revoke_family_access(
&state, ctx.tenant_id, patient_id, family_member_id,
Some(ctx.user_id), params.version,
).await?;
Ok(Json(ApiResponse::ok(result)))
}
/// 家庭成员查看关联患者列表
pub async fn list_my_family_patients(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
) -> Result<Json<ApiResponse<Vec<FamilyPatientSummaryResp>>>, AppError> {
let result = family_proxy_service::list_family_patients(
&state, ctx.tenant_id, ctx.user_id,
).await?;
Ok(Json(ApiResponse::ok(result)))
}
/// 家庭成员查看患者健康摘要
pub async fn get_family_health_summary(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(patient_id): Path<Uuid>,
) -> Result<Json<ApiResponse<FamilyHealthSummaryResp>>, AppError> {
let result = family_proxy_service::get_family_health_summary(
&state, ctx.tenant_id, ctx.user_id, patient_id,
).await?;
Ok(Json(ApiResponse::ok(result)))
}
/// 绑定家庭成员到系统用户(小程序扫码验证后调用)
pub async fn link_family_member_user(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(family_member_id): Path<Uuid>,
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError> {
let result = family_proxy_service::link_family_member_user(
&state, ctx.tenant_id, family_member_id, ctx.user_id,
).await?;
Ok(Json(ApiResponse::ok(result)))
}