feat(health): 护理计划实体与服务 — Phase 1 关怀引擎 MVP 第一步
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

新增护理计划(Care Plan)完整 CRUD:3 张表(care_plans / care_plan_items /
care_plan_outcomes)、3 个 SeaORM Entity、15 个 API 端点、4 个事件常量、
2 个权限码。支持透析/慢性/预防/康复计划类型,条目分干预/监测/目标/教育四类,
预后测量含基线/目标/当前值追踪。
This commit is contained in:
iven
2026-05-04 18:40:22 +08:00
parent c35ea83799
commit ef422f354d
16 changed files with 1662 additions and 2 deletions

View File

@@ -110,6 +110,7 @@ mod m20260504_000107_alter_article_article_tag_add_tenant_and_soft_delete;
mod m20260504_000108_alter_vital_signs_hourly_add_soft_delete;
mod m20260504_000109_add_missing_fk_constraints;
mod m20260504_000110_alter_critical_alerts_version_i32;
mod m20260505_000111_create_care_plan;
pub struct Migrator;
@@ -227,6 +228,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260504_000108_alter_vital_signs_hourly_add_soft_delete::Migration),
Box::new(m20260504_000109_add_missing_fk_constraints::Migration),
Box::new(m20260504_000110_alter_critical_alerts_version_i32::Migration),
Box::new(m20260505_000111_create_care_plan::Migration),
]
}
}

View File

@@ -0,0 +1,258 @@
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> {
// care_plans — 护理计划主表
manager
.create_table(
Table::create()
.table(Alias::new("care_plans"))
.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("plan_type"))
.string_len(50)
.not_null(),
)
.col(
ColumnDef::new(Alias::new("status"))
.string_len(32)
.not_null()
.default("draft"),
)
.col(ColumnDef::new(Alias::new("title")).string_len(200).not_null())
.col(
ColumnDef::new(Alias::new("goals"))
.json_binary()
.not_null()
.default("[]"),
)
.col(ColumnDef::new(Alias::new("start_date")).date())
.col(ColumnDef::new(Alias::new("end_date")).date())
.col(ColumnDef::new(Alias::new("notes")).text())
.col(
ColumnDef::new(Alias::new("created_at"))
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null(),
)
.col(ColumnDef::new(Alias::new("created_by")).uuid())
.col(ColumnDef::new(Alias::new("updated_by")).uuid())
.col(ColumnDef::new(Alias::new("deleted_at")).timestamp_with_time_zone())
.col(
ColumnDef::new(Alias::new("version"))
.integer()
.not_null()
.default(1),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_care_plans_tenant_patient")
.table(Alias::new("care_plans"))
.col(Alias::new("tenant_id"))
.col(Alias::new("patient_id"))
.col(Alias::new("deleted_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_care_plans_tenant_status")
.table(Alias::new("care_plans"))
.col(Alias::new("tenant_id"))
.col(Alias::new("status"))
.col(Alias::new("deleted_at"))
.to_owned(),
)
.await?;
// care_plan_items — 护理计划条目(干预/监测/目标)
manager
.create_table(
Table::create()
.table(Alias::new("care_plan_items"))
.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("plan_id")).uuid().not_null())
.col(
ColumnDef::new(Alias::new("item_type"))
.string_len(32)
.not_null(),
)
.col(
ColumnDef::new(Alias::new("title"))
.string_len(200)
.not_null(),
)
.col(ColumnDef::new(Alias::new("description")).text())
.col(
ColumnDef::new(Alias::new("status"))
.string_len(32)
.not_null()
.default("pending"),
)
.col(ColumnDef::new(Alias::new("schedule")).string_len(100))
.col(ColumnDef::new(Alias::new("sort_order")).integer().default(0))
.col(
ColumnDef::new(Alias::new("created_at"))
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null(),
)
.col(ColumnDef::new(Alias::new("created_by")).uuid())
.col(ColumnDef::new(Alias::new("updated_by")).uuid())
.col(ColumnDef::new(Alias::new("deleted_at")).timestamp_with_time_zone())
.col(
ColumnDef::new(Alias::new("version"))
.integer()
.not_null()
.default(1),
)
.foreign_key(
&mut ForeignKey::create()
.name("fk_care_plan_items_plan_id")
.from(Alias::new("care_plan_items"), Alias::new("plan_id"))
.to(Alias::new("care_plans"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade)
.to_owned(),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_care_plan_items_tenant_plan")
.table(Alias::new("care_plan_items"))
.col(Alias::new("tenant_id"))
.col(Alias::new("plan_id"))
.col(Alias::new("deleted_at"))
.to_owned(),
)
.await?;
// care_plan_outcomes — 护理计划预后测量
manager
.create_table(
Table::create()
.table(Alias::new("care_plan_outcomes"))
.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("plan_id")).uuid().not_null())
.col(ColumnDef::new(Alias::new("item_id")).uuid())
.col(
ColumnDef::new(Alias::new("metric"))
.string_len(100)
.not_null(),
)
.col(
ColumnDef::new(Alias::new("baseline_value"))
.string_len(50)
.not_null(),
)
.col(
ColumnDef::new(Alias::new("target_value"))
.string_len(50)
.not_null(),
)
.col(ColumnDef::new(Alias::new("current_value")).string_len(50))
.col(
ColumnDef::new(Alias::new("measured_at"))
.timestamp_with_time_zone(),
)
.col(ColumnDef::new(Alias::new("notes")).text())
.col(
ColumnDef::new(Alias::new("created_at"))
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null(),
)
.col(ColumnDef::new(Alias::new("created_by")).uuid())
.col(ColumnDef::new(Alias::new("updated_by")).uuid())
.col(ColumnDef::new(Alias::new("deleted_at")).timestamp_with_time_zone())
.col(
ColumnDef::new(Alias::new("version"))
.integer()
.not_null()
.default(1),
)
.foreign_key(
&mut ForeignKey::create()
.name("fk_care_plan_outcomes_plan_id")
.from(Alias::new("care_plan_outcomes"), Alias::new("plan_id"))
.to(Alias::new("care_plans"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade)
.to_owned(),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_care_plan_outcomes_tenant_plan")
.table(Alias::new("care_plan_outcomes"))
.col(Alias::new("tenant_id"))
.col(Alias::new("plan_id"))
.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("care_plan_outcomes")).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Alias::new("care_plan_items")).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Alias::new("care_plans")).to_owned())
.await?;
Ok(())
}
}