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:
51
crates/erp-health/src/entity/handoff_log.rs
Normal file
51
crates/erp-health/src/entity/handoff_log.rs
Normal 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 {}
|
||||
@@ -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;
|
||||
|
||||
55
crates/erp-health/src/entity/patient_assignment.rs
Normal file
55
crates/erp-health/src/entity/patient_assignment.rs
Normal 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 {}
|
||||
53
crates/erp-health/src/entity/shift.rs
Normal file
53
crates/erp-health/src/entity/shift.rs
Normal 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 {}
|
||||
Reference in New Issue
Block a user