新增: - AlertList 告警列表页: 状态筛选/确认/忽略操作 - AlertRuleList 告警规则页: 创建/编辑/启停管理 - alerts + deviceReadings 前端 API 层 - App.tsx 路由注册 + MainLayout 标题 fallback - wiki/frontend.md 更新页面清单 修复: - ArticleEditor: 修复 unused variable 构建错误 - FollowUpTaskList: 修复 filter(Boolean) 类型窄化问题
110 lines
2.9 KiB
TypeScript
110 lines
2.9 KiB
TypeScript
import client from '../client';
|
|
import type { PaginatedResponse } from '../types';
|
|
|
|
// --- Types ---
|
|
export interface Alert {
|
|
id: string;
|
|
patient_id: string;
|
|
rule_id: string;
|
|
severity: string;
|
|
title: string;
|
|
detail?: Record<string, unknown>;
|
|
status: string;
|
|
acknowledged_by?: string;
|
|
acknowledged_at?: string;
|
|
resolved_at?: string;
|
|
created_at: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface AlertRule {
|
|
id: string;
|
|
name: string;
|
|
description?: string;
|
|
device_type: string;
|
|
condition_type: string;
|
|
condition_params: Record<string, unknown>;
|
|
severity: string;
|
|
is_active: boolean;
|
|
apply_tags?: Record<string, unknown>;
|
|
notify_roles: unknown[];
|
|
cooldown_minutes: number;
|
|
created_at: string;
|
|
updated_at: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface CreateAlertRuleReq {
|
|
name: string;
|
|
description?: string;
|
|
device_type: string;
|
|
condition_type: string;
|
|
condition_params: Record<string, unknown>;
|
|
severity?: string;
|
|
apply_tags?: Record<string, unknown>;
|
|
notify_roles?: unknown[];
|
|
cooldown_minutes?: number;
|
|
}
|
|
|
|
export interface UpdateAlertRuleReq {
|
|
name?: string;
|
|
description?: string;
|
|
condition_params?: Record<string, unknown>;
|
|
severity?: string;
|
|
apply_tags?: Record<string, unknown>;
|
|
notify_roles?: unknown[];
|
|
cooldown_minutes?: number;
|
|
version: number;
|
|
}
|
|
|
|
// --- Alert API ---
|
|
export async function listAlerts(params?: {
|
|
patient_id?: string;
|
|
status?: string;
|
|
page?: number;
|
|
page_size?: number;
|
|
}) {
|
|
const res = await client.get('/health/alerts', { params });
|
|
return res.data.data as PaginatedResponse<Alert>;
|
|
}
|
|
|
|
export async function acknowledgeAlert(id: string, version: number) {
|
|
const res = await client.put(`/health/alerts/${id}/acknowledge`, { version });
|
|
return res.data.data as Alert;
|
|
}
|
|
|
|
export async function dismissAlert(id: string, version: number) {
|
|
const res = await client.put(`/health/alerts/${id}/dismiss`, { version });
|
|
return res.data.data as Alert;
|
|
}
|
|
|
|
export async function resolveAlert(id: string, version: number) {
|
|
const res = await client.put(`/health/alerts/${id}/resolve`, { version });
|
|
return res.data.data as Alert;
|
|
}
|
|
|
|
// --- Alert Rule API ---
|
|
export async function listAlertRules(params?: {
|
|
device_type?: string;
|
|
page?: number;
|
|
page_size?: number;
|
|
}) {
|
|
const res = await client.get('/health/alert-rules', { params });
|
|
return res.data.data as PaginatedResponse<AlertRule>;
|
|
}
|
|
|
|
export async function createAlertRule(data: CreateAlertRuleReq) {
|
|
const res = await client.post('/health/alert-rules', data);
|
|
return res.data.data as AlertRule;
|
|
}
|
|
|
|
export async function updateAlertRule(id: string, data: UpdateAlertRuleReq) {
|
|
const res = await client.put(`/health/alert-rules/${id}`, data);
|
|
return res.data.data as AlertRule;
|
|
}
|
|
|
|
export async function deactivateAlertRule(id: string, version: number) {
|
|
const res = await client.put(`/health/alert-rules/${id}/deactivate`, { version });
|
|
return res.data.data as AlertRule;
|
|
}
|