fix(web,miniprogram): 端到端测试修复 + 小程序接口字段对齐
## 前端修复 - 修复 9 个 TypeScript 编译错误(未使用变量/undefined 守卫/vitest 类型) - 重写 E2E auth fixture 使用真实 API 登录替代 mock token - 更新 E2E 测试选择器适配当前 UI 布局 - Playwright 改为串行执行避免 token 唯一约束冲突 - E2E 测试从 0/10 通过提升到 10/10 通过 ## 小程序接口一致性修复(P0-P3) - P0: consultation.ts type→consultation_type, unread_count→unread_count_patient - P0: followup.ts task_type→follow_up_type, due_date→planned_date, description→content_template - P1: appointment.ts calendarView 展平嵌套结构, available_count 计算 max-current - P1: doctor.ts HealthSummary 适配后台实际返回结构 - P2: doctor.ts PatientStats/ConsultationStats/FollowUpStats 字段名对齐 - P3: article.ts 新增 buildCategoryTree 工具函数
This commit is contained in:
@@ -25,6 +25,8 @@ export interface DoctorSchedule {
|
||||
date: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
max_appointments: number;
|
||||
current_appointments: number;
|
||||
available_count: number;
|
||||
}
|
||||
|
||||
@@ -60,12 +62,17 @@ export async function cancelAppointment(id: string, version: number) {
|
||||
}
|
||||
|
||||
export async function getDoctorSchedules(doctorId: string, startDate: string, endDate: string) {
|
||||
return api.get<{ data: DoctorSchedule[]; total: number }>('/health/doctor-schedules', {
|
||||
const resp = await api.get<{ data: DoctorSchedule[]; total: number }>('/health/doctor-schedules', {
|
||||
doctor_id: doctorId,
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
page_size: 50,
|
||||
});
|
||||
// 计算可用号源数
|
||||
for (const s of resp.data) {
|
||||
s.available_count = s.available_count ?? (s.max_appointments - s.current_appointments);
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
export async function listDoctors(department?: string) {
|
||||
@@ -76,9 +83,24 @@ export async function listDoctors(department?: string) {
|
||||
}
|
||||
|
||||
export async function calendarView(startDate: string, endDate: string, doctorId?: string) {
|
||||
return api.get<DoctorSchedule[]>('/health/doctor-schedules/calendar', {
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
...(doctorId && { doctor_id: doctorId }),
|
||||
});
|
||||
const raw = await api.get<{ date: string; schedules: DoctorSchedule[] }[]>(
|
||||
'/health/doctor-schedules/calendar',
|
||||
{
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
...(doctorId && { doctor_id: doctorId }),
|
||||
},
|
||||
);
|
||||
// 后台返回按日期分组的嵌套结构,展平为扁平数组并计算 available_count
|
||||
const flat: DoctorSchedule[] = [];
|
||||
for (const day of (raw as unknown as { date: string; schedules: DoctorSchedule[] }[])) {
|
||||
for (const s of day.schedules) {
|
||||
flat.push({
|
||||
...s,
|
||||
date: s.date || day.date,
|
||||
available_count: s.available_count ?? (s.max_appointments - s.current_appointments),
|
||||
});
|
||||
}
|
||||
}
|
||||
return flat;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,28 @@ export interface Article {
|
||||
export interface ArticleCategory {
|
||||
id: string;
|
||||
name: string;
|
||||
parent_id?: string;
|
||||
parent_id?: string | null;
|
||||
children?: ArticleCategory[];
|
||||
}
|
||||
|
||||
/** 将后台返回的扁平分类数组构建为树形结构 */
|
||||
export function buildCategoryTree(flat: ArticleCategory[]): ArticleCategory[] {
|
||||
const map = new Map<string, ArticleCategory>();
|
||||
const roots: ArticleCategory[] = [];
|
||||
for (const c of flat) {
|
||||
c.children = [];
|
||||
map.set(c.id, c);
|
||||
}
|
||||
for (const c of flat) {
|
||||
if (c.parent_id && map.has(c.parent_id)) {
|
||||
map.get(c.parent_id)!.children!.push(c);
|
||||
} else {
|
||||
roots.push(c);
|
||||
}
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
|
||||
export async function listArticles(params?: {
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
|
||||
@@ -4,12 +4,12 @@ export interface ConsultationSession {
|
||||
id: string;
|
||||
patient_id: string;
|
||||
doctor_id: string | null;
|
||||
type: string;
|
||||
consultation_type: string;
|
||||
status: string;
|
||||
subject: string | null;
|
||||
last_message: string | null;
|
||||
last_message_at: string | null;
|
||||
unread_count: number;
|
||||
unread_count_patient: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ export interface PatientDetail extends PatientItem {
|
||||
}
|
||||
|
||||
export interface HealthSummary {
|
||||
patient_id: string;
|
||||
latest_vital_signs?: {
|
||||
record_date: string;
|
||||
systolic_bp?: number;
|
||||
@@ -49,11 +50,15 @@ export interface HealthSummary {
|
||||
heart_rate?: number;
|
||||
weight?: number;
|
||||
blood_sugar?: number;
|
||||
};
|
||||
active_conditions?: string[];
|
||||
recent_lab_reports?: { id: string; report_date: string; report_type: string; abnormal_count: number }[];
|
||||
upcoming_appointments?: { id: string; appointment_date: string; type: string }[];
|
||||
} | null;
|
||||
latest_lab_report?: {
|
||||
id: string;
|
||||
report_date: string;
|
||||
report_type: string;
|
||||
abnormal_count?: number;
|
||||
} | null;
|
||||
pending_follow_ups?: number;
|
||||
upcoming_appointments?: number;
|
||||
}
|
||||
|
||||
export interface PatientTag {
|
||||
@@ -267,21 +272,23 @@ export async function listAppointments(params?: {
|
||||
// ── Statistics ─────────────────────────────────────
|
||||
|
||||
export interface PatientStats {
|
||||
total: number;
|
||||
active: number;
|
||||
total_patients: number;
|
||||
new_this_month: number;
|
||||
by_source?: Record<string, number>;
|
||||
new_this_week: number;
|
||||
active_this_month: number;
|
||||
}
|
||||
|
||||
export interface ConsultationStats {
|
||||
total: number;
|
||||
active: number;
|
||||
avg_response_time_minutes?: number;
|
||||
total_sessions: number;
|
||||
pending_reply: number;
|
||||
avg_response_time_minutes?: number | null;
|
||||
this_month: number;
|
||||
}
|
||||
|
||||
export interface FollowUpStats {
|
||||
total: number;
|
||||
total_tasks: number;
|
||||
completed: number;
|
||||
pending: number;
|
||||
overdue: number;
|
||||
completion_rate?: number;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ import { api } from './request';
|
||||
|
||||
export interface FollowUpTask {
|
||||
id: string;
|
||||
patient_name: string;
|
||||
task_type: string;
|
||||
description: string;
|
||||
patient_id?: string;
|
||||
patient_name?: string;
|
||||
follow_up_type: string;
|
||||
content_template?: string;
|
||||
status: string;
|
||||
due_date: string;
|
||||
planned_date: string;
|
||||
version: number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user