Files
hms/crates/erp-health/src/handler/device_reading_handler.rs
iven 3412d807e3 fix(core): 跨 crate 小修复 — dto 合并、tracing 补全、死代码清理
- erp-ai: 删除孤立 dto.rs(已合并到子模块)
- erp-core: audit_service tracing 优化
- erp-health: points_handler 补充返回值、alert_engine 修正日志级别
- erp-plugin: host/data_handler/market_handler tracing 统一
- erp-dialysis/event: 移除无用 import
- erp-workflow/executor: tracing 格式统一
2026-05-03 19:31:46 +08:00

93 lines
2.8 KiB
Rust

use axum::extract::{FromRef, Path, Query, State};
use axum::response::IntoResponse;
use axum::Extension;
use serde::Deserialize;
use utoipa::IntoParams;
use uuid::Uuid;
use erp_core::error::AppError;
use erp_core::rbac::require_permission;
use erp_core::types::{ApiResponse, TenantContext};
use crate::service::device_reading_service;
use crate::state::HealthState;
#[derive(Debug, Deserialize)]
pub struct PatientPath {
pub patient_id: Uuid,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct ReadingListQuery {
pub device_type: Option<String>,
pub hours: Option<i64>,
pub page: Option<u64>,
pub page_size: Option<u64>,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct HourlyQuery {
pub device_type: String,
pub days: Option<i64>,
pub page: Option<u64>,
pub page_size: Option<u64>,
}
pub async fn batch_create<S>(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(path): Path<PatientPath>,
axum::Json(body): axum::Json<device_reading_service::BatchReadingRequest>,
) -> Result<impl IntoResponse, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "health.device-readings.manage")?;
let result = device_reading_service::batch_create_readings(
&state, ctx.tenant_id, path.patient_id, body,
).await?;
Ok(axum::Json(ApiResponse::ok(result)))
}
pub async fn list_readings<S>(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(path): Path<PatientPath>,
Query(query): Query<ReadingListQuery>,
) -> Result<impl IntoResponse, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "health.device-readings.list")?;
let page = query.page.unwrap_or(1);
let page_size = query.page_size.unwrap_or(20);
let result = device_reading_service::query_device_readings(
&state, ctx.tenant_id, path.patient_id,
query.device_type.as_deref(), query.hours, page, page_size,
).await?;
Ok(axum::Json(ApiResponse::ok(result)))
}
pub async fn list_hourly<S>(
State(state): State<HealthState>,
Extension(ctx): Extension<TenantContext>,
Path(path): Path<PatientPath>,
Query(query): Query<HourlyQuery>,
) -> Result<impl IntoResponse, AppError>
where
HealthState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "health.device-readings.list")?;
let page = query.page.unwrap_or(1);
let page_size = query.page_size.unwrap_or(20);
let days = query.days.unwrap_or(7);
let result = device_reading_service::query_hourly_readings(
&state, ctx.tenant_id, path.patient_id,
&query.device_type, days, page, page_size,
).await?;
Ok(axum::Json(ApiResponse::ok(result)))
}