Files
hms/crates/erp-server/migration/src/m20260502_000102_seed_warning_thresholds.rs
iven e8ee441ae1 feat(health): Track 3 医疗阈值 — warning 种子 + 患者端只读 API
- 新增 6 条 warning 级别阈值种子数据(血压/心率/血糖参考范围)
- 新增 GET /health/critical-value-thresholds/public 患者端只读接口
- 扩展 indicator 验证支持 blood_sugar_fasting/postprandial 等新指标
2026-05-02 11:37:21 +08:00

57 lines
2.2 KiB
Rust

//! 补充 warning 级别危急值阈值种子数据
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> {
let db = manager.get_connection();
let result = db
.query_one(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
"SELECT id::text FROM tenant LIMIT 1".to_string(),
))
.await?;
let tid = match result {
Some(row) => row.try_get_by_index::<String>(0).unwrap_or_default(),
None => return Ok(()),
};
// warning 级别阈值 — 用于小程序体征参考范围
let sql = format!(
r#"
INSERT INTO critical_value_threshold (id, tenant_id, indicator, direction, threshold_value, level, is_active, created_at, updated_at)
VALUES
(gen_random_uuid(), '{tid}', 'systolic_bp', 'high', 140, 'warning', true, now(), now()),
(gen_random_uuid(), '{tid}', 'diastolic_bp', 'high', 90, 'warning', true, now(), now()),
(gen_random_uuid(), '{tid}', 'heart_rate', 'high', 100, 'warning', true, now(), now()),
(gen_random_uuid(), '{tid}', 'heart_rate', 'low', 60, 'warning', true, now(), now()),
(gen_random_uuid(), '{tid}', 'blood_sugar_fasting', 'high', 6.1, 'warning', true, now(), now()),
(gen_random_uuid(), '{tid}', 'blood_sugar_postprandial','high', 7.8, 'warning', true, now(), now())
"#
);
db.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
sql,
))
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
db.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
"DELETE FROM critical_value_threshold WHERE level = 'warning'".to_string(),
))
.await?;
Ok(())
}
}