feat(health): 护理计划实体与服务 — Phase 1 关怀引擎 MVP 第一步
新增护理计划(Care Plan)完整 CRUD:3 张表(care_plans / care_plan_items / care_plan_outcomes)、3 个 SeaORM Entity、15 个 API 端点、4 个事件常量、 2 个权限码。支持透析/慢性/预防/康复计划类型,条目分干预/监测/目标/教育四类, 预后测量含基线/目标/当前值追踪。
This commit is contained in:
304
crates/erp-health/src/handler/care_plan_handler.rs
Normal file
304
crates/erp-health/src/handler/care_plan_handler.rs
Normal file
@@ -0,0 +1,304 @@
|
||||
use axum::extract::{FromRef, Json, Path, Query, State};
|
||||
use axum::Extension;
|
||||
use erp_core::error::AppError;
|
||||
use erp_core::rbac::require_permission;
|
||||
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
|
||||
|
||||
use crate::dto::care_plan_dto::*;
|
||||
use crate::service::care_plan_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct PaginationParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CarePlan
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_care_plans<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<ListCarePlansParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<CarePlanResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.list")?;
|
||||
let result = care_plan_service::list_care_plans(&state, ctx.tenant_id, ¶ms).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn get_care_plan<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
) -> Result<Json<ApiResponse<CarePlanResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.list")?;
|
||||
let result = care_plan_service::get_care_plan(&state, ctx.tenant_id, plan_id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn create_care_plan<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(mut req): Json<CreateCarePlanReq>,
|
||||
) -> Result<Json<ApiResponse<CarePlanResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
req.sanitize();
|
||||
let result =
|
||||
care_plan_service::create_care_plan(&state, ctx.tenant_id, Some(ctx.user_id), req).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn update_care_plan<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
Json(mut req): Json<UpdateCarePlanWithVersion>,
|
||||
) -> Result<Json<ApiResponse<CarePlanResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
req.data.sanitize();
|
||||
let result = care_plan_service::update_care_plan(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
Some(ctx.user_id),
|
||||
req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn delete_care_plan<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
Json(body): Json<crate::dto::DeleteWithVersion>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
care_plan_service::delete_care_plan(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
Some(ctx.user_id),
|
||||
body.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CarePlanItem
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_care_plan_items<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<CarePlanItemResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.list")?;
|
||||
let page = params.page.unwrap_or(1);
|
||||
let page_size = params.page_size.unwrap_or(20);
|
||||
let result = care_plan_service::list_care_plan_items(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
page,
|
||||
page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn create_care_plan_item<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
Json(mut req): Json<CreateCarePlanItemReq>,
|
||||
) -> Result<Json<ApiResponse<CarePlanItemResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
req.sanitize();
|
||||
let result = care_plan_service::create_care_plan_item(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
Some(ctx.user_id),
|
||||
req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn update_care_plan_item<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((plan_id, item_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
||||
Json(mut req): Json<UpdateCarePlanItemWithVersion>,
|
||||
) -> Result<Json<ApiResponse<CarePlanItemResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
req.data.sanitize();
|
||||
let result = care_plan_service::update_care_plan_item(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
item_id,
|
||||
Some(ctx.user_id),
|
||||
req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn delete_care_plan_item<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((plan_id, item_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
||||
Json(body): Json<crate::dto::DeleteWithVersion>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
care_plan_service::delete_care_plan_item(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
item_id,
|
||||
Some(ctx.user_id),
|
||||
body.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CarePlanOutcome
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_care_plan_outcomes<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<CarePlanOutcomeResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.list")?;
|
||||
let page = params.page.unwrap_or(1);
|
||||
let page_size = params.page_size.unwrap_or(20);
|
||||
let result = care_plan_service::list_care_plan_outcomes(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
page,
|
||||
page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn create_care_plan_outcome<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(plan_id): Path<uuid::Uuid>,
|
||||
Json(mut req): Json<CreateCarePlanOutcomeReq>,
|
||||
) -> Result<Json<ApiResponse<CarePlanOutcomeResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
req.sanitize();
|
||||
let result = care_plan_service::create_care_plan_outcome(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
Some(ctx.user_id),
|
||||
req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn update_care_plan_outcome<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((plan_id, outcome_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
||||
Json(mut req): Json<UpdateCarePlanOutcomeWithVersion>,
|
||||
) -> Result<Json<ApiResponse<CarePlanOutcomeResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
req.data.sanitize();
|
||||
let result = care_plan_service::update_care_plan_outcome(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
outcome_id,
|
||||
Some(ctx.user_id),
|
||||
req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn delete_care_plan_outcome<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((plan_id, outcome_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
||||
Json(body): Json<crate::dto::DeleteWithVersion>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.care-plan.manage")?;
|
||||
care_plan_service::delete_care_plan_outcome(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
plan_id,
|
||||
outcome_id,
|
||||
Some(ctx.user_id),
|
||||
body.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub mod appointment_handler;
|
||||
pub mod article_category_handler;
|
||||
pub mod article_handler;
|
||||
pub mod article_tag_handler;
|
||||
pub mod care_plan_handler;
|
||||
pub mod consultation_handler;
|
||||
pub mod consent_handler;
|
||||
pub mod critical_alert_handler;
|
||||
|
||||
Reference in New Issue
Block a user