Files
hms/crates/erp-health/src/entity/medication_record.rs
iven bab0d6619b
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
feat(health): 用药记录实体 — CRUD 全栈
- 迁移 080: medication_record 表(18 字段 + 频率/给药途径校验)
- Entity/DTO/Service/Handler 全链路
- 端点: GET/POST/PUT/DELETE /health/medications + /health/patients/{id}/medications
- 软删除 + 乐观锁 + 审计日志
2026-04-27 11:45:49 +08:00

71 lines
2.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
/// 用药记录实体 — 记录患者当前和历史的用药情况
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "medication_record")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
pub patient_id: Uuid,
/// 药品名称(商品名)
pub medication_name: String,
/// 通用名
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub generic_name: Option<String>,
/// 剂量(如 500mg
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub dosage: Option<String>,
/// 单位(如 mg/ml/片)
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>,
/// 用药频率: daily/bid/tid/qid/prn
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub frequency: Option<String>,
/// 给药途径: oral/injection/topical/inhalation
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub route: Option<String>,
/// 开始日期
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub start_date: Option<chrono::NaiveDate>,
/// 结束日期
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub end_date: Option<chrono::NaiveDate>,
/// 是否当前用药
pub is_current: bool,
/// 开方医生 ID
#[sea_orm(skip_serializing_if = "Option::is_none")]
pub prescribed_by: Option<Uuid>,
/// 备注PII 加密存储)
#[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::patient::Entity",
from = "Column::PatientId",
to = "super::patient::Column::Id"
)]
Patient,
}
impl Related<super::patient::Entity> for Entity {
fn to() -> RelationDef {
Relation::Patient.def()
}
}
impl ActiveModelBehavior for ActiveModel {}