feat(health): 班次管理与护士分配 — Shift/PatientAssignment/HandoffLog CRUD
- 新增 3 张数据表迁移 (shifts, patient_assignments, shift_handoff_log) - 3 个 SeaORM Entity (shift, patient_assignment, handoff_log) - 完整 CRUD 服务层:班次管理、患者分配(含批量分配)、交接记录 - 12 个 API 端点 + health.shifts.list/manage 权限 - 班次列表含患者分配摘要 (patient_count/critical_count/attention_count) - 乐观锁、软删除、审计日志、事件发布 - 输入验证:period/shift_status/care_level 白名单
This commit is contained in:
@@ -111,6 +111,7 @@ 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;
|
||||
mod m20260505_000112_create_shift_management;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -229,6 +230,7 @@ impl MigratorTrait for Migrator {
|
||||
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),
|
||||
Box::new(m20260505_000112_create_shift_management::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
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(Shift::Table)
|
||||
.col(
|
||||
ColumnDef::new(Shift::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Shift::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(Shift::ShiftDate).date().not_null())
|
||||
.col(ColumnDef::new(Shift::Period).string_len(20).not_null())
|
||||
.col(ColumnDef::new(Shift::NurseId).uuid())
|
||||
.col(ColumnDef::new(Shift::Status).string_len(20).not_null().default("scheduled"))
|
||||
.col(ColumnDef::new(Shift::Notes).text())
|
||||
.col(ColumnDef::new(Shift::CreatedAt).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(Shift::UpdatedAt).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(Shift::CreatedBy).uuid())
|
||||
.col(ColumnDef::new(Shift::UpdatedBy).uuid())
|
||||
.col(ColumnDef::new(Shift::DeletedAt).timestamp_with_time_zone())
|
||||
.col(ColumnDef::new(Shift::Version).integer().not_null().default(1))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_shifts_tenant_date")
|
||||
.table(Shift::Table)
|
||||
.col(Shift::TenantId)
|
||||
.col(Shift::ShiftDate)
|
||||
.col(Shift::DeletedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_shifts_tenant_nurse")
|
||||
.table(Shift::Table)
|
||||
.col(Shift::TenantId)
|
||||
.col(Shift::NurseId)
|
||||
.col(Shift::DeletedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 患者分配表
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(PatientAssignment::Table)
|
||||
.col(
|
||||
ColumnDef::new(PatientAssignment::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(PatientAssignment::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(PatientAssignment::ShiftId).uuid().not_null())
|
||||
.col(ColumnDef::new(PatientAssignment::PatientId).uuid().not_null())
|
||||
.col(ColumnDef::new(PatientAssignment::CareLevel).string_len(20).not_null().default("routine"))
|
||||
.col(ColumnDef::new(PatientAssignment::Notes).text())
|
||||
.col(ColumnDef::new(PatientAssignment::CreatedAt).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(PatientAssignment::UpdatedAt).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(PatientAssignment::CreatedBy).uuid())
|
||||
.col(ColumnDef::new(PatientAssignment::UpdatedBy).uuid())
|
||||
.col(ColumnDef::new(PatientAssignment::DeletedAt).timestamp_with_time_zone())
|
||||
.col(ColumnDef::new(PatientAssignment::Version).integer().not_null().default(1))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_foreign_key(
|
||||
&mut ForeignKey::create()
|
||||
.name("fk_patient_assignments_shift")
|
||||
.from(PatientAssignment::Table, PatientAssignment::ShiftId)
|
||||
.to(Shift::Table, Shift::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_patient_assignments_shift")
|
||||
.table(PatientAssignment::Table)
|
||||
.col(PatientAssignment::TenantId)
|
||||
.col(PatientAssignment::ShiftId)
|
||||
.col(PatientAssignment::DeletedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_patient_assignments_patient")
|
||||
.table(PatientAssignment::Table)
|
||||
.col(PatientAssignment::TenantId)
|
||||
.col(PatientAssignment::PatientId)
|
||||
.col(PatientAssignment::DeletedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 交接日志表
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(HandoffLog::Table)
|
||||
.col(
|
||||
ColumnDef::new(HandoffLog::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(HandoffLog::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(HandoffLog::FromShiftId).uuid().not_null())
|
||||
.col(ColumnDef::new(HandoffLog::ToShiftId).uuid().not_null())
|
||||
.col(ColumnDef::new(HandoffLog::PatientId).uuid().not_null())
|
||||
.col(ColumnDef::new(HandoffLog::Notes).text())
|
||||
.col(ColumnDef::new(HandoffLog::PendingItems).json_binary())
|
||||
.col(ColumnDef::new(HandoffLog::CreatedAt).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(HandoffLog::UpdatedAt).timestamp_with_time_zone().not_null())
|
||||
.col(ColumnDef::new(HandoffLog::CreatedBy).uuid())
|
||||
.col(ColumnDef::new(HandoffLog::UpdatedBy).uuid())
|
||||
.col(ColumnDef::new(HandoffLog::DeletedAt).timestamp_with_time_zone())
|
||||
.col(ColumnDef::new(HandoffLog::Version).integer().not_null().default(1))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_foreign_key(
|
||||
&mut ForeignKey::create()
|
||||
.name("fk_handoff_log_from_shift")
|
||||
.from(HandoffLog::Table, HandoffLog::FromShiftId)
|
||||
.to(Shift::Table, Shift::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_foreign_key(
|
||||
&mut ForeignKey::create()
|
||||
.name("fk_handoff_log_to_shift")
|
||||
.from(HandoffLog::Table, HandoffLog::ToShiftId)
|
||||
.to(Shift::Table, Shift::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_handoff_log_to_shift")
|
||||
.table(HandoffLog::Table)
|
||||
.col(HandoffLog::TenantId)
|
||||
.col(HandoffLog::ToShiftId)
|
||||
.col(HandoffLog::DeletedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(HandoffLog::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(PatientAssignment::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(Shift::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Shift {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
ShiftDate,
|
||||
Period,
|
||||
NurseId,
|
||||
Status,
|
||||
Notes,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum PatientAssignment {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
ShiftId,
|
||||
PatientId,
|
||||
CareLevel,
|
||||
Notes,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum HandoffLog {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
FromShiftId,
|
||||
ToShiftId,
|
||||
PatientId,
|
||||
Notes,
|
||||
PendingItems,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
Reference in New Issue
Block a user