Files
hms/crates/erp-server/migration/src/m20260426_000056_create_diagnosis.rs
iven b4735213c5
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 业务改进 — 诊断编码/统计API/体征表合并/积分修复
1.1 Dashboard 统计: 新增 3 个统计端点 (patient/consultation/follow-up)
1.2 事件发布: follow_up.overdue + health_data.critical_alert 事件
1.3 体征表合并: vital_signs 添加 source 列, daily_monitoring 委托写入
1.4 实时预警: 创建体征时检测血压/心率/血糖异常并发布事件
1.5 诊断编码: 新建 diagnosis entity/service/handler + ICD-10 支持
1.6 积分过期: expire_points 定时任务 + 修复 r#type 列名问题

修复: points_transaction.r#type → transaction_type 列重命名
修复: consultation_message.sender_type → sender_role SQL 列名
前端: 3 个统计 API 从伪实现改为真实调用
2026-04-26 00:54:56 +08:00

79 lines
2.8 KiB
Rust

use sea_orm_migration::{prelude::*, schema::*};
#[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(Alias::new("diagnosis"))
.if_not_exists()
.col(uuid("id").primary_key())
.col(uuid("tenant_id").not_null())
.col(uuid("patient_id").not_null())
.col(uuid_null("health_record_id"))
.col(string_uniq("icd_code").not_null())
.col(string("diagnosis_name").not_null())
.col(string("diagnosis_type").not_null().default("primary"))
.col(date("diagnosed_date").not_null())
.col(string("status").not_null().default("active"))
.col(uuid_null("diagnosed_by"))
.col(string_null("notes"))
.col(timestamp_with_time_zone("created_at").not_null().default(Expr::current_timestamp()))
.col(timestamp_with_time_zone("updated_at").not_null().default(Expr::current_timestamp()))
.col(uuid_null("created_by"))
.col(uuid_null("updated_by"))
.col(timestamp_with_time_zone_null("deleted_at"))
.col(integer("version").not_null().default(1))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_diagnosis_tenant_patient")
.table(Alias::new("diagnosis"))
.col(Alias::new("tenant_id"))
.col(Alias::new("patient_id"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_diagnosis_icd_code")
.table(Alias::new("diagnosis"))
.col(Alias::new("tenant_id"))
.col(Alias::new("icd_code"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_diagnosis_deleted_at")
.table(Alias::new("diagnosis"))
.col(Alias::new("deleted_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Alias::new("diagnosis")).to_owned())
.await
}
}