Files
hms/apps/web/src/api/health/consultations.ts
iven 07f4ba41ba
Some checks failed
CI / frontend-build (push) Has been cancelled
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / security-audit (push) Has been cancelled
fix(health): 穷尽审计修复 — 权限同步/编译错误/前端bug/审计日志
审计发现并修复的问题:

HIGH:
- H1: ConsultationDetail 使用 getSession(id) 替代错误的列表搜索
- H2: SessionResp 添加 version/updated_at 字段
- H3: 移除 FollowUpRecordList 调用不存在的导出端点
- H4: 新增 articles.ts 前端 API 模块

MEDIUM:
- M1: article delete 添加乐观锁 (expected_version)
- M2: 取消预约排班释放传播错误 (log::warn -> ?)
- M3: FollowUpTaskList 日期格式 Dayjs -> string
- M4: 补充 15 个缺失审计日志

LOW:
- L1: 替换 follow_up_service 中的 .unwrap()
- L2: PatientListItem 添加 version 字段

CRITICAL (新发现):
- 权限未同步: 健康模块 14 个权限从未写入数据库,添加启动时自动同步
- migration 表名错误: patients -> patient
- 编译错误: health_trend entity 未导入, ToPrimitive trait 未导入
- HealthError 缺少 From<AppError> 实现
2026-04-25 08:58:58 +08:00

118 lines
2.7 KiB
TypeScript

import client from '../client';
import type { PaginatedResponse } from '../types';
// --- Types ---
export interface Session {
id: string;
patient_id: string;
doctor_id?: string;
consultation_type: string;
status: string;
last_message_at?: string;
unread_count_patient: number;
unread_count_doctor: number;
created_at: string;
updated_at: string;
version: number;
}
export interface CreateSessionReq {
patient_id: string;
doctor_id?: string;
consultation_type?: string;
}
export interface Message {
id: string;
session_id: string;
sender_id: string;
sender_role: string;
content_type: string;
content: string;
is_read: boolean;
created_at: string;
}
export interface CreateMessageReq {
session_id: string;
sender_id: string;
sender_role: string;
content_type?: string;
content: string;
}
// --- API ---
export const consultationApi = {
listSessions: async (params: {
page?: number;
page_size?: number;
status?: string;
patient_id?: string;
doctor_id?: string;
}) => {
const { data } = await client.get<{
success: boolean;
data: PaginatedResponse<Session>;
}>('/health/consultation-sessions', { params });
return data.data;
},
createSession: async (req: CreateSessionReq) => {
const { data } = await client.post<{
success: boolean;
data: Session;
}>('/health/consultation-sessions', req);
return data.data;
},
getSession: async (id: string) => {
const { data } = await client.get<{
success: boolean;
data: Session;
}>(`/health/consultation-sessions/${id}`);
return data.data;
},
closeSession: async (
id: string,
req: { version: number },
) => {
const { data } = await client.put<{
success: boolean;
data: Session;
}>(`/health/consultation-sessions/${id}/close`, req);
return data.data;
},
listMessages: async (
sessionId: string,
params: { page?: number; page_size?: number },
) => {
const { data } = await client.get<{
success: boolean;
data: PaginatedResponse<Message>;
}>(`/health/consultation-sessions/${sessionId}/messages`, { params });
return data.data;
},
createMessage: async (req: CreateMessageReq) => {
const { data } = await client.post<{
success: boolean;
data: Message;
}>('/health/consultation-messages', req);
return data.data;
},
exportSessions: async (params: {
status?: string;
patient_id?: string;
doctor_id?: string;
}) => {
const { data } = await client.get<{
success: boolean;
data: Session[];
}>('/health/consultation-sessions/export', { params });
return data.data;
},
};