Files
hms/apps/web/src/api/copilot.ts
iven 6d97328ff6 feat(web): CopilotAlert 告警组件 + 告警 API 扩展
- CopilotAlert: 分级告警列表,30秒轮询刷新,危急 banner
- copilot.ts 新增 listAlerts 函数
2026-05-12 22:36:36 +08:00

64 lines
1.6 KiB
TypeScript

import client from './client';
import type { PaginatedResponse } from './types';
// --- Types ---
export type InsightType = 'risk_score' | 'anomaly' | 'follow_up_hint' | 'consult_hint';
export type InsightSource = 'rule' | 'llm' | 'hybrid';
export type RiskLevel = 'low' | 'medium' | 'high' | 'critical';
export interface MatchedRule {
rule_id: string;
name: string;
score: number;
severity: string;
suggestion?: string;
}
export interface RiskScore {
score: number;
level: RiskLevel;
matched_rules: MatchedRule[];
}
export interface CopilotInsight {
id: string;
patient_id: string;
insight_type: InsightType;
source: InsightSource;
severity: 'info' | 'warning' | 'critical';
title: string;
content: Record<string, unknown>;
rule_matches?: MatchedRule[];
llm_supplement?: string;
created_at: string;
}
// --- API Functions ---
export function getPatientRisk(patientId: string) {
return client.get<RiskScore>(`/copilot/patients/${patientId}/risk`);
}
export function listInsights(params: {
patient_id?: string;
insight_type?: string;
severity?: string;
page?: number;
page_size?: number;
}) {
return client.get<PaginatedResponse<CopilotInsight>>('/copilot/insights', { params });
}
export function dismissInsight(id: string) {
return client.post(`/copilot/insights/${id}/dismiss`);
}
export function listAlerts(params?: { severity?: string; page?: number; page_size?: number }) {
return listInsights({ insight_type: 'anomaly', ...params });
}
export function listRules(params?: { page?: number; page_size?: number }) {
return client.get<PaginatedResponse<Record<string, unknown>>>('/copilot/rules', { params });
}