feat(health): Handler 接线 + Doctor Service + DTO 统一
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

- 重写全部 6 个 handler 文件,从占位错误改为调用 service 层
- 删除 handler 内联 DTO,统一使用 dto/ 模块类型
- 新增 dto/doctor_dto.rs 和 dto/follow_up_dto.rs
- 新增 service/doctor_service.rs 实现医护档案 CRUD
- 将 follow_up_service 内联 DTO 迁移到 dto/follow_up_dto.rs
- 修复 consultation_session 列名 type→consultation_type(数据库+entity+迁移同步)
- 全部 51 个 API 端点已验证可用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
iven
2026-04-23 21:31:42 +08:00
parent 1824f84467
commit d6678d001e
14 changed files with 929 additions and 915 deletions

View File

@@ -1,19 +1,16 @@
use axum::Extension;
use axum::extract::{FromRef, Json, Path, Query, State};
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};
use serde::Deserialize;
use utoipa::IntoParams;
use uuid::Uuid;
use erp_core::error::AppError;
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
use crate::dto::follow_up_dto::*;
use crate::service::follow_up_service;
use crate::state::HealthState;
// ---------------------------------------------------------------------------
// DTO — 随访管理
// ---------------------------------------------------------------------------
/// 随访任务列表查询参数
#[derive(Debug, Deserialize, IntoParams)]
pub struct FollowUpTaskListParams {
pub page: Option<u64>,
@@ -23,55 +20,6 @@ pub struct FollowUpTaskListParams {
pub status: Option<String>,
}
/// 创建随访任务请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct CreateFollowUpTaskReq {
pub patient_id: Uuid,
pub task_type: String,
pub title: String,
pub description: Option<String>,
pub due_date: String,
pub assigned_to: Option<Uuid>,
}
/// 更新随访任务请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct UpdateFollowUpTaskReq {
pub task_type: Option<String>,
pub title: Option<String>,
pub description: Option<String>,
pub due_date: Option<String>,
pub assigned_to: Option<Uuid>,
pub status: Option<String>,
pub version: i32,
}
/// 随访任务响应
#[derive(Debug, Serialize, ToSchema)]
pub struct FollowUpTaskResp {
pub id: Uuid,
pub patient_id: Uuid,
pub task_type: String,
pub title: String,
pub description: Option<String>,
pub due_date: String,
pub assigned_to: Option<Uuid>,
pub status: String,
pub created_at: String,
pub updated_at: String,
}
/// 创建随访记录请求
#[derive(Debug, Deserialize, ToSchema)]
pub struct CreateFollowUpRecordReq {
pub task_id: Uuid,
pub contact_method: String,
pub content: String,
pub outcome: Option<String>,
pub next_follow_up_date: Option<String>,
}
/// 随访记录列表查询参数
#[derive(Debug, Deserialize, IntoParams)]
pub struct FollowUpRecordListParams {
pub page: Option<u64>,
@@ -80,99 +28,108 @@ pub struct FollowUpRecordListParams {
pub patient_id: Option<Uuid>,
}
/// 随访记录响应
#[derive(Debug, Serialize, ToSchema)]
pub struct FollowUpRecordResp {
pub id: Uuid,
pub task_id: Uuid,
pub patient_id: Uuid,
pub contact_method: String,
pub content: String,
pub outcome: Option<String>,
pub next_follow_up_date: Option<String>,
pub created_by: Uuid,
pub created_at: String,
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
pub struct UpdateFollowUpTaskWithVersion {
#[serde(flatten)]
pub data: UpdateFollowUpTaskReq,
pub version: i32,
}
// ---------------------------------------------------------------------------
// Handler — 随访管理 (6 个端点)
// ---------------------------------------------------------------------------
/// GET /api/v1/health/follow-up/tasks — 随访任务列表
pub async fn list_tasks<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Query(_params): Query<FollowUpTaskListParams>,
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Query(params): Query<FollowUpTaskListParams>,
) -> Result<Json<ApiResponse<PaginatedResponse<FollowUpTaskResp>>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
let page = params.page.unwrap_or(1);
let page_size = params.page_size.unwrap_or(20);
let result = follow_up_service::list_tasks(
&state, ctx.tenant_id, page, page_size, params.patient_id, params.assigned_to,
params.status,
)
.await?;
Ok(Json(ApiResponse::ok(result)))
}
/// POST /api/v1/health/follow-up/tasks — 创建随访任务
pub async fn create_task<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Json(_req): Json<CreateFollowUpTaskReq>,
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Json(req): Json<CreateFollowUpTaskReq>,
) -> Result<Json<ApiResponse<FollowUpTaskResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
let result = follow_up_service::create_task(
&state, ctx.tenant_id, Some(ctx.user_id), req,
)
.await?;
Ok(Json(ApiResponse::ok(result)))
}
/// PUT /api/v1/health/follow-up/tasks/{id} — 更新随访任务
pub async fn update_task<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
Json(_req): Json<UpdateFollowUpTaskReq>,
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(id): Path<Uuid>,
Json(req): Json<UpdateFollowUpTaskWithVersion>,
) -> Result<Json<ApiResponse<FollowUpTaskResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
let result = follow_up_service::update_task(
&state, ctx.tenant_id, id, Some(ctx.user_id), req.data, req.version,
)
.await?;
Ok(Json(ApiResponse::ok(result)))
}
/// DELETE /api/v1/health/follow-up/tasks/{id} — 删除随访任务
pub async fn delete_task<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Path(_id): Path<Uuid>,
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(id): Path<Uuid>,
) -> Result<Json<ApiResponse<()>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
follow_up_service::delete_task(&state, ctx.tenant_id, id, Some(ctx.user_id)).await?;
Ok(Json(ApiResponse::ok(())))
}
/// POST /api/v1/health/follow-up/records — 创建随访记录
pub async fn create_record<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Json(_req): Json<CreateFollowUpRecordReq>,
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Json(req): Json<CreateFollowUpRecordReq>,
) -> Result<Json<ApiResponse<FollowUpRecordResp>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
let result = follow_up_service::create_record(
&state, ctx.tenant_id, Some(ctx.user_id), req,
)
.await?;
Ok(Json(ApiResponse::ok(result)))
}
/// GET /api/v1/health/follow-up/records — 随访记录列表
pub async fn list_records<S>(
State(_state): State<HealthState>,
Extension(_ctx): Extension<TenantContext>,
Query(_params): Query<FollowUpRecordListParams>,
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Query(params): Query<FollowUpRecordListParams>,
) -> Result<Json<ApiResponse<PaginatedResponse<FollowUpRecordResp>>>, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Err(AppError::Internal("Not implemented yet".into()))
let page = params.page.unwrap_or(1);
let page_size = params.page_size.unwrap_or(20);
let result = follow_up_service::list_records(
&state, ctx.tenant_id, page, page_size, params.task_id, params.patient_id,
)
.await?;
Ok(Json(ApiResponse::ok(result)))
}