feat(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

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 状态)
This commit is contained in:
iven
2026-05-04 20:57:24 +08:00
parent 0a9272bcf6
commit 95fa09c383
11 changed files with 675 additions and 1 deletions

View File

@@ -114,6 +114,7 @@ mod m20260505_000111_create_care_plan;
mod m20260505_000112_create_shift_management;
mod m20260505_000113_create_ble_gateways;
mod m20260505_000114_dialysis_record_add_workflow_instance;
mod m20260505_000115_family_member_health_proxy;
pub struct Migrator;
@@ -235,6 +236,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260505_000112_create_shift_management::Migration),
Box::new(m20260505_000113_create_ble_gateways::Migration),
Box::new(m20260505_000114_dialysis_record_add_workflow_instance::Migration),
Box::new(m20260505_000115_family_member_health_proxy::Migration),
]
}
}

View File

@@ -0,0 +1,120 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Alias::new("patient_family_member"))
.add_column(
ColumnDef::new(Alias::new("user_id"))
.uuid()
.null()
.to_owned(),
)
.add_column(
ColumnDef::new(Alias::new("consent_status"))
.string()
.not_null()
.default("none")
.to_owned(),
)
.add_column(
ColumnDef::new(Alias::new("access_level"))
.string()
.not_null()
.default("none")
.to_owned(),
)
.add_column(
ColumnDef::new(Alias::new("consented_at"))
.timestamp_with_time_zone()
.null()
.to_owned(),
)
.add_column(
ColumnDef::new(Alias::new("consent_revoked_at"))
.timestamp_with_time_zone()
.null()
.to_owned(),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_family_member_user_id")
.table(Alias::new("patient_family_member"))
.col(Alias::new("user_id"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_family_member_consent_status")
.table(Alias::new("patient_family_member"))
.col(Alias::new("consent_status"))
.to_owned(),
)
.await?;
manager
.create_foreign_key(
ForeignKey::create()
.name("fk_family_member_user")
.from(Alias::new("patient_family_member"), Alias::new("user_id"))
.to(Alias::new("users"), Alias::new("id"))
.on_delete(ForeignKeyAction::SetNull)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_foreign_key(
ForeignKey::drop()
.name("fk_family_member_user")
.table(Alias::new("patient_family_member"))
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.name("idx_family_member_consent_status")
.to_owned(),
)
.await?;
manager
.drop_index(Index::drop().name("idx_family_member_user_id").to_owned())
.await?;
manager
.alter_table(
Table::alter()
.table(Alias::new("patient_family_member"))
.drop_column(Alias::new("consent_revoked_at"))
.drop_column(Alias::new("consented_at"))
.drop_column(Alias::new("access_level"))
.drop_column(Alias::new("consent_status"))
.drop_column(Alias::new("user_id"))
.to_owned(),
)
.await?;
Ok(())
}
}