feat(health): 用药记录实体 — CRUD 全栈
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

- 迁移 080: medication_record 表(18 字段 + 频率/给药途径校验)
- Entity/DTO/Service/Handler 全链路
- 端点: GET/POST/PUT/DELETE /health/medications + /health/patients/{id}/medications
- 软删除 + 乐观锁 + 审计日志
This commit is contained in:
iven
2026-04-27 11:45:49 +08:00
parent 67f2d07809
commit bab0d6619b
11 changed files with 752 additions and 1 deletions

View File

@@ -79,6 +79,7 @@ mod m20260426_000076_create_alert_rules;
mod m20260426_000077_create_alerts;
mod m20260427_000078_normalize_follow_up_types;
mod m20260427_000079_add_vital_signs_fields;
mod m20260427_000080_create_medication_record;
pub struct Migrator;
@@ -165,6 +166,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260426_000077_create_alerts::Migration),
Box::new(m20260427_000078_normalize_follow_up_types::Migration),
Box::new(m20260427_000079_add_vital_signs_fields::Migration),
Box::new(m20260427_000080_create_medication_record::Migration),
]
}
}

View File

@@ -0,0 +1,86 @@
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(Alias::new("medication_record"))
.if_not_exists()
.col(ColumnDef::new(Alias::new("id")).uuid().not_null().primary_key())
.col(ColumnDef::new(Alias::new("tenant_id")).uuid().not_null())
.col(ColumnDef::new(Alias::new("patient_id")).uuid().not_null())
.col(ColumnDef::new(Alias::new("medication_name")).string_len(200).not_null())
.col(ColumnDef::new(Alias::new("generic_name")).string_len(200).null())
.col(ColumnDef::new(Alias::new("dosage")).string_len(50).null())
.col(ColumnDef::new(Alias::new("unit")).string_len(20).null())
.col(ColumnDef::new(Alias::new("frequency")).string_len(20).null())
.col(ColumnDef::new(Alias::new("route")).string_len(20).null())
.col(ColumnDef::new(Alias::new("start_date")).date().null())
.col(ColumnDef::new(Alias::new("end_date")).date().null())
.col(ColumnDef::new(Alias::new("is_current")).boolean().not_null().default(true))
.col(ColumnDef::new(Alias::new("prescribed_by")).uuid().null())
.col(ColumnDef::new(Alias::new("notes")).text().null())
.col(
ColumnDef::new(Alias::new("created_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.col(ColumnDef::new(Alias::new("created_by")).uuid().null())
.col(ColumnDef::new(Alias::new("updated_by")).uuid().null())
.col(ColumnDef::new(Alias::new("deleted_at")).timestamp_with_time_zone().null())
.col(
ColumnDef::new(Alias::new("version"))
.integer()
.not_null()
.default(1),
)
.to_owned(),
)
.await?;
// 租户+患者复合索引 — 最常用的查询维度
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_medication_record_tenant_patient")
.table(Alias::new("medication_record"))
.col(Alias::new("tenant_id"))
.col(Alias::new("patient_id"))
.to_owned(),
)
.await?;
// 软删除索引 — 过滤已删除记录
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_medication_record_deleted_at")
.table(Alias::new("medication_record"))
.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("medication_record")).to_owned())
.await
}
}