feat(health): 添加 erp-health 健康管理模块骨架
新建 erp-health 原生 Rust crate,覆盖设计规格中定义的 5 大业务域: - 16 个 SeaORM Entity(患者/家属/标签/医生/健康档案/体征/化验单/预约/排班/随访/咨询等) - 16 表数据库迁移(含索引、外键、默认值、可回滚) - 40+ API 路由骨架(患者管理/健康数据/预约排班/随访/咨询/医生管理) - 12 个权限声明(health.patient/health-data/appointment/follow-up/consultation/doctor 各 .list/.manage) - DTO / Service / Handler / Event 四层架构,Service 使用 todo!() 占位 - erp-server 集成:模块注册 + AppState FromRef 桥接 + 路由挂载 同步更新 CLAUDE.md 项目进度、wiki 知识库、设计规格文档。
This commit is contained in:
408
crates/erp-health/src/handler/health_data_handler.rs
Normal file
408
crates/erp-health/src/handler/health_data_handler.rs
Normal file
@@ -0,0 +1,408 @@
|
||||
use axum::Extension;
|
||||
use axum::extract::{FromRef, Json, Path, Query, State};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::{IntoParams, ToSchema};
|
||||
use uuid::Uuid;
|
||||
|
||||
use erp_core::error::AppError;
|
||||
use erp_core::types::{ApiResponse, PaginatedResponse, TenantContext};
|
||||
|
||||
use crate::state::HealthState;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTO — 健康数据
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 生命体征列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct VitalSignsListParams {
|
||||
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>,
|
||||
}
|
||||
|
||||
/// 指标时间序列数据点
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct TimeseriesDataPoint {
|
||||
pub date: String,
|
||||
pub value: f64,
|
||||
pub unit: Option<String>,
|
||||
}
|
||||
|
||||
/// 指标时间序列响应
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct IndicatorTimeseriesResp {
|
||||
pub indicator_name: String,
|
||||
pub patient_id: Uuid,
|
||||
pub data_points: Vec<TimeseriesDataPoint>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 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>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<VitalSignsResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<VitalSignsResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<VitalSignsResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<LabReportResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<LabReportResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<LabReportResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/records — 健康档案列表
|
||||
pub async fn list_health_records<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
Query(_params): Query<HealthRecordListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<HealthRecordResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/records — 创建健康档案
|
||||
pub async fn create_health_record<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
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()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<HealthRecordResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<()>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// 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>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
|
||||
/// POST /api/v1/health/trends/generate — 生成趋势分析
|
||||
pub async fn generate_trend<S>(
|
||||
State(_state): State<HealthState>,
|
||||
Extension(_ctx): Extension<TenantContext>,
|
||||
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()))
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
) -> Result<Json<ApiResponse<IndicatorTimeseriesResp>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Err(AppError::Internal("Not implemented yet".into()))
|
||||
}
|
||||
Reference in New Issue
Block a user