- refactor(web): PatientDetail.tsx 拆分为 4 个子组件(737→334行) - refactor(web): 提取 usePaginatedData hook 消除重复分页状态 - feat(db): patient.id_number varchar(20)→varchar(255) 容纳加密值 - test(health): 添加预约模块集成测试(创建/列表/租户隔离) - test(plugin): 添加 6 个 SQL 注入 sanitize 测试 - fix(miniprogram): 7 个 service 文件 URL 构建规范化(params 对象) - fix(miniprogram): 跨平台字段名对齐(birth_date/start_time/end_time)
163 lines
3.5 KiB
TypeScript
163 lines
3.5 KiB
TypeScript
import client from '../client';
|
|
import type { PaginatedResponse } from '../types';
|
|
|
|
// --- Types ---
|
|
export interface Appointment {
|
|
id: string;
|
|
patient_id: string;
|
|
doctor_id?: string;
|
|
appointment_type: string;
|
|
appointment_date: string;
|
|
start_time: string;
|
|
end_time: string;
|
|
status: string;
|
|
cancel_reason?: string;
|
|
notes?: string;
|
|
patient_name?: string;
|
|
doctor_name?: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface CreateAppointmentReq {
|
|
patient_id: string;
|
|
doctor_id?: string;
|
|
appointment_type?: string;
|
|
appointment_date: string;
|
|
start_time: string;
|
|
end_time: string;
|
|
notes?: string;
|
|
}
|
|
|
|
export interface UpdateAppointmentStatusReq {
|
|
status: string;
|
|
cancel_reason?: string;
|
|
}
|
|
|
|
export interface Schedule {
|
|
id: string;
|
|
doctor_id: string;
|
|
schedule_date: string;
|
|
period_type: string;
|
|
start_time: string;
|
|
end_time: string;
|
|
max_appointments: number;
|
|
current_appointments: number;
|
|
status: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface CreateScheduleReq {
|
|
doctor_id: string;
|
|
schedule_date: string;
|
|
period_type?: string;
|
|
start_time: string;
|
|
end_time: string;
|
|
max_appointments: number;
|
|
}
|
|
|
|
export interface UpdateScheduleReq {
|
|
start_time?: string;
|
|
end_time?: string;
|
|
max_appointments?: number;
|
|
status?: string;
|
|
}
|
|
|
|
export interface CalendarDay {
|
|
date: string;
|
|
schedules: Schedule[];
|
|
}
|
|
|
|
// --- API ---
|
|
export const appointmentApi = {
|
|
list: async (params: {
|
|
page?: number;
|
|
page_size?: number;
|
|
status?: string;
|
|
patient_id?: string;
|
|
doctor_id?: string;
|
|
date?: string;
|
|
}) => {
|
|
const { data } = await client.get<{
|
|
success: boolean;
|
|
data: PaginatedResponse<Appointment>;
|
|
}>('/health/appointments', { params });
|
|
return data.data;
|
|
},
|
|
|
|
get: async (id: string) => {
|
|
const { data } = await client.get<{
|
|
success: boolean;
|
|
data: Appointment;
|
|
}>(`/health/appointments/${id}`);
|
|
return data.data;
|
|
},
|
|
|
|
create: async (req: CreateAppointmentReq) => {
|
|
const { data } = await client.post<{
|
|
success: boolean;
|
|
data: Appointment;
|
|
}>('/health/appointments', req);
|
|
return data.data;
|
|
},
|
|
|
|
updateStatus: async (
|
|
id: string,
|
|
req: UpdateAppointmentStatusReq & { version: number },
|
|
) => {
|
|
const { data } = await client.put<{
|
|
success: boolean;
|
|
data: Appointment;
|
|
}>(`/health/appointments/${id}/status`, req);
|
|
return data.data;
|
|
},
|
|
|
|
// Schedules
|
|
listSchedules: async (params: {
|
|
page?: number;
|
|
page_size?: number;
|
|
doctor_id?: string;
|
|
date?: string;
|
|
}) => {
|
|
const { data } = await client.get<{
|
|
success: boolean;
|
|
data: PaginatedResponse<Schedule>;
|
|
}>('/health/doctor-schedules', { params });
|
|
return data.data;
|
|
},
|
|
|
|
createSchedule: async (req: CreateScheduleReq) => {
|
|
const { data } = await client.post<{
|
|
success: boolean;
|
|
data: Schedule;
|
|
}>('/health/doctor-schedules', req);
|
|
return data.data;
|
|
},
|
|
|
|
updateSchedule: async (
|
|
id: string,
|
|
req: UpdateScheduleReq & { version: number },
|
|
) => {
|
|
const { data } = await client.put<{
|
|
success: boolean;
|
|
data: Schedule;
|
|
}>(`/health/doctor-schedules/${id}`, req);
|
|
return data.data;
|
|
},
|
|
|
|
calendar: async (params: {
|
|
start_date: string;
|
|
end_date: string;
|
|
doctor_id?: string;
|
|
}) => {
|
|
const { data } = await client.get<{
|
|
success: boolean;
|
|
data: CalendarDay[];
|
|
}>('/health/doctor-schedules/calendar', { params });
|
|
return data.data;
|
|
},
|
|
};
|