feat(health): Web 管理端设备数据集成补全 — Phase 2
- 新增告警三页面(仪表盘/列表/规则)+ 设备管理菜单种子数据
- 新增设备管理后端 API(GET /devices + DELETE /devices/{id})
- 新增设备数据查看组件 DeviceReadingsTab(原始数据 + 小时聚合)
- 新增设备管理页面 DeviceManage(列表/筛选/解绑)
- 患者详情页新增设备数据 Tab
This commit is contained in:
85
crates/erp-health/src/handler/device_handler.rs
Normal file
85
crates/erp-health/src/handler/device_handler.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
//! 设备管理 API — 设备列表查询与解绑
|
||||
|
||||
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, PaginatedResponse, TenantContext};
|
||||
|
||||
use crate::dto::DeleteWithVersion;
|
||||
use crate::service::device_service;
|
||||
use crate::state::HealthState;
|
||||
|
||||
/// 设备列表查询参数
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct DeviceListQuery {
|
||||
/// 按患者 ID 筛选
|
||||
pub patient_id: Option<Uuid>,
|
||||
/// 按设备类型筛选
|
||||
pub device_type: Option<String>,
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
}
|
||||
|
||||
/// GET /api/v1/health/devices — 设备绑定列表
|
||||
pub async fn list_devices<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Query(query): Query<DeviceListQuery>,
|
||||
) -> Result<impl IntoResponse, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.devices.list")?;
|
||||
let page = query.page.unwrap_or(1);
|
||||
let page_size = query.page_size.unwrap_or(20);
|
||||
|
||||
let (items, total) = device_service::list_devices(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
query.patient_id,
|
||||
query.device_type.as_deref(),
|
||||
page,
|
||||
page_size,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(axum::Json(ApiResponse::ok(PaginatedResponse {
|
||||
data: items,
|
||||
total,
|
||||
page,
|
||||
page_size,
|
||||
total_pages: total.div_ceil(page_size.max(1)),
|
||||
})))
|
||||
}
|
||||
|
||||
/// DELETE /api/v1/health/devices/{id} — 解绑设备(软删除)
|
||||
pub async fn unbind_device<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(id): Path<Uuid>,
|
||||
axum::Json(body): axum::Json<DeleteWithVersion>,
|
||||
) -> Result<impl IntoResponse, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
require_permission(&ctx, "health.devices.manage")?;
|
||||
|
||||
let device = device_service::unbind_device(
|
||||
&state,
|
||||
ctx.tenant_id,
|
||||
id,
|
||||
ctx.user_id,
|
||||
body.version,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(axum::Json(ApiResponse::ok(device)))
|
||||
}
|
||||
@@ -9,6 +9,7 @@ pub mod consent_handler;
|
||||
pub mod critical_alert_handler;
|
||||
pub mod critical_value_threshold_handler;
|
||||
pub mod daily_monitoring_handler;
|
||||
pub mod device_handler;
|
||||
pub mod device_reading_handler;
|
||||
pub mod diagnosis_handler;
|
||||
pub mod medication_record_handler;
|
||||
|
||||
Reference in New Issue
Block a user