feat(health): 班次管理与护士分配 — Shift/PatientAssignment/HandoffLog 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

- 新增 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:
iven
2026-05-04 20:11:07 +08:00
parent 3ff17382ff
commit 7b17f94bc0
14 changed files with 1554 additions and 2 deletions

View File

@@ -0,0 +1,51 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "shift_handoff_log")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
pub from_shift_id: Uuid,
pub to_shift_id: Uuid,
pub patient_id: Uuid,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub pending_items: Option<serde_json::Value>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub created_by: Option<Uuid>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub updated_by: Option<Uuid>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::shift::Entity",
from = "Column::FromShiftId",
to = "super::shift::Column::Id"
)]
FromShift,
#[sea_orm(
belongs_to = "super::shift::Entity",
from = "Column::ToShiftId",
to = "super::shift::Column::Id"
)]
ToShift,
}
impl Related<super::shift::Entity> for Entity {
fn to() -> RelationDef {
Relation::FromShift.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -46,5 +46,8 @@ pub mod vital_signs;
pub mod care_plan;
pub mod care_plan_item;
pub mod care_plan_outcome;
pub mod shift;
pub mod patient_assignment;
pub mod handoff_log;
pub mod vital_signs_daily;
pub mod vital_signs_hourly;

View File

@@ -0,0 +1,55 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "patient_assignments")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
pub shift_id: Uuid,
pub patient_id: Uuid,
pub care_level: String,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub created_by: Option<Uuid>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub updated_by: Option<Uuid>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::shift::Entity",
from = "Column::ShiftId",
to = "super::shift::Column::Id"
)]
Shift,
#[sea_orm(
belongs_to = "super::patient::Entity",
from = "Column::PatientId",
to = "super::patient::Column::Id"
)]
Patient,
}
impl Related<super::shift::Entity> for Entity {
fn to() -> RelationDef {
Relation::Shift.def()
}
}
impl Related<super::patient::Entity> for Entity {
fn to() -> RelationDef {
Relation::Patient.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,53 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "shifts")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
pub shift_date: chrono::NaiveDate,
/// 班次时段: morning / afternoon / night
pub period: String,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub nurse_id: Option<Uuid>,
/// 班次状态: scheduled / in_progress / completed
pub status: String,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub created_by: Option<Uuid>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub updated_by: Option<Uuid>,
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::patient_assignment::Entity")]
PatientAssignments,
#[sea_orm(has_many = "super::handoff_log::Entity")]
HandoffFrom,
#[sea_orm(has_many = "super::handoff_log::Entity")]
HandoffTo,
}
impl Related<super::patient_assignment::Entity> for Entity {
fn to() -> RelationDef {
Relation::PatientAssignments.def()
}
}
impl Related<super::handoff_log::Entity> for Entity {
fn to() -> RelationDef {
Relation::HandoffFrom.def()
}
}
impl ActiveModelBehavior for ActiveModel {}