- 创建 erp-dialysis crate(DialysisState + DialysisError + DialysisModule) - 迁移 2 Entity + 2 Service + 2 Handler + 2 DTO 共 8 个文件 - Entity 移除跨 crate patient Relation(FK 列保留) - Service 内联 validation 逻辑,移除 patient 存在性检查(FK 约束保证) - erp-health 的 stats/consultation 中 dialysis 查询改为 raw SQL - ReviewLabReportReq 从 dialysis_dto 移至 health_data_dto(正确归属) - workspace 全量编译通过
145 lines
4.3 KiB
Rust
145 lines
4.3 KiB
Rust
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::DialysisState;
|
|
|
|
#[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<DialysisState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(patient_id): Path<Uuid>,
|
|
Query(params): Query<PaginationParams>,
|
|
) -> Result<Json<ApiResponse<PaginatedResponse<DialysisRecordResp>>>, AppError>
|
|
where
|
|
DialysisState: 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<DialysisState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(record_id): Path<Uuid>,
|
|
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
|
where
|
|
DialysisState: 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<DialysisState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Json(req): Json<CreateDialysisRecordReq>,
|
|
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
|
where
|
|
DialysisState: 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<DialysisState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(record_id): Path<Uuid>,
|
|
Json(req): Json<UpdateDialysisWithVersion>,
|
|
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
|
where
|
|
DialysisState: 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<DialysisState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(record_id): Path<Uuid>,
|
|
Json(req): Json<ReviewDialysisWithVersion>,
|
|
) -> Result<Json<ApiResponse<DialysisRecordResp>>, AppError>
|
|
where
|
|
DialysisState: 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<DialysisState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(record_id): Path<Uuid>,
|
|
Json(req): Json<DeleteWithVersion>,
|
|
) -> Result<Json<ApiResponse<()>>, AppError>
|
|
where
|
|
DialysisState: 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(())))
|
|
}
|