feat(health): P0 平台基座回顾 — 7项上线前必修
P0-1: 危急值告警消费者 — health_data.critical_alert 事件推送给责任医护 P0-2: 危急值阈值可配置化 — 硬编码改为数据库配置(critical_value_threshold表),支持科室/年龄差异化 P0-3: daily_monitoring合并后告警验证 — update_vital_signs也触发危急值检测 P0-4: 随访逾期通知+幂等保护 — 只通知本次新标记的逾期任务,避免重复 P0-5: 知情同意记录(consent) — 新增实体/迁移/Service/Handler,PIPL合规 P0-6: 审计日志补全 — 患者更新记录前后值(过敏史/病史/状态变更) P0-7: EventBus持久化增强 — 两阶段提交(pending→published)+启动时outbox relay恢复
This commit is contained in:
@@ -59,6 +59,8 @@ mod m20260426_000056_create_diagnosis;
|
||||
mod m20260426_000057_rename_points_transaction_type_column;
|
||||
mod m20260426_000058_merge_daily_monitoring_into_vital_signs;
|
||||
mod m20260426_000059_seed_menus;
|
||||
mod m20260426_000060_create_critical_value_thresholds;
|
||||
mod m20260426_000061_create_consent;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -125,6 +127,8 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260426_000057_rename_points_transaction_type_column::Migration),
|
||||
Box::new(m20260426_000058_merge_daily_monitoring_into_vital_signs::Migration),
|
||||
Box::new(m20260426_000059_seed_menus::Migration),
|
||||
Box::new(m20260426_000060_create_critical_value_thresholds::Migration),
|
||||
Box::new(m20260426_000061_create_consent::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
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
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(CriticalValueThreshold::Table)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::TenantId)
|
||||
.uuid()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::Indicator)
|
||||
.string_len(50)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::Direction)
|
||||
.string_len(10)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::ThresholdValue)
|
||||
.double()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::Level)
|
||||
.string_len(20)
|
||||
.not_null()
|
||||
.default("critical"),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::Department)
|
||||
.string_len(100),
|
||||
)
|
||||
.col(ColumnDef::new(CriticalValueThreshold::AgeMin).integer())
|
||||
.col(ColumnDef::new(CriticalValueThreshold::AgeMax).integer())
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::IsActive)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(true),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(CriticalValueThreshold::CreatedBy).uuid())
|
||||
.col(ColumnDef::new(CriticalValueThreshold::UpdatedBy).uuid())
|
||||
.col(ColumnDef::new(CriticalValueThreshold::DeletedAt).timestamp_with_time_zone())
|
||||
.col(
|
||||
ColumnDef::new(CriticalValueThreshold::Version)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_cvt_tenant_indicator_direction")
|
||||
.table(CriticalValueThreshold::Table)
|
||||
.col(CriticalValueThreshold::TenantId)
|
||||
.col(CriticalValueThreshold::Indicator)
|
||||
.col(CriticalValueThreshold::Direction)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 种子数据:默认危急值阈值
|
||||
let sql = r#"
|
||||
INSERT INTO critical_value_threshold (id, tenant_id, indicator, direction, threshold_value, level, created_at, updated_at) VALUES
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'systolic_bp', 'high', 180, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'systolic_bp', 'low', 80, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'diastolic_bp', 'high', 110, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'diastolic_bp', 'low', 50, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'heart_rate', 'high', 150, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'heart_rate', 'low', 40, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'blood_sugar', 'high', 25.0, 'critical', now(), now()),
|
||||
(gen_random_uuid(), '00000000-0000-0000-0000-000000000001', 'blood_sugar', 'low', 2.5, 'critical', now(), now())
|
||||
"#;
|
||||
manager.get_connection().execute_unprepared(sql).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(
|
||||
Table::drop()
|
||||
.table(CriticalValueThreshold::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum CriticalValueThreshold {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
Indicator,
|
||||
Direction,
|
||||
ThresholdValue,
|
||||
Level,
|
||||
Department,
|
||||
AgeMin,
|
||||
AgeMax,
|
||||
IsActive,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
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
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Consent::Table)
|
||||
.col(
|
||||
ColumnDef::new(Consent::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Consent::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(Consent::PatientId).uuid().not_null())
|
||||
.col(ColumnDef::new(Consent::ConsentType).string_len(50).not_null())
|
||||
.col(ColumnDef::new(Consent::ConsentScope).string_len(100).not_null())
|
||||
.col(
|
||||
ColumnDef::new(Consent::Status)
|
||||
.string_len(20)
|
||||
.not_null()
|
||||
.default("granted"),
|
||||
)
|
||||
.col(ColumnDef::new(Consent::GrantedAt).timestamp_with_time_zone())
|
||||
.col(ColumnDef::new(Consent::RevokedAt).timestamp_with_time_zone())
|
||||
.col(ColumnDef::new(Consent::ExpiryDate).date())
|
||||
.col(ColumnDef::new(Consent::ConsentMethod).string_len(30))
|
||||
.col(ColumnDef::new(Consent::WitnessName).string_len(100))
|
||||
.col(ColumnDef::new(Consent::Notes).text())
|
||||
.col(
|
||||
ColumnDef::new(Consent::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Consent::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(Consent::CreatedBy).uuid())
|
||||
.col(ColumnDef::new(Consent::UpdatedBy).uuid())
|
||||
.col(ColumnDef::new(Consent::DeletedAt).timestamp_with_time_zone())
|
||||
.col(
|
||||
ColumnDef::new(Consent::Version)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_consent_tenant_patient")
|
||||
.table(Consent::Table)
|
||||
.col(Consent::TenantId)
|
||||
.col(Consent::PatientId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Consent::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Consent {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
PatientId,
|
||||
ConsentType,
|
||||
ConsentScope,
|
||||
Status,
|
||||
GrantedAt,
|
||||
RevokedAt,
|
||||
ExpiryDate,
|
||||
ConsentMethod,
|
||||
WitnessName,
|
||||
Notes,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
Reference in New Issue
Block a user