feat(health): V2 血透专科数据模型 — dialysis_record + lab_report 审阅流程
- 新增 dialysis_record 表和完整 CRUD API(透析日期/体重/血压/超滤量/透析类型/症状)
- ALTER lab_report 增加 source/status/reviewed_by/reviewed_at 字段
- 重命名 lab_report: indicators→items, doctor_interpretation→doctor_notes
- 新增透析记录审阅端点 PUT /dialysis-records/{id}/review
- 新增化验报告审阅端点 PUT /patients/{id}/lab-reports/{rid}/review
- 化验报告 items JSON 支持 V2 结构(name/value/unit/reference/is_abnormal)
- 迁移 m000051 含完整 up/down 回滚
- 94 个后端测试全部通过,API 全链路验证通过
This commit is contained in:
124
crates/erp-health/src/dto/dialysis_dto.rs
Normal file
124
crates/erp-health/src/dto/dialysis_dto.rs
Normal file
@@ -0,0 +1,124 @@
|
||||
use chrono::NaiveDate;
|
||||
use chrono::NaiveTime;
|
||||
use erp_core::sanitize::sanitize_option;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
type Decimal = f64;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 透析记录
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct CreateDialysisRecordReq {
|
||||
pub patient_id: Uuid,
|
||||
pub dialysis_date: NaiveDate,
|
||||
pub start_time: Option<NaiveTime>,
|
||||
pub end_time: Option<NaiveTime>,
|
||||
pub dry_weight: Option<Decimal>,
|
||||
pub pre_weight: Option<Decimal>,
|
||||
pub post_weight: Option<Decimal>,
|
||||
pub pre_bp_systolic: Option<i32>,
|
||||
pub pre_bp_diastolic: Option<i32>,
|
||||
pub post_bp_systolic: Option<i32>,
|
||||
pub post_bp_diastolic: Option<i32>,
|
||||
pub pre_heart_rate: Option<i32>,
|
||||
pub post_heart_rate: Option<i32>,
|
||||
pub ultrafiltration_volume: Option<i32>,
|
||||
pub dialysis_duration: Option<i32>,
|
||||
pub blood_flow_rate: Option<i32>,
|
||||
/// HD / HDF / HF
|
||||
#[serde(default = "default_dialysis_type")]
|
||||
pub dialysis_type: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub symptoms: Option<serde_json::Value>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub complication_notes: Option<String>,
|
||||
}
|
||||
|
||||
fn default_dialysis_type() -> String {
|
||||
"HD".to_string()
|
||||
}
|
||||
|
||||
impl CreateDialysisRecordReq {
|
||||
pub fn sanitize(&mut self) {
|
||||
self.complication_notes = sanitize_option(self.complication_notes.take());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UpdateDialysisRecordReq {
|
||||
pub dialysis_date: Option<NaiveDate>,
|
||||
pub start_time: Option<NaiveTime>,
|
||||
pub end_time: Option<NaiveTime>,
|
||||
pub dry_weight: Option<Decimal>,
|
||||
pub pre_weight: Option<Decimal>,
|
||||
pub post_weight: Option<Decimal>,
|
||||
pub pre_bp_systolic: Option<i32>,
|
||||
pub pre_bp_diastolic: Option<i32>,
|
||||
pub post_bp_systolic: Option<i32>,
|
||||
pub post_bp_diastolic: Option<i32>,
|
||||
pub pre_heart_rate: Option<i32>,
|
||||
pub post_heart_rate: Option<i32>,
|
||||
pub ultrafiltration_volume: Option<i32>,
|
||||
pub dialysis_duration: Option<i32>,
|
||||
pub blood_flow_rate: Option<i32>,
|
||||
pub dialysis_type: Option<String>,
|
||||
pub symptoms: Option<serde_json::Value>,
|
||||
pub complication_notes: Option<String>,
|
||||
}
|
||||
|
||||
impl UpdateDialysisRecordReq {
|
||||
pub fn sanitize(&mut self) {
|
||||
self.complication_notes = sanitize_option(self.complication_notes.take());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct DialysisRecordResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub dialysis_date: NaiveDate,
|
||||
pub start_time: Option<NaiveTime>,
|
||||
pub end_time: Option<NaiveTime>,
|
||||
pub dry_weight: Option<Decimal>,
|
||||
pub pre_weight: Option<Decimal>,
|
||||
pub post_weight: Option<Decimal>,
|
||||
pub pre_bp_systolic: Option<i32>,
|
||||
pub pre_bp_diastolic: Option<i32>,
|
||||
pub post_bp_systolic: Option<i32>,
|
||||
pub post_bp_diastolic: Option<i32>,
|
||||
pub pre_heart_rate: Option<i32>,
|
||||
pub post_heart_rate: Option<i32>,
|
||||
pub ultrafiltration_volume: Option<i32>,
|
||||
pub dialysis_duration: Option<i32>,
|
||||
pub blood_flow_rate: Option<i32>,
|
||||
pub dialysis_type: String,
|
||||
pub symptoms: Option<serde_json::Value>,
|
||||
pub complication_notes: Option<String>,
|
||||
pub status: String,
|
||||
pub reviewed_by: Option<Uuid>,
|
||||
pub reviewed_at: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub updated_at: chrono::DateTime<chrono::Utc>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 化验报告审阅
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct ReviewLabReportReq {
|
||||
pub doctor_notes: Option<String>,
|
||||
/// 审阅时可选覆盖 items(补充标注 is_abnormal)
|
||||
pub items: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl ReviewLabReportReq {
|
||||
pub fn sanitize(&mut self) {
|
||||
self.doctor_notes = sanitize_option(self.doctor_notes.take());
|
||||
}
|
||||
}
|
||||
@@ -76,14 +76,17 @@ pub struct VitalSignsResp {
|
||||
pub struct CreateLabReportReq {
|
||||
pub report_date: NaiveDate,
|
||||
pub report_type: String,
|
||||
pub indicators: Option<serde_json::Value>,
|
||||
/// manual_input / photo_upload
|
||||
pub source: Option<String>,
|
||||
/// V2 JSON 结构: [{name, value, unit, reference_low, reference_high, is_abnormal}]
|
||||
pub items: Option<serde_json::Value>,
|
||||
pub image_urls: Option<serde_json::Value>,
|
||||
pub doctor_interpretation: Option<String>,
|
||||
pub doctor_notes: Option<String>,
|
||||
}
|
||||
|
||||
impl CreateLabReportReq {
|
||||
pub fn sanitize(&mut self) {
|
||||
self.doctor_interpretation = sanitize_option(self.doctor_interpretation.take());
|
||||
self.doctor_notes = sanitize_option(self.doctor_notes.take());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,14 +94,15 @@ impl CreateLabReportReq {
|
||||
pub struct UpdateLabReportReq {
|
||||
pub report_date: Option<NaiveDate>,
|
||||
pub report_type: Option<String>,
|
||||
pub indicators: Option<serde_json::Value>,
|
||||
pub source: Option<String>,
|
||||
pub items: Option<serde_json::Value>,
|
||||
pub image_urls: Option<serde_json::Value>,
|
||||
pub doctor_interpretation: Option<String>,
|
||||
pub doctor_notes: Option<String>,
|
||||
}
|
||||
|
||||
impl UpdateLabReportReq {
|
||||
pub fn sanitize(&mut self) {
|
||||
self.doctor_interpretation = sanitize_option(self.doctor_interpretation.take());
|
||||
self.doctor_notes = sanitize_option(self.doctor_notes.take());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +112,13 @@ pub struct LabReportResp {
|
||||
pub patient_id: Uuid,
|
||||
pub report_date: NaiveDate,
|
||||
pub report_type: String,
|
||||
pub indicators: Option<serde_json::Value>,
|
||||
pub source: Option<String>,
|
||||
pub items: Option<serde_json::Value>,
|
||||
pub image_urls: Option<serde_json::Value>,
|
||||
pub doctor_interpretation: Option<String>,
|
||||
pub doctor_notes: Option<String>,
|
||||
pub status: String,
|
||||
pub reviewed_by: Option<Uuid>,
|
||||
pub reviewed_at: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub updated_at: chrono::DateTime<chrono::Utc>,
|
||||
pub version: i32,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod appointment_dto;
|
||||
pub mod article_dto;
|
||||
pub mod consultation_dto;
|
||||
pub mod dialysis_dto;
|
||||
pub mod doctor_dto;
|
||||
pub mod follow_up_dto;
|
||||
pub mod health_data_dto;
|
||||
|
||||
79
crates/erp-health/src/entity/dialysis_record.rs
Normal file
79
crates/erp-health/src/entity/dialysis_record.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "dialysis_record")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub dialysis_date: chrono::NaiveDate,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub start_time: Option<chrono::NaiveTime>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub end_time: Option<chrono::NaiveTime>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub dry_weight: Option<Decimal>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub pre_weight: Option<Decimal>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub post_weight: Option<Decimal>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub pre_bp_systolic: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub pre_bp_diastolic: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub post_bp_systolic: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub post_bp_diastolic: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub pre_heart_rate: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub post_heart_rate: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub ultrafiltration_volume: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub dialysis_duration: Option<i32>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub blood_flow_rate: Option<i32>,
|
||||
/// HD / HDF / HF
|
||||
pub dialysis_type: String,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub symptoms: Option<serde_json::Value>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub complication_notes: Option<String>,
|
||||
/// draft / completed / reviewed
|
||||
pub status: String,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub reviewed_by: Option<Uuid>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub reviewed_at: Option<DateTimeUtc>,
|
||||
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 {}
|
||||
@@ -9,13 +9,24 @@ pub struct Model {
|
||||
pub tenant_id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub report_date: chrono::NaiveDate,
|
||||
/// kidney_function / blood_routine / electrolyte / liver_function / other
|
||||
pub report_type: String,
|
||||
/// manual_input / photo_upload
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub indicators: Option<serde_json::Value>,
|
||||
pub source: Option<String>,
|
||||
/// V2 JSON 结构: [{name, value, unit, reference_low, reference_high, is_abnormal}]
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub items: Option<serde_json::Value>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub image_urls: Option<serde_json::Value>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub doctor_interpretation: Option<String>,
|
||||
pub doctor_notes: Option<String>,
|
||||
/// pending / reviewed
|
||||
pub status: String,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub reviewed_by: Option<Uuid>,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
pub reviewed_at: Option<DateTimeUtc>,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||
|
||||
@@ -2,6 +2,7 @@ pub mod appointment;
|
||||
pub mod article;
|
||||
pub mod consultation_message;
|
||||
pub mod consultation_session;
|
||||
pub mod dialysis_record;
|
||||
pub mod doctor_profile;
|
||||
pub mod doctor_schedule;
|
||||
pub mod follow_up_record;
|
||||
|
||||
@@ -23,6 +23,9 @@ pub enum HealthError {
|
||||
#[error("化验报告不存在")]
|
||||
LabReportNotFound,
|
||||
|
||||
#[error("透析记录不存在")]
|
||||
DialysisRecordNotFound,
|
||||
|
||||
#[error("健康档案不存在")]
|
||||
HealthRecordNotFound,
|
||||
|
||||
@@ -64,6 +67,7 @@ impl From<HealthError> for AppError {
|
||||
| HealthError::ScheduleNotFound
|
||||
| HealthError::VitalSignsNotFound
|
||||
| HealthError::LabReportNotFound
|
||||
| HealthError::DialysisRecordNotFound
|
||||
| HealthError::HealthRecordNotFound
|
||||
| HealthError::FamilyMemberNotFound
|
||||
| HealthError::TagNotFound
|
||||
|
||||
144
crates/erp-health/src/handler/dialysis_handler.rs
Normal file
144
crates/erp-health/src/handler/dialysis_handler.rs
Normal file
@@ -0,0 +1,144 @@
|
||||
use axum::Extension;
|
||||
use axum::extract::{FromRef, Json, Path, Query, State};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
use uuid::Uuid;
|
||||
|
||||
use erp_core::error::AppError;
|
||||
use erp_core::rbac::require_permission;
|
||||
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
|
||||
|
||||
use crate::dto::dialysis_dto::*;
|
||||
use crate::dto::DeleteWithVersion;
|
||||
use crate::service::dialysis_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PaginationParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateDialysisWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: UpdateDialysisRecordReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct ReviewDialysisWithVersion {
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
pub async fn list_dialysis_records<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<DialysisRecordResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.list")?;
|
||||
let page = params.page.unwrap_or(1);
|
||||
let page_size = params.page_size.unwrap_or(20);
|
||||
let result = dialysis_service::list_dialysis_records(
|
||||
&state, ctx.tenant_id, patient_id, page, page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn get_dialysis_record<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(record_id): Path<Uuid>,
|
||||
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.list")?;
|
||||
let result = dialysis_service::get_dialysis_record(
|
||||
&state, ctx.tenant_id, record_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn create_dialysis_record<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateDialysisRecordReq>,
|
||||
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.manage")?;
|
||||
let mut req = req;
|
||||
req.sanitize();
|
||||
let result = dialysis_service::create_dialysis_record(
|
||||
&state, ctx.tenant_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn update_dialysis_record<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(record_id): Path<Uuid>,
|
||||
Json(req): Json<UpdateDialysisWithVersion>,
|
||||
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.manage")?;
|
||||
let mut data = req.data;
|
||||
data.sanitize();
|
||||
let result = dialysis_service::update_dialysis_record(
|
||||
&state, ctx.tenant_id, record_id, Some(ctx.user_id), data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn review_dialysis_record<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(record_id): Path<Uuid>,
|
||||
Json(req): Json<ReviewDialysisWithVersion>,
|
||||
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.manage")?;
|
||||
let result = dialysis_service::review_dialysis_record(
|
||||
&state, ctx.tenant_id, record_id, ctx.user_id, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn delete_dialysis_record<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(record_id): Path<Uuid>,
|
||||
Json(req): Json<DeleteWithVersion>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.manage")?;
|
||||
dialysis_service::delete_dialysis_record(
|
||||
&state, ctx.tenant_id, record_id, Some(ctx.user_id), req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use erp_core::rbac::require_permission;
|
||||
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
|
||||
|
||||
use crate::dto::health_data_dto::*;
|
||||
use crate::dto::dialysis_dto::ReviewLabReportReq;
|
||||
use crate::dto::DeleteWithVersion;
|
||||
use crate::service::health_data_service;
|
||||
use crate::service::trend_service;
|
||||
@@ -200,6 +201,26 @@ where
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
pub async fn review_lab_report<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, rid)): Path<(Uuid, Uuid)>,
|
||||
Json(req): Json<ReviewLabReportWithVersion>,
|
||||
) -> Result<Json<ApiResponse<LabReportResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.health-data.manage")?;
|
||||
let mut data = req.data;
|
||||
data.sanitize();
|
||||
let result = health_data_service::review_lab_report(
|
||||
&state, ctx.tenant_id, _patient_id, rid, ctx.user_id, data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 健康档案
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -404,3 +425,10 @@ pub struct UpdateHealthRecordWithVersion {
|
||||
pub data: UpdateHealthRecordReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct ReviewLabReportWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: ReviewLabReportReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod appointment_handler;
|
||||
pub mod article_handler;
|
||||
pub mod consultation_handler;
|
||||
pub mod dialysis_handler;
|
||||
pub mod doctor_handler;
|
||||
pub mod follow_up_handler;
|
||||
pub mod health_data_handler;
|
||||
|
||||
@@ -6,7 +6,7 @@ use erp_core::events::EventBus;
|
||||
use erp_core::module::{ErpModule, PermissionDescriptor};
|
||||
|
||||
use crate::handler::{
|
||||
appointment_handler, article_handler, consultation_handler, doctor_handler, follow_up_handler,
|
||||
appointment_handler, article_handler, consultation_handler, dialysis_handler, doctor_handler, follow_up_handler,
|
||||
health_data_handler, patient_handler,
|
||||
};
|
||||
|
||||
@@ -144,6 +144,30 @@ impl HealthModule {
|
||||
"/health/vital-signs/today",
|
||||
axum::routing::get(health_data_handler::get_mini_today),
|
||||
)
|
||||
// 透析记录(血透专科)
|
||||
.route(
|
||||
"/health/patients/{id}/dialysis-records",
|
||||
axum::routing::get(dialysis_handler::list_dialysis_records),
|
||||
)
|
||||
.route(
|
||||
"/health/dialysis-records",
|
||||
axum::routing::post(dialysis_handler::create_dialysis_record),
|
||||
)
|
||||
.route(
|
||||
"/health/dialysis-records/{id}",
|
||||
axum::routing::get(dialysis_handler::get_dialysis_record)
|
||||
.put(dialysis_handler::update_dialysis_record)
|
||||
.delete(dialysis_handler::delete_dialysis_record),
|
||||
)
|
||||
.route(
|
||||
"/health/dialysis-records/{id}/review",
|
||||
axum::routing::put(dialysis_handler::review_dialysis_record),
|
||||
)
|
||||
// 化验报告审阅
|
||||
.route(
|
||||
"/health/patients/{id}/lab-reports/{rid}/review",
|
||||
axum::routing::put(health_data_handler::review_lab_report),
|
||||
)
|
||||
// 预约排班
|
||||
.route(
|
||||
"/health/appointments",
|
||||
|
||||
286
crates/erp-health/src/service/dialysis_service.rs
Normal file
286
crates/erp-health/src/service/dialysis_service.rs
Normal file
@@ -0,0 +1,286 @@
|
||||
//! 透析记录 Service — 血透专科 CRUD + 审阅
|
||||
|
||||
use chrono::Utc;
|
||||
use erp_core::audit::AuditLog;
|
||||
use erp_core::audit_service;
|
||||
use num_traits::ToPrimitive;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::{ActiveValue::Set, QueryOrder, QuerySelect};
|
||||
use uuid::Uuid;
|
||||
|
||||
use erp_core::error::check_version;
|
||||
use erp_core::types::PaginatedResponse;
|
||||
|
||||
use crate::dto::dialysis_dto::*;
|
||||
use crate::entity::{dialysis_record, patient};
|
||||
use crate::error::{HealthError, HealthResult};
|
||||
use crate::state::HealthState;
|
||||
|
||||
pub async fn list_dialysis_records(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
patient_id: Uuid,
|
||||
page: u64,
|
||||
page_size: u64,
|
||||
) -> HealthResult<PaginatedResponse<DialysisRecordResp>> {
|
||||
let limit = page_size.min(100);
|
||||
let offset = page.saturating_sub(1) * limit;
|
||||
|
||||
let query = dialysis_record::Entity::find()
|
||||
.filter(dialysis_record::Column::TenantId.eq(tenant_id))
|
||||
.filter(dialysis_record::Column::PatientId.eq(patient_id))
|
||||
.filter(dialysis_record::Column::DeletedAt.is_null());
|
||||
|
||||
let total = query.clone().count(&state.db).await?;
|
||||
let models = query
|
||||
.order_by_desc(dialysis_record::Column::DialysisDate)
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.all(&state.db)
|
||||
.await?;
|
||||
|
||||
let total_pages = total.div_ceil(limit.max(1));
|
||||
let data: Vec<DialysisRecordResp> = models.into_iter().map(to_resp).collect();
|
||||
|
||||
Ok(PaginatedResponse { data, total, page, page_size: limit, total_pages })
|
||||
}
|
||||
|
||||
pub async fn get_dialysis_record(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
record_id: Uuid,
|
||||
) -> HealthResult<DialysisRecordResp> {
|
||||
let m = dialysis_record::Entity::find()
|
||||
.filter(dialysis_record::Column::Id.eq(record_id))
|
||||
.filter(dialysis_record::Column::TenantId.eq(tenant_id))
|
||||
.filter(dialysis_record::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?
|
||||
.ok_or(HealthError::DialysisRecordNotFound)?;
|
||||
|
||||
Ok(to_resp(m))
|
||||
}
|
||||
|
||||
pub async fn create_dialysis_record(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
operator_id: Option<Uuid>,
|
||||
req: CreateDialysisRecordReq,
|
||||
) -> HealthResult<DialysisRecordResp> {
|
||||
patient::Entity::find()
|
||||
.filter(patient::Column::Id.eq(req.patient_id))
|
||||
.filter(patient::Column::TenantId.eq(tenant_id))
|
||||
.filter(patient::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?
|
||||
.ok_or(HealthError::PatientNotFound)?;
|
||||
|
||||
validate_dialysis_type(&req.dialysis_type)?;
|
||||
|
||||
let now = Utc::now();
|
||||
let active = dialysis_record::ActiveModel {
|
||||
id: Set(Uuid::now_v7()),
|
||||
tenant_id: Set(tenant_id),
|
||||
patient_id: Set(req.patient_id),
|
||||
dialysis_date: Set(req.dialysis_date),
|
||||
start_time: Set(req.start_time),
|
||||
end_time: Set(req.end_time),
|
||||
dry_weight: Set(req.dry_weight.map(|v| Decimal::from_f64_retain(v).unwrap_or_default())),
|
||||
pre_weight: Set(req.pre_weight.map(|v| Decimal::from_f64_retain(v).unwrap_or_default())),
|
||||
post_weight: Set(req.post_weight.map(|v| Decimal::from_f64_retain(v).unwrap_or_default())),
|
||||
pre_bp_systolic: Set(req.pre_bp_systolic),
|
||||
pre_bp_diastolic: Set(req.pre_bp_diastolic),
|
||||
post_bp_systolic: Set(req.post_bp_systolic),
|
||||
post_bp_diastolic: Set(req.post_bp_diastolic),
|
||||
pre_heart_rate: Set(req.pre_heart_rate),
|
||||
post_heart_rate: Set(req.post_heart_rate),
|
||||
ultrafiltration_volume: Set(req.ultrafiltration_volume),
|
||||
dialysis_duration: Set(req.dialysis_duration),
|
||||
blood_flow_rate: Set(req.blood_flow_rate),
|
||||
dialysis_type: Set(req.dialysis_type),
|
||||
symptoms: Set(req.symptoms),
|
||||
complication_notes: Set(req.complication_notes),
|
||||
status: Set("draft".to_string()),
|
||||
reviewed_by: Set(None),
|
||||
reviewed_at: Set(None),
|
||||
created_at: Set(now),
|
||||
updated_at: Set(now),
|
||||
created_by: Set(operator_id),
|
||||
updated_by: Set(operator_id),
|
||||
deleted_at: Set(None),
|
||||
version: Set(1),
|
||||
};
|
||||
let m = active.insert(&state.db).await?;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, operator_id, "dialysis_record.created", "dialysis_record")
|
||||
.with_resource_id(m.id),
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(to_resp(m))
|
||||
}
|
||||
|
||||
pub async fn update_dialysis_record(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
record_id: Uuid,
|
||||
operator_id: Option<Uuid>,
|
||||
req: UpdateDialysisRecordReq,
|
||||
expected_version: i32,
|
||||
) -> HealthResult<DialysisRecordResp> {
|
||||
let model = dialysis_record::Entity::find()
|
||||
.filter(dialysis_record::Column::Id.eq(record_id))
|
||||
.filter(dialysis_record::Column::TenantId.eq(tenant_id))
|
||||
.filter(dialysis_record::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?
|
||||
.ok_or(HealthError::DialysisRecordNotFound)?;
|
||||
|
||||
let next_ver = check_version(expected_version, model.version)
|
||||
.map_err(|_| HealthError::VersionMismatch)?;
|
||||
|
||||
let mut active: dialysis_record::ActiveModel = model.into();
|
||||
if let Some(v) = req.dialysis_date { active.dialysis_date = Set(v); }
|
||||
if let Some(v) = req.start_time { active.start_time = Set(Some(v)); }
|
||||
if let Some(v) = req.end_time { active.end_time = Set(Some(v)); }
|
||||
if let Some(v) = req.dry_weight { active.dry_weight = Set(Some(Decimal::from_f64_retain(v).unwrap_or_default())); }
|
||||
if let Some(v) = req.pre_weight { active.pre_weight = Set(Some(Decimal::from_f64_retain(v).unwrap_or_default())); }
|
||||
if let Some(v) = req.post_weight { active.post_weight = Set(Some(Decimal::from_f64_retain(v).unwrap_or_default())); }
|
||||
if let Some(v) = req.pre_bp_systolic { active.pre_bp_systolic = Set(Some(v)); }
|
||||
if let Some(v) = req.pre_bp_diastolic { active.pre_bp_diastolic = Set(Some(v)); }
|
||||
if let Some(v) = req.post_bp_systolic { active.post_bp_systolic = Set(Some(v)); }
|
||||
if let Some(v) = req.post_bp_diastolic { active.post_bp_diastolic = Set(Some(v)); }
|
||||
if let Some(v) = req.pre_heart_rate { active.pre_heart_rate = Set(Some(v)); }
|
||||
if let Some(v) = req.post_heart_rate { active.post_heart_rate = Set(Some(v)); }
|
||||
if let Some(v) = req.ultrafiltration_volume { active.ultrafiltration_volume = Set(Some(v)); }
|
||||
if let Some(v) = req.dialysis_duration { active.dialysis_duration = Set(Some(v)); }
|
||||
if let Some(v) = req.blood_flow_rate { active.blood_flow_rate = Set(Some(v)); }
|
||||
if let Some(ref v) = req.dialysis_type { validate_dialysis_type(v)?; active.dialysis_type = Set(v.clone()); }
|
||||
if let Some(v) = req.symptoms { active.symptoms = Set(Some(v)); }
|
||||
if let Some(v) = req.complication_notes { active.complication_notes = Set(Some(v)); }
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.updated_by = Set(operator_id);
|
||||
active.version = Set(next_ver);
|
||||
|
||||
let m = active.update(&state.db).await?;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, operator_id, "dialysis_record.updated", "dialysis_record")
|
||||
.with_resource_id(m.id),
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(to_resp(m))
|
||||
}
|
||||
|
||||
pub async fn review_dialysis_record(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
record_id: Uuid,
|
||||
reviewer_id: Uuid,
|
||||
expected_version: i32,
|
||||
) -> HealthResult<DialysisRecordResp> {
|
||||
let model = dialysis_record::Entity::find()
|
||||
.filter(dialysis_record::Column::Id.eq(record_id))
|
||||
.filter(dialysis_record::Column::TenantId.eq(tenant_id))
|
||||
.filter(dialysis_record::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?
|
||||
.ok_or(HealthError::DialysisRecordNotFound)?;
|
||||
|
||||
let next_ver = check_version(expected_version, model.version)
|
||||
.map_err(|_| HealthError::VersionMismatch)?;
|
||||
|
||||
let mut active: dialysis_record::ActiveModel = model.into();
|
||||
active.status = Set("reviewed".to_string());
|
||||
active.reviewed_by = Set(Some(reviewer_id));
|
||||
active.reviewed_at = Set(Some(Utc::now()));
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.updated_by = Set(Some(reviewer_id));
|
||||
active.version = Set(next_ver);
|
||||
|
||||
let m = active.update(&state.db).await?;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(reviewer_id), "dialysis_record.reviewed", "dialysis_record")
|
||||
.with_resource_id(m.id),
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(to_resp(m))
|
||||
}
|
||||
|
||||
pub async fn delete_dialysis_record(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
record_id: Uuid,
|
||||
operator_id: Option<Uuid>,
|
||||
expected_version: i32,
|
||||
) -> HealthResult<()> {
|
||||
let model = dialysis_record::Entity::find()
|
||||
.filter(dialysis_record::Column::Id.eq(record_id))
|
||||
.filter(dialysis_record::Column::TenantId.eq(tenant_id))
|
||||
.filter(dialysis_record::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?
|
||||
.ok_or(HealthError::DialysisRecordNotFound)?;
|
||||
|
||||
let next_ver = check_version(expected_version, model.version)
|
||||
.map_err(|_| HealthError::VersionMismatch)?;
|
||||
|
||||
let mut active: dialysis_record::ActiveModel = model.into();
|
||||
active.deleted_at = Set(Some(Utc::now()));
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.updated_by = Set(operator_id);
|
||||
active.version = Set(next_ver);
|
||||
active.update(&state.db).await?;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, operator_id, "dialysis_record.deleted", "dialysis_record")
|
||||
.with_resource_id(record_id),
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_dialysis_type(dialysis_type: &str) -> HealthResult<()> {
|
||||
match dialysis_type {
|
||||
"HD" | "HDF" | "HF" => Ok(()),
|
||||
_ => Err(HealthError::Validation(format!(
|
||||
"无效的透析类型: {},允许值: HD, HDF, HF", dialysis_type
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_resp(m: dialysis_record::Model) -> DialysisRecordResp {
|
||||
DialysisRecordResp {
|
||||
id: m.id,
|
||||
patient_id: m.patient_id,
|
||||
dialysis_date: m.dialysis_date,
|
||||
start_time: m.start_time,
|
||||
end_time: m.end_time,
|
||||
dry_weight: m.dry_weight.map(|d| d.to_f64().unwrap_or(0.0)),
|
||||
pre_weight: m.pre_weight.map(|d| d.to_f64().unwrap_or(0.0)),
|
||||
post_weight: m.post_weight.map(|d| d.to_f64().unwrap_or(0.0)),
|
||||
pre_bp_systolic: m.pre_bp_systolic,
|
||||
pre_bp_diastolic: m.pre_bp_diastolic,
|
||||
post_bp_systolic: m.post_bp_systolic,
|
||||
post_bp_diastolic: m.post_bp_diastolic,
|
||||
pre_heart_rate: m.pre_heart_rate,
|
||||
post_heart_rate: m.post_heart_rate,
|
||||
ultrafiltration_volume: m.ultrafiltration_volume,
|
||||
dialysis_duration: m.dialysis_duration,
|
||||
blood_flow_rate: m.blood_flow_rate,
|
||||
dialysis_type: m.dialysis_type,
|
||||
symptoms: m.symptoms,
|
||||
complication_notes: m.complication_notes,
|
||||
status: m.status,
|
||||
reviewed_by: m.reviewed_by,
|
||||
reviewed_at: m.reviewed_at,
|
||||
created_at: m.created_at,
|
||||
updated_at: m.updated_at,
|
||||
version: m.version,
|
||||
}
|
||||
}
|
||||
@@ -247,8 +247,9 @@ pub async fn list_lab_reports(
|
||||
let total_pages = total.div_ceil(limit.max(1));
|
||||
let data = models.into_iter().map(|m| LabReportResp {
|
||||
id: m.id, patient_id: m.patient_id, report_date: m.report_date,
|
||||
report_type: m.report_type, indicators: m.indicators,
|
||||
image_urls: m.image_urls, doctor_interpretation: m.doctor_interpretation,
|
||||
report_type: m.report_type, source: m.source,
|
||||
items: m.items, image_urls: m.image_urls, doctor_notes: m.doctor_notes,
|
||||
status: m.status, reviewed_by: m.reviewed_by, reviewed_at: m.reviewed_at,
|
||||
created_at: m.created_at, updated_at: m.updated_at, version: m.version,
|
||||
}).collect();
|
||||
|
||||
@@ -278,9 +279,13 @@ pub async fn create_lab_report(
|
||||
patient_id: Set(patient_id),
|
||||
report_date: Set(req.report_date),
|
||||
report_type: Set(req.report_type),
|
||||
indicators: Set(req.indicators),
|
||||
source: Set(req.source),
|
||||
items: Set(req.items),
|
||||
image_urls: Set(req.image_urls),
|
||||
doctor_interpretation: Set(req.doctor_interpretation),
|
||||
doctor_notes: Set(req.doctor_notes),
|
||||
status: Set("pending".to_string()),
|
||||
reviewed_by: Set(None),
|
||||
reviewed_at: Set(None),
|
||||
created_at: Set(now),
|
||||
updated_at: Set(now),
|
||||
created_by: Set(operator_id),
|
||||
@@ -305,8 +310,9 @@ pub async fn create_lab_report(
|
||||
|
||||
Ok(LabReportResp {
|
||||
id: m.id, patient_id: m.patient_id, report_date: m.report_date,
|
||||
report_type: m.report_type, indicators: m.indicators,
|
||||
image_urls: m.image_urls, doctor_interpretation: m.doctor_interpretation,
|
||||
report_type: m.report_type, source: m.source,
|
||||
items: m.items, image_urls: m.image_urls, doctor_notes: m.doctor_notes,
|
||||
status: m.status, reviewed_by: m.reviewed_by, reviewed_at: m.reviewed_at,
|
||||
created_at: m.created_at, updated_at: m.updated_at, version: m.version,
|
||||
})
|
||||
}
|
||||
@@ -334,9 +340,10 @@ pub async fn update_lab_report(
|
||||
let mut active: lab_report::ActiveModel = model.into();
|
||||
if let Some(v) = req.report_date { active.report_date = Set(v); }
|
||||
if let Some(v) = req.report_type { active.report_type = Set(v); }
|
||||
if let Some(v) = req.indicators { active.indicators = Set(Some(v)); }
|
||||
if let Some(v) = req.source { active.source = Set(Some(v)); }
|
||||
if let Some(v) = req.items { active.items = Set(Some(v)); }
|
||||
if let Some(v) = req.image_urls { active.image_urls = Set(Some(v)); }
|
||||
if let Some(v) = req.doctor_interpretation { active.doctor_interpretation = Set(Some(v)); }
|
||||
if let Some(v) = req.doctor_notes { active.doctor_notes = Set(Some(v)); }
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.updated_by = Set(operator_id);
|
||||
active.version = Set(next_ver);
|
||||
@@ -351,8 +358,9 @@ pub async fn update_lab_report(
|
||||
|
||||
Ok(LabReportResp {
|
||||
id: m.id, patient_id: m.patient_id, report_date: m.report_date,
|
||||
report_type: m.report_type, indicators: m.indicators,
|
||||
image_urls: m.image_urls, doctor_interpretation: m.doctor_interpretation,
|
||||
report_type: m.report_type, source: m.source,
|
||||
items: m.items, image_urls: m.image_urls, doctor_notes: m.doctor_notes,
|
||||
status: m.status, reviewed_by: m.reviewed_by, reviewed_at: m.reviewed_at,
|
||||
created_at: m.created_at, updated_at: m.updated_at, version: m.version,
|
||||
})
|
||||
}
|
||||
@@ -391,6 +399,54 @@ pub async fn delete_lab_report(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn review_lab_report(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
patient_id: Uuid,
|
||||
report_id: Uuid,
|
||||
reviewer_id: Uuid,
|
||||
req: crate::dto::dialysis_dto::ReviewLabReportReq,
|
||||
expected_version: i32,
|
||||
) -> HealthResult<LabReportResp> {
|
||||
let model = lab_report::Entity::find()
|
||||
.filter(lab_report::Column::Id.eq(report_id))
|
||||
.filter(lab_report::Column::PatientId.eq(patient_id))
|
||||
.filter(lab_report::Column::TenantId.eq(tenant_id))
|
||||
.filter(lab_report::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?
|
||||
.ok_or(HealthError::LabReportNotFound)?;
|
||||
|
||||
let next_ver = check_version(expected_version, model.version)
|
||||
.map_err(|_| HealthError::VersionMismatch)?;
|
||||
|
||||
let mut active: lab_report::ActiveModel = model.into();
|
||||
active.status = Set("reviewed".to_string());
|
||||
active.reviewed_by = Set(Some(reviewer_id));
|
||||
active.reviewed_at = Set(Some(Utc::now()));
|
||||
if let Some(v) = req.doctor_notes { active.doctor_notes = Set(Some(v)); }
|
||||
if let Some(v) = req.items { active.items = Set(Some(v)); }
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.updated_by = Set(Some(reviewer_id));
|
||||
active.version = Set(next_ver);
|
||||
|
||||
let m = active.update(&state.db).await?;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(reviewer_id), "lab_report.reviewed", "lab_report")
|
||||
.with_resource_id(m.id),
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(LabReportResp {
|
||||
id: m.id, patient_id: m.patient_id, report_date: m.report_date,
|
||||
report_type: m.report_type, source: m.source,
|
||||
items: m.items, image_urls: m.image_urls, doctor_notes: m.doctor_notes,
|
||||
status: m.status, reviewed_by: m.reviewed_by, reviewed_at: m.reviewed_at,
|
||||
created_at: m.created_at, updated_at: m.updated_at, version: m.version,
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 体检记录 (Health Records)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod appointment_service;
|
||||
pub mod article_service;
|
||||
pub mod consultation_service;
|
||||
pub mod dialysis_service;
|
||||
pub mod doctor_service;
|
||||
pub mod follow_up_service;
|
||||
pub mod health_data_service;
|
||||
|
||||
@@ -50,6 +50,7 @@ mod m20260424_000047_health_index_fix;
|
||||
mod m20260425_000048_add_patient_id_number_hash;
|
||||
mod m20260425_000049_widen_patient_id_number;
|
||||
mod m20260425_00050_add_doctor_name_column;
|
||||
mod m20260425_000051_dialysis_and_lab_enhance;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -107,6 +108,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260425_000048_add_patient_id_number_hash::Migration),
|
||||
Box::new(m20260425_000049_widen_patient_id_number::Migration),
|
||||
Box::new(m20260425_00050_add_doctor_name_column::Migration),
|
||||
Box::new(m20260425_000051_dialysis_and_lab_enhance::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
/// V2 血透专科数据模型: dialysis_record 新表 + lab_report 增强审阅流程
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// 1. 创建 dialysis_record 表
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Alias::new("dialysis_record"))
|
||||
.if_not_exists()
|
||||
.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("dialysis_date")).date().not_null())
|
||||
.col(ColumnDef::new(Alias::new("start_time")).time())
|
||||
.col(ColumnDef::new(Alias::new("end_time")).time())
|
||||
// 体重 (Decimal 5,1)
|
||||
.col(ColumnDef::new(Alias::new("dry_weight")).decimal().extra("CHECK(dry_weight IS NULL OR dry_weight >= 0)"))
|
||||
.col(ColumnDef::new(Alias::new("pre_weight")).decimal().extra("CHECK(pre_weight IS NULL OR pre_weight >= 0)"))
|
||||
.col(ColumnDef::new(Alias::new("post_weight")).decimal().extra("CHECK(post_weight IS NULL OR post_weight >= 0)"))
|
||||
// 血压
|
||||
.col(ColumnDef::new(Alias::new("pre_bp_systolic")).integer())
|
||||
.col(ColumnDef::new(Alias::new("pre_bp_diastolic")).integer())
|
||||
.col(ColumnDef::new(Alias::new("post_bp_systolic")).integer())
|
||||
.col(ColumnDef::new(Alias::new("post_bp_diastolic")).integer())
|
||||
// 心率
|
||||
.col(ColumnDef::new(Alias::new("pre_heart_rate")).integer())
|
||||
.col(ColumnDef::new(Alias::new("post_heart_rate")).integer())
|
||||
// 透析参数
|
||||
.col(ColumnDef::new(Alias::new("ultrafiltration_volume")).integer())
|
||||
.col(ColumnDef::new(Alias::new("dialysis_duration")).integer())
|
||||
.col(ColumnDef::new(Alias::new("blood_flow_rate")).integer())
|
||||
// HD / HDF / HF
|
||||
.col(ColumnDef::new(Alias::new("dialysis_type")).string().not_null().default("HD"))
|
||||
.col(ColumnDef::new(Alias::new("symptoms")).json())
|
||||
.col(ColumnDef::new(Alias::new("complication_notes")).text())
|
||||
// draft / completed / reviewed
|
||||
.col(ColumnDef::new(Alias::new("status")).string().not_null().default("draft"))
|
||||
.col(ColumnDef::new(Alias::new("reviewed_by")).uuid())
|
||||
.col(ColumnDef::new(Alias::new("reviewed_at")).timestamp_with_time_zone())
|
||||
// 标准字段
|
||||
.col(ColumnDef::new(Alias::new("created_at")).timestamp_with_time_zone().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(Alias::new("updated_at")).timestamp_with_time_zone().not_null().default(Expr::current_timestamp()))
|
||||
.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?;
|
||||
|
||||
// dialysis_record 索引
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.if_not_exists()
|
||||
.name("idx_dialysis_record_tenant_patient")
|
||||
.table(Alias::new("dialysis_record"))
|
||||
.col(Alias::new("tenant_id"))
|
||||
.col(Alias::new("patient_id"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.if_not_exists()
|
||||
.name("idx_dialysis_record_date")
|
||||
.table(Alias::new("dialysis_record"))
|
||||
.col(Alias::new("dialysis_date"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 2. ALTER lab_report: 增加审阅流程字段
|
||||
// source: manual_input / photo_upload
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("lab_report"))
|
||||
.add_column(ColumnDef::new(Alias::new("source")).string().default("manual_input"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// status: pending / reviewed
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("lab_report"))
|
||||
.add_column(ColumnDef::new(Alias::new("status")).string().not_null().default("pending"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("lab_report"))
|
||||
.add_column(ColumnDef::new(Alias::new("reviewed_by")).uuid())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("lab_report"))
|
||||
.add_column(ColumnDef::new(Alias::new("reviewed_at")).timestamp_with_time_zone())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 重命名 indicators → items (V2 JSON 结构含 name/value/unit/reference_low/reference_high/is_abnormal)
|
||||
manager.get_connection().execute(sea_orm::Statement::from_string(
|
||||
sea_orm::DatabaseBackend::Postgres,
|
||||
"ALTER TABLE lab_report RENAME COLUMN indicators TO items".to_string(),
|
||||
)).await?;
|
||||
|
||||
// 重命名 doctor_interpretation → doctor_notes
|
||||
manager.get_connection().execute(sea_orm::Statement::from_string(
|
||||
sea_orm::DatabaseBackend::Postgres,
|
||||
"ALTER TABLE lab_report RENAME COLUMN doctor_interpretation TO doctor_notes".to_string(),
|
||||
)).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// 恢复 lab_report 列名
|
||||
manager.get_connection().execute(sea_orm::Statement::from_string(
|
||||
sea_orm::DatabaseBackend::Postgres,
|
||||
"ALTER TABLE lab_report RENAME COLUMN doctor_notes TO doctor_interpretation".to_string(),
|
||||
)).await?;
|
||||
|
||||
manager.get_connection().execute(sea_orm::Statement::from_string(
|
||||
sea_orm::DatabaseBackend::Postgres,
|
||||
"ALTER TABLE lab_report RENAME COLUMN items TO indicators".to_string(),
|
||||
)).await?;
|
||||
|
||||
// 删除新增列
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("lab_report"))
|
||||
.drop_column(Alias::new("reviewed_at"))
|
||||
.drop_column(Alias::new("reviewed_by"))
|
||||
.drop_column(Alias::new("status"))
|
||||
.drop_column(Alias::new("source"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 删除 dialysis_record 表
|
||||
manager
|
||||
.drop_table(Table::drop().table(Alias::new("dialysis_record")).if_exists().to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user