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)))
|
||||
}
|
||||
|
||||
@@ -1,142 +1,142 @@
|
||||
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::consultation_dto::*;
|
||||
use crate::service::consultation_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTO — 咨询管理
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 会话列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct SessionListParams {
|
||||
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>,
|
||||
}
|
||||
|
||||
/// 会话响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct ConsultationSessionResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub doctor_id: Uuid,
|
||||
pub subject: String,
|
||||
pub status: String,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
/// 消息列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct MessageListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
}
|
||||
|
||||
/// 创建消息请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateConsultationMessageReq {
|
||||
pub content: String,
|
||||
pub message_type: Option<String>,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct CloseSessionReq {
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 消息响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct ConsultationMessageResp {
|
||||
pub id: Uuid,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateConsultationMessageReq {
|
||||
pub session_id: Uuid,
|
||||
pub sender_id: Uuid,
|
||||
pub sender_type: String,
|
||||
pub sender_role: String,
|
||||
pub content_type: Option<String>,
|
||||
pub content: String,
|
||||
pub message_type: String,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
/// 导出会话请求
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct ExportSessionsParams {
|
||||
pub status: Option<String>,
|
||||
pub patient_id: Option<Uuid>,
|
||||
pub doctor_id: Option<Uuid>,
|
||||
pub start_date: Option<String>,
|
||||
pub end_date: Option<String>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handler — 咨询管理 (5 个端点)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// GET /api/v1/health/consultations/sessions — 会话列表
|
||||
pub async fn list_sessions<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<SessionListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<ConsultationSessionResp>>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<SessionListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<SessionResp>>>, 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 = consultation_service::list_sessions(
|
||||
&state, ctx.tenant_id, page, page_size, params.status, params.patient_id,
|
||||
params.doctor_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/consultations/sessions/{id}/messages — 消息列表
|
||||
pub async fn list_messages<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_session_id): Path<Uuid>,
|
||||
Query(_params): Query<MessageListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<ConsultationMessageResp>>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(session_id): Path<Uuid>,
|
||||
Query(params): Query<MessageListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<MessageResp>>>, 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 = consultation_service::list_messages(
|
||||
&state, ctx.tenant_id, session_id, page, page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/consultations/sessions/{id}/close — 关闭会话
|
||||
pub async fn close_session<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
) -> Result<Json<ApiResponse<ConsultationSessionResp>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<CloseSessionReq>,
|
||||
) -> Result<Json<ApiResponse<SessionResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = consultation_service::close_session(
|
||||
&state, ctx.tenant_id, id, Some(ctx.user_id), req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/consultations/sessions/{id}/messages — 创建消息
|
||||
pub async fn create_message<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_session_id): Path<Uuid>,
|
||||
Json(_req): Json<CreateConsultationMessageReq>,
|
||||
) -> Result<Json<ApiResponse<ConsultationMessageResp>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateConsultationMessageReq>,
|
||||
) -> Result<Json<ApiResponse<MessageResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let msg_req = CreateMessageReq {
|
||||
session_id: req.session_id,
|
||||
sender_id: req.sender_id,
|
||||
sender_role: req.sender_role,
|
||||
content_type: req.content_type,
|
||||
content: req.content,
|
||||
};
|
||||
let result = consultation_service::create_message(
|
||||
&state, ctx.tenant_id, Some(ctx.user_id), msg_req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/consultations/export — 导出会话
|
||||
pub async fn export_sessions<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<ExportSessionsParams>,
|
||||
) -> Result<Json<ApiResponse<Vec<ConsultationSessionResp>>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<ExportSessionsParams>,
|
||||
) -> Result<Json<ApiResponse<Vec<SessionResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = consultation_service::export_sessions(
|
||||
&state, ctx.tenant_id, params.status, params.patient_id, params.doctor_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
@@ -1,136 +1,105 @@
|
||||
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::doctor_dto::*;
|
||||
use crate::service::doctor_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTO — 医护管理
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 医护列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct DoctorListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
/// 按姓名模糊搜索
|
||||
pub search: Option<String>,
|
||||
/// 按科室筛选
|
||||
pub department: Option<String>,
|
||||
/// 按职称筛选
|
||||
pub title: Option<String>,
|
||||
}
|
||||
|
||||
/// 创建医护档案请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateDoctorReq {
|
||||
pub user_id: Uuid,
|
||||
pub name: String,
|
||||
pub department: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub specialty: Option<String>,
|
||||
pub license_number: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
}
|
||||
|
||||
/// 更新医护档案请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateDoctorReq {
|
||||
pub name: Option<String>,
|
||||
pub department: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub specialty: Option<String>,
|
||||
pub license_number: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateDoctorWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: UpdateDoctorReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 医护档案响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct DoctorResp {
|
||||
pub id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub name: String,
|
||||
pub department: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub specialty: Option<String>,
|
||||
pub license_number: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handler — 医护管理 (5 个端点)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// GET /api/v1/health/doctors — 医护档案列表
|
||||
pub async fn list_doctors<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<DoctorListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<DoctorListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<DoctorResp>>>, 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 = doctor_service::list_doctors(
|
||||
&state, ctx.tenant_id, page, page_size, params.search, params.department, params.title,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/doctors — 创建医护档案
|
||||
pub async fn create_doctor<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreateDoctorReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateDoctorReq>,
|
||||
) -> Result<Json<ApiResponse<DoctorResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = doctor_service::create_doctor(
|
||||
&state, ctx.tenant_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/doctors/{id} — 获取医护档案详情
|
||||
pub async fn get_doctor<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<DoctorResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = doctor_service::get_doctor(&state, ctx.tenant_id, id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/doctors/{id} — 更新医护档案
|
||||
pub async fn update_doctor<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdateDoctorReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<UpdateDoctorWithVersion>,
|
||||
) -> Result<Json<ApiResponse<DoctorResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = doctor_service::update_doctor(
|
||||
&state, ctx.tenant_id, id, Some(ctx.user_id), req.data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/doctors/{id} — 删除医护档案
|
||||
pub async fn delete_doctor<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()))
|
||||
doctor_service::delete_doctor(&state, ctx.tenant_id, id, Some(ctx.user_id)).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
@@ -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)))
|
||||
}
|
||||
|
||||
@@ -1,408 +1,332 @@
|
||||
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::health_data_dto::*;
|
||||
use crate::service::health_data_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTO — 健康数据
|
||||
// 查询参数
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 生命体征列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct VitalSignsListParams {
|
||||
pub struct PaginationParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
pub patient_id: Uuid,
|
||||
}
|
||||
|
||||
/// 创建生命体征请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateVitalSignsReq {
|
||||
pub patient_id: Uuid,
|
||||
pub blood_pressure_systolic: Option<i32>,
|
||||
pub blood_pressure_diastolic: Option<i32>,
|
||||
pub heart_rate: Option<i32>,
|
||||
pub temperature: Option<f64>,
|
||||
pub blood_oxygen: Option<i32>,
|
||||
pub weight: Option<f64>,
|
||||
pub height: Option<f64>,
|
||||
pub measured_at: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
}
|
||||
|
||||
/// 更新生命体征请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateVitalSignsReq {
|
||||
pub blood_pressure_systolic: Option<i32>,
|
||||
pub blood_pressure_diastolic: Option<i32>,
|
||||
pub heart_rate: Option<i32>,
|
||||
pub temperature: Option<f64>,
|
||||
pub blood_oxygen: Option<i32>,
|
||||
pub weight: Option<f64>,
|
||||
pub height: Option<f64>,
|
||||
pub measured_at: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 生命体征响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct VitalSignsResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub blood_pressure_systolic: Option<i32>,
|
||||
pub blood_pressure_diastolic: Option<i32>,
|
||||
pub heart_rate: Option<i32>,
|
||||
pub temperature: Option<f64>,
|
||||
pub blood_oxygen: Option<i32>,
|
||||
pub weight: Option<f64>,
|
||||
pub height: Option<f64>,
|
||||
pub measured_at: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
/// 化验报告列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct LabReportListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
pub patient_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
/// 创建化验报告请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateLabReportReq {
|
||||
pub patient_id: Uuid,
|
||||
pub report_type: String,
|
||||
pub report_date: String,
|
||||
pub indicators: serde_json::Value,
|
||||
pub file_url: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
}
|
||||
|
||||
/// 更新化验报告请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateLabReportReq {
|
||||
pub report_type: Option<String>,
|
||||
pub report_date: Option<String>,
|
||||
pub indicators: Option<serde_json::Value>,
|
||||
pub file_url: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 化验报告响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct LabReportResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub report_type: String,
|
||||
pub report_date: String,
|
||||
pub indicators: serde_json::Value,
|
||||
pub file_url: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
/// 健康档案列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct HealthRecordListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
pub patient_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
/// 创建健康档案请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateHealthRecordReq {
|
||||
pub patient_id: Uuid,
|
||||
pub record_type: String,
|
||||
pub title: String,
|
||||
pub content: serde_json::Value,
|
||||
pub record_date: String,
|
||||
}
|
||||
|
||||
/// 更新健康档案请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateHealthRecordReq {
|
||||
pub record_type: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub content: Option<serde_json::Value>,
|
||||
pub record_date: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 健康档案响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct HealthRecordResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub record_type: String,
|
||||
pub title: String,
|
||||
pub content: serde_json::Value,
|
||||
pub record_date: String,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
/// 趋势分析列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct TrendListParams {
|
||||
pub patient_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
/// 生成趋势请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct GenerateTrendReq {
|
||||
pub patient_id: Uuid,
|
||||
pub indicator_name: String,
|
||||
pub start_date: String,
|
||||
pub end_date: String,
|
||||
}
|
||||
|
||||
/// 趋势分析响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct TrendResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub indicator_name: String,
|
||||
pub trend_data: serde_json::Value,
|
||||
pub analysis_summary: Option<String>,
|
||||
pub generated_at: String,
|
||||
}
|
||||
|
||||
/// 指标时间序列查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct IndicatorTimeseriesParams {
|
||||
pub patient_id: Uuid,
|
||||
pub indicator_name: String,
|
||||
pub start_date: Option<String>,
|
||||
pub end_date: Option<String>,
|
||||
pub start_date: Option<chrono::NaiveDate>,
|
||||
pub end_date: Option<chrono::NaiveDate>,
|
||||
}
|
||||
|
||||
/// 指标时间序列数据点
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct TimeseriesDataPoint {
|
||||
pub date: String,
|
||||
pub value: f64,
|
||||
pub unit: Option<String>,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct GenerateTrendReq {
|
||||
pub period_start: chrono::NaiveDate,
|
||||
pub period_end: chrono::NaiveDate,
|
||||
}
|
||||
|
||||
/// 指标时间序列响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct IndicatorTimeseriesResp {
|
||||
pub indicator_name: String,
|
||||
pub patient_id: Uuid,
|
||||
pub data_points: Vec<TimeseriesDataPoint>,
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateWithVersion<T> {
|
||||
pub data: T,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handler — 健康数据 (15 个端点)
|
||||
// 生命体征
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// GET /api/v1/health/vital-signs — 生命体征列表
|
||||
pub async fn list_vital_signs<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<VitalSignsListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<VitalSignsResp>>>, 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 = health_data_service::list_vital_signs(
|
||||
&state, ctx.tenant_id, patient_id, page, page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/vital-signs — 创建生命体征记录
|
||||
pub async fn create_vital_signs<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreateVitalSignsReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Json(req): Json<CreateVitalSignsReq>,
|
||||
) -> Result<Json<ApiResponse<VitalSignsResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::create_vital_signs(
|
||||
&state, ctx.tenant_id, patient_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/vital-signs/{id} — 更新生命体征记录
|
||||
pub async fn update_vital_signs<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdateVitalSignsReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((patient_id, vid)): Path<(Uuid, Uuid)>,
|
||||
Json(req): Json<UpdateVitalSignsWithVersion>,
|
||||
) -> Result<Json<ApiResponse<VitalSignsResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::update_vital_signs(
|
||||
&state, ctx.tenant_id, patient_id, vid, Some(ctx.user_id), req.data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/vital-signs/{id} — 删除生命体征记录
|
||||
pub async fn delete_vital_signs<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, vid)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
health_data_service::delete_vital_signs(&state, ctx.tenant_id, vid, Some(ctx.user_id)).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/lab-reports — 化验报告列表
|
||||
// ---------------------------------------------------------------------------
|
||||
// 化验报告
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_lab_reports<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<LabReportListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<LabReportResp>>>, 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 = health_data_service::list_lab_reports(
|
||||
&state, ctx.tenant_id, patient_id, page, page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/lab-reports — 创建化验报告
|
||||
pub async fn create_lab_report<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreateLabReportReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Json(req): Json<CreateLabReportReq>,
|
||||
) -> Result<Json<ApiResponse<LabReportResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::create_lab_report(
|
||||
&state, ctx.tenant_id, patient_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/lab-reports/{id} — 更新化验报告
|
||||
pub async fn update_lab_report<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdateLabReportReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, rid)): Path<(Uuid, Uuid)>,
|
||||
Json(req): Json<UpdateLabReportWithVersion>,
|
||||
) -> Result<Json<ApiResponse<LabReportResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::update_lab_report(
|
||||
&state, ctx.tenant_id, rid, Some(ctx.user_id), req.data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/lab-reports/{id} — 删除化验报告
|
||||
pub async fn delete_lab_report<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, rid)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
health_data_service::delete_lab_report(&state, ctx.tenant_id, rid, Some(ctx.user_id)).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/records — 健康档案列表
|
||||
// ---------------------------------------------------------------------------
|
||||
// 健康档案
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_health_records<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<HealthRecordListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<HealthRecordResp>>>, 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 = health_data_service::list_health_records(
|
||||
&state, ctx.tenant_id, patient_id, page, page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/records — 创建健康档案
|
||||
pub async fn create_health_record<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreateHealthRecordReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Json(req): Json<CreateHealthRecordReq>,
|
||||
) -> Result<Json<ApiResponse<HealthRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::create_health_record(
|
||||
&state, ctx.tenant_id, patient_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/records/{id} — 更新健康档案
|
||||
pub async fn update_health_record<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdateHealthRecordReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, rid)): Path<(Uuid, Uuid)>,
|
||||
Json(req): Json<UpdateHealthRecordWithVersion>,
|
||||
) -> Result<Json<ApiResponse<HealthRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::update_health_record(
|
||||
&state, ctx.tenant_id, rid, Some(ctx.user_id), req.data, req.version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/records/{id} — 删除健康档案
|
||||
pub async fn delete_health_record<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, rid)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
health_data_service::delete_health_record(&state, ctx.tenant_id, rid, Some(ctx.user_id)).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/trends — 趋势分析列表
|
||||
// ---------------------------------------------------------------------------
|
||||
// 趋势分析
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_trends<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<TrendListParams>,
|
||||
) -> Result<Json<ApiResponse<Vec<TrendResp>>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<TrendResp>>>, 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 = health_data_service::list_trends(
|
||||
&state, ctx.tenant_id, patient_id, page, page_size,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/trends/generate — 生成趋势分析
|
||||
pub async fn generate_trend<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<GenerateTrendReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(patient_id): Path<Uuid>,
|
||||
Json(req): Json<GenerateTrendReq>,
|
||||
) -> Result<Json<ApiResponse<TrendResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::generate_trend(
|
||||
&state, ctx.tenant_id, patient_id, Some(ctx.user_id), req.period_start, req.period_end,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/trends/timeseries — 获取指标时间序列
|
||||
pub async fn get_indicator_timeseries<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<IndicatorTimeseriesParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((patient_id, indicator)): Path<(Uuid, String)>,
|
||||
Query(params): Query<IndicatorTimeseriesParams>,
|
||||
) -> Result<Json<ApiResponse<IndicatorTimeseriesResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = health_data_service::get_indicator_timeseries(
|
||||
&state, ctx.tenant_id, patient_id, indicator, params.start_date, params.end_date,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 带版本号的更新请求包装
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateVitalSignsWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: UpdateVitalSignsReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateLabReportWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: CreateLabReportReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateHealthRecordWithVersion {
|
||||
#[serde(flatten)]
|
||||
pub data: CreateHealthRecordReq,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
@@ -1,311 +1,281 @@
|
||||
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::patient_dto::{
|
||||
CreatePatientReq, FamilyMemberReq, FamilyMemberResp, ManageTagsReq, PatientResp,
|
||||
UpdatePatientReq,
|
||||
};
|
||||
use crate::service::patient_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTO — 患者管理
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 患者列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PatientListParams {
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
/// 按姓名/身份证号模糊搜索
|
||||
pub search: Option<String>,
|
||||
/// 按标签筛选
|
||||
pub tag_id: Option<Uuid>,
|
||||
/// 按负责医生筛选
|
||||
pub doctor_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
/// 创建患者请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreatePatientReq {
|
||||
pub name: String,
|
||||
pub id_card: Option<String>,
|
||||
pub phone: Option<String>,
|
||||
pub gender: Option<String>,
|
||||
pub birth_date: Option<String>,
|
||||
pub address: Option<String>,
|
||||
pub emergency_contact: Option<String>,
|
||||
pub emergency_phone: Option<String>,
|
||||
pub medical_notes: Option<String>,
|
||||
}
|
||||
|
||||
/// 更新患者请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdatePatientReq {
|
||||
pub name: Option<String>,
|
||||
pub id_card: Option<String>,
|
||||
pub phone: Option<String>,
|
||||
pub gender: Option<String>,
|
||||
pub birth_date: Option<String>,
|
||||
pub address: Option<String>,
|
||||
pub emergency_contact: Option<String>,
|
||||
pub emergency_phone: Option<String>,
|
||||
pub medical_notes: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
/// 患者标签管理请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct ManagePatientTagsReq {
|
||||
pub tag_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
/// 患者响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct PatientResp {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub id_card: Option<String>,
|
||||
pub phone: Option<String>,
|
||||
pub gender: Option<String>,
|
||||
pub birth_date: Option<String>,
|
||||
pub address: Option<String>,
|
||||
pub emergency_contact: Option<String>,
|
||||
pub emergency_phone: Option<String>,
|
||||
pub medical_notes: Option<String>,
|
||||
pub tags: Vec<PatientTagResp>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
/// 患者标签响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct PatientTagResp {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub color: Option<String>,
|
||||
}
|
||||
|
||||
/// 健康摘要响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct HealthSummaryResp {
|
||||
pub patient_id: Uuid,
|
||||
pub latest_vital_signs: Option<serde_json::Value>,
|
||||
pub latest_lab_report: Option<serde_json::Value>,
|
||||
pub upcoming_appointments: u64,
|
||||
pub pending_follow_ups: u64,
|
||||
}
|
||||
|
||||
/// 家庭成员请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct CreateFamilyMemberReq {
|
||||
pub name: String,
|
||||
pub relationship: String,
|
||||
pub phone: Option<String>,
|
||||
pub id_card: Option<String>,
|
||||
}
|
||||
|
||||
/// 更新家庭成员请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct UpdateFamilyMemberReq {
|
||||
pub name: Option<String>,
|
||||
pub relationship: Option<String>,
|
||||
pub phone: Option<String>,
|
||||
pub id_card: Option<String>,
|
||||
}
|
||||
|
||||
/// 家庭成员响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct FamilyMemberResp {
|
||||
pub id: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub name: String,
|
||||
pub relationship: String,
|
||||
pub phone: Option<String>,
|
||||
pub id_card: Option<String>,
|
||||
}
|
||||
|
||||
/// 分配医生请求
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct AssignDoctorReq {
|
||||
pub doctor_id: Uuid,
|
||||
pub relationship_type: Option<String>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handler — 患者管理 (13 个端点)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// GET /api/v1/health/patients — 患者列表
|
||||
pub async fn list_patients<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<PatientListParams>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(params): Query<PatientListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<PatientResp>>>, 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 = patient_service::list_patients(
|
||||
&state, ctx.tenant_id, page, page_size, params.search, params.tag_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/patients — 创建患者
|
||||
pub async fn create_patient<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Json(_req): Json<CreatePatientReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreatePatientReq>,
|
||||
) -> Result<Json<ApiResponse<PatientResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = patient_service::create_patient(
|
||||
&state, ctx.tenant_id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/patients/{id} — 获取患者详情
|
||||
pub async fn get_patient<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<PatientResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = patient_service::get_patient(&state, ctx.tenant_id, id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/patients/{id} — 更新患者
|
||||
pub async fn update_patient<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<UpdatePatientReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<UpdatePatientWithVersion>,
|
||||
) -> Result<Json<ApiResponse<PatientResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let version = req.version;
|
||||
let update = UpdatePatientReq {
|
||||
name: req.name,
|
||||
gender: req.gender,
|
||||
birth_date: req.birth_date,
|
||||
blood_type: req.blood_type,
|
||||
id_number: req.id_number,
|
||||
allergy_history: req.allergy_history,
|
||||
medical_history_summary: req.medical_history_summary,
|
||||
emergency_contact_name: req.emergency_contact_name,
|
||||
emergency_contact_phone: req.emergency_contact_phone,
|
||||
source: req.source,
|
||||
notes: req.notes,
|
||||
};
|
||||
let result = patient_service::update_patient(
|
||||
&state, ctx.tenant_id, id, Some(ctx.user_id), update, version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/patients/{id} — 删除患者(软删除)
|
||||
pub async fn delete_patient<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()))
|
||||
patient_service::delete_patient(&state, ctx.tenant_id, id, Some(ctx.user_id)).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/patients/{id}/tags — 管理患者标签
|
||||
pub async fn manage_patient_tags<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<ManagePatientTagsReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<ManageTagsReq>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
patient_service::manage_patient_tags(&state, ctx.tenant_id, id, req, Some(ctx.user_id)).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/patients/{id}/health-summary — 获取患者健康摘要
|
||||
pub async fn get_health_summary<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
) -> Result<Json<ApiResponse<HealthSummaryResp>>, AppError>
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<ApiResponse<serde_json::Value>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = patient_service::get_health_summary(&state, ctx.tenant_id, id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/patients/{id}/family-members — 家庭成员列表
|
||||
pub async fn list_family_members<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<Vec<FamilyMemberResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = patient_service::list_family_members(&state, ctx.tenant_id, id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/patients/{id}/family-members — 创建家庭成员
|
||||
pub async fn create_family_member<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<CreateFamilyMemberReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<FamilyMemberReq>,
|
||||
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let result = patient_service::create_family_member(
|
||||
&state, ctx.tenant_id, id, Some(ctx.user_id), req,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// PUT /api/v1/health/patients/{patient_id}/family-members/{member_id} — 更新家庭成员
|
||||
pub async fn update_family_member<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, _member_id)): Path<(Uuid, Uuid)>,
|
||||
Json(_req): Json<UpdateFamilyMemberReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
Json(req): Json<FamilyMemberUpdateWithVersion>,
|
||||
) -> Result<Json<ApiResponse<FamilyMemberResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
let version = req.version;
|
||||
let update = FamilyMemberReq {
|
||||
name: req.name,
|
||||
relationship: req.relationship,
|
||||
phone: req.phone,
|
||||
birth_date: req.birth_date,
|
||||
notes: req.notes,
|
||||
};
|
||||
let result = patient_service::update_family_member(
|
||||
&state, ctx.tenant_id, _patient_id, member_id, Some(ctx.user_id), update, version,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/patients/{patient_id}/family-members/{member_id} — 删除家庭成员
|
||||
pub async fn delete_family_member<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, _member_id)): Path<(Uuid, Uuid)>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((patient_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
patient_service::delete_family_member(
|
||||
&state, ctx.tenant_id, patient_id, member_id, Some(ctx.user_id),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/patients/{id}/doctors — 分配负责医生
|
||||
pub async fn assign_doctor<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path(_id): Path<Uuid>,
|
||||
Json(_req): Json<AssignDoctorReq>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(req): Json<AssignDoctorReq>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
patient_service::assign_doctor(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
id,
|
||||
req.doctor_id,
|
||||
req.relationship_type.unwrap_or_else(|| "primary".to_string()),
|
||||
Some(ctx.user_id),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/patients/{patient_id}/doctors/{doctor_id} — 移除负责医生
|
||||
pub async fn remove_doctor<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Path((_patient_id, _doctor_id)): Path<(Uuid, Uuid)>,
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path((patient_id, doctor_id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
patient_service::remove_doctor(&state, ctx.tenant_id, patient_id, doctor_id).await?;
|
||||
Ok(Json(ApiResponse::ok(())))
|
||||
}
|
||||
|
||||
// 带版本号的更新请求包装
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdatePatientWithVersion {
|
||||
pub name: Option<String>,
|
||||
pub gender: Option<String>,
|
||||
pub birth_date: Option<chrono::NaiveDate>,
|
||||
pub blood_type: Option<String>,
|
||||
pub id_number: Option<String>,
|
||||
pub allergy_history: Option<String>,
|
||||
pub medical_history_summary: Option<String>,
|
||||
pub emergency_contact_name: Option<String>,
|
||||
pub emergency_contact_phone: Option<String>,
|
||||
pub source: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, utoipa::ToSchema)]
|
||||
pub struct FamilyMemberUpdateWithVersion {
|
||||
pub name: String,
|
||||
pub relationship: String,
|
||||
pub phone: Option<String>,
|
||||
pub birth_date: Option<chrono::NaiveDate>,
|
||||
pub notes: Option<String>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user