新增透析方案实体和完整 CRUD: - Entity: 20 字段含抗凝/血管通路/透析参数 - DTO: f64 类型适配 utoipa ToSchema - Service: 抗凝类型 + 血管通路类型校验 - Handler: 5 端点 + RBAC 权限控制 - 路由: /api/v1/health/dialysis-prescriptions
120 lines
3.8 KiB
Rust
120 lines
3.8 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_prescription_dto::*;
|
|
use crate::dto::DeleteWithVersion;
|
|
use crate::service::dialysis_prescription_service;
|
|
use crate::state::HealthState;
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct DialysisPrescriptionListParams {
|
|
pub page: Option<u64>,
|
|
pub page_size: Option<u64>,
|
|
pub patient_id: Option<Uuid>,
|
|
pub status: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
|
pub struct UpdateDialysisPrescriptionWithVersion {
|
|
#[serde(flatten)]
|
|
pub data: UpdateDialysisPrescriptionReq,
|
|
pub version: i32,
|
|
}
|
|
|
|
pub async fn list_prescriptions<S>(
|
|
State(state): State<HealthState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Query(params): Query<DialysisPrescriptionListParams>,
|
|
) -> Result<Json<ApiResponse<PaginatedResponse<DialysisPrescriptionResp>>>, AppError>
|
|
where
|
|
HealthState: FromRef<S>,
|
|
S: Clone + Send + Sync + 'static,
|
|
{
|
|
require_permission(&ctx, "health.dialysis-prescription.list")?;
|
|
let page = params.page.unwrap_or(1);
|
|
let page_size = params.page_size.unwrap_or(20);
|
|
let result = dialysis_prescription_service::list_prescriptions(
|
|
&state, ctx.tenant_id, page, page_size, params.patient_id, params.status,
|
|
)
|
|
.await?;
|
|
Ok(Json(ApiResponse::ok(result)))
|
|
}
|
|
|
|
pub async fn get_prescription<S>(
|
|
State(state): State<HealthState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(id): Path<Uuid>,
|
|
) -> Result<Json<ApiResponse<DialysisPrescriptionResp>>, AppError>
|
|
where
|
|
HealthState: FromRef<S>,
|
|
S: Clone + Send + Sync + 'static,
|
|
{
|
|
require_permission(&ctx, "health.dialysis-prescription.list")?;
|
|
let result = dialysis_prescription_service::get_prescription(&state, ctx.tenant_id, id).await?;
|
|
Ok(Json(ApiResponse::ok(result)))
|
|
}
|
|
|
|
pub async fn create_prescription<S>(
|
|
State(state): State<HealthState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Json(req): Json<CreateDialysisPrescriptionReq>,
|
|
) -> Result<Json<ApiResponse<DialysisPrescriptionResp>>, AppError>
|
|
where
|
|
HealthState: FromRef<S>,
|
|
S: Clone + Send + Sync + 'static,
|
|
{
|
|
require_permission(&ctx, "health.dialysis-prescription.manage")?;
|
|
let mut req = req;
|
|
req.sanitize();
|
|
let result = dialysis_prescription_service::create_prescription(
|
|
&state, ctx.tenant_id, Some(ctx.user_id), req,
|
|
)
|
|
.await?;
|
|
Ok(Json(ApiResponse::ok(result)))
|
|
}
|
|
|
|
pub async fn update_prescription<S>(
|
|
State(state): State<HealthState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(id): Path<Uuid>,
|
|
Json(req): Json<UpdateDialysisPrescriptionWithVersion>,
|
|
) -> Result<Json<ApiResponse<DialysisPrescriptionResp>>, AppError>
|
|
where
|
|
HealthState: FromRef<S>,
|
|
S: Clone + Send + Sync + 'static,
|
|
{
|
|
require_permission(&ctx, "health.dialysis-prescription.manage")?;
|
|
let mut data = req.data;
|
|
data.sanitize();
|
|
let result = dialysis_prescription_service::update_prescription(
|
|
&state, ctx.tenant_id, id, Some(ctx.user_id), data, req.version,
|
|
)
|
|
.await?;
|
|
Ok(Json(ApiResponse::ok(result)))
|
|
}
|
|
|
|
pub async fn delete_prescription<S>(
|
|
State(state): State<HealthState>,
|
|
Extension(ctx): Extension<TenantContext>,
|
|
Path(id): Path<Uuid>,
|
|
Json(req): Json<DeleteWithVersion>,
|
|
) -> Result<Json<ApiResponse<()>>, AppError>
|
|
where
|
|
HealthState: FromRef<S>,
|
|
S: Clone + Send + Sync + 'static,
|
|
{
|
|
require_permission(&ctx, "health.dialysis-prescription.manage")?;
|
|
dialysis_prescription_service::delete_prescription(
|
|
&state, ctx.tenant_id, id, Some(ctx.user_id), req.version,
|
|
)
|
|
.await?;
|
|
Ok(Json(ApiResponse::ok(())))
|
|
}
|