feat(health): Handler 接线 + Doctor Service + DTO 统一
- 重写全部 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:
@@ -1,226 +1,174 @@
|
||||
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::appointment_dto::*;
|
||||
use crate::service::appointment_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTO — 预约排班
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 预约列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct AppointmentListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
pub status: Option<String>,
|
||||
pub patient_id: Option<Uuid>,
|
||||
pub doctor_id: Option<Uuid>,
|
||||
pub status: Option<String>,
|
||||
pub date: Option<String>,
|
||||
pub date: Option<chrono::NaiveDate>,
|
||||
}
|
||||
|
||||
/// 创建预约请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateAppointmentReq {
|
||||
pub patient_id: Uuid,
|
||||
pub doctor_id: Uuid,
|
||||
pub schedule_id: Uuid,
|
||||
pub appointment_date: String,
|
||||
pub start_time: String,
|
||||
pub end_time: String,
|
||||
pub reason: Option<String>,
|
||||
}
|
||||
|
||||
/// 更新预约状态请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateAppointmentStatusReq {
|
||||
pub status: String,
|
||||
pub cancel_reason: Option<String>,
|
||||
}
|
||||
|
||||
/// 预约响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct AppointmentResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub doctor_id: Uuid,
|
||||
pub schedule_id: Uuid,
|
||||
pub appointment_date: String,
|
||||
pub start_time: String,
|
||||
pub end_time: String,
|
||||
pub status: String,
|
||||
pub reason: Option<String>,
|
||||
pub cancel_reason: Option<String>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
/// 排班列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct ScheduleListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
pub doctor_id: Option<Uuid>,
|
||||
pub start_date: Option<String>,
|
||||
pub end_date: Option<String>,
|
||||
pub date: Option<chrono::NaiveDate>,
|
||||
}
|
||||
|
||||
/// 创建排班请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateScheduleReq {
|
||||
pub doctor_id: Uuid,
|
||||
pub schedule_date: String,
|
||||
pub start_time: String,
|
||||
pub end_time: String,
|
||||
pub max_appointments: i32,
|
||||
pub slot_duration_minutes: Option<i32>,
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct CalendarViewParams {
|
||||
pub start_date: chrono::NaiveDate,
|
||||
pub end_date: chrono::NaiveDate,
|
||||
pub doctor_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
/// 更新排班请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateScheduleReq {
|
||||
pub start_time: Option<String>,
|
||||
pub end_time: Option<String>,
|
||||
pub max_appointments: Option<i32>,
|
||||
pub slot_duration_minutes: Option<i32>,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateScheduleWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: UpdateScheduleReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 排班响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct ScheduleResp {
|
||||
pub id: Uuid,
|
||||
pub doctor_id: Uuid,
|
||||
pub schedule_date: String,
|
||||
pub start_time: String,
|
||||
pub end_time: String,
|
||||
pub max_appointments: i32,
|
||||
pub current_appointments: i32,
|
||||
pub slot_duration_minutes: Option<i32>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateAppointmentStatusWithVersion {
|
||||
pub status: String,
|
||||
pub cancel_reason: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 日历视图查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct CalendarViewParams {
|
||||
pub doctor_id: Option<Uuid>,
|
||||
pub start_date: String,
|
||||
pub end_date: String,
|
||||
}
|
||||
|
||||
/// 日历视图单个日期条目
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct CalendarDayEntry {
|
||||
pub date: String,
|
||||
pub schedules: Vec<ScheduleResp>,
|
||||
pub appointments: Vec<AppointmentResp>,
|
||||
}
|
||||
|
||||
/// 日历视图响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct CalendarViewResp {
|
||||
pub days: Vec<CalendarDayEntry>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handler — 预约排班 (7 个端点)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// GET /api/v1/health/appointments — 预约列表
|
||||
pub async fn list_appointments<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<AppointmentListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<AppointmentListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<AppointmentResp>>>, 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 = appointment_service::list_appointments(
|
||||
&state, ctx.tenant_id, page, page_size, params.status, params.patient_id,
|
||||
params.doctor_id, params.date,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/appointments — 创建预约
|
||||
pub async fn create_appointment<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreateAppointmentReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateAppointmentReq>,
|
||||
) -> Result<Json<ApiResponse<AppointmentResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = appointment_service::create_appointment(
|
||||
&state, ctx.tenant_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/appointments/{id}/status — 更新预约状态
|
||||
pub async fn update_appointment_status<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdateAppointmentStatusReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<UpdateAppointmentStatusWithVersion>,
|
||||
) -> Result<Json<ApiResponse<AppointmentResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let update_req = UpdateAppointmentStatusReq {
|
||||
status: req.status,
|
||||
cancel_reason: req.cancel_reason,
|
||||
};
|
||||
let result = appointment_service::update_appointment_status(
|
||||
&state, ctx.tenant_id, id, Some(ctx.user_id), update_req, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/schedules — 排班列表
|
||||
pub async fn list_schedules<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<ScheduleListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<ScheduleListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<ScheduleResp>>>, 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 = appointment_service::list_schedules(
|
||||
&state, ctx.tenant_id, page, page_size, params.doctor_id, params.date,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/schedules — 创建排班
|
||||
pub async fn create_schedule<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreateScheduleReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateScheduleReq>,
|
||||
) -> Result<Json<ApiResponse<ScheduleResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = appointment_service::create_schedule(
|
||||
&state, ctx.tenant_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/schedules/{id} — 更新排班
|
||||
pub async fn update_schedule<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdateScheduleReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<UpdateScheduleWithVersion>,
|
||||
) -> Result<Json<ApiResponse<ScheduleResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = appointment_service::update_schedule(
|
||||
&state, ctx.tenant_id, id, Some(ctx.user_id), req.data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/calendar — 日历视图
|
||||
pub async fn calendar_view<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<CalendarViewParams>,
|
||||
) -> Result<Json<ApiResponse<CalendarViewResp>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<CalendarViewParams>,
|
||||
) -> Result<Json<ApiResponse<Vec<CalendarDayResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = appointment_service::calendar_view(
|
||||
&state, ctx.tenant_id, params.start_date, params.end_date, params.doctor_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user