Files
hms/apps/miniprogram/src/services/appointment.ts

70 lines
1.9 KiB
TypeScript

import { api } from './request';
export interface Appointment {
id: string;
patient_name: string;
doctor_name: string;
department: string;
appointment_date: string;
time_slot: string;
status: string;
version: number;
}
export interface Doctor {
id: string;
name: string;
department: string;
title?: string;
}
export interface DoctorSchedule {
id: string;
doctor_id: string;
date: string;
time_slot: string;
available_count: number;
}
export async function listAppointments(page = 1) {
return api.get<{ data: Appointment[]; total: number }>(`/health/appointments?page=${page}&page_size=20`);
}
export async function getAppointment(id: string) {
return api.get<Appointment>(`/health/appointments/${id}`);
}
export async function createAppointment(data: {
patient_id: string;
doctor_id: string;
schedule_id?: string;
appointment_date: string;
time_slot: string;
reason?: string;
}) {
return api.post<Appointment>('/health/appointments', data);
}
export async function cancelAppointment(id: string, version: number) {
return api.put(`/health/appointments/${id}/status`, {
status: 'cancelled',
version,
});
}
export async function getDoctorSchedules(doctorId: string, startDate: string, endDate: string) {
return api.get<{ data: DoctorSchedule[]; total: number }>(
`/health/doctor-schedules?doctor_id=${doctorId}&start_date=${startDate}&end_date=${endDate}&page_size=50`
);
}
export async function listDoctors(department?: string) {
const deptParam = department ? `&department=${department}` : '';
return api.get<{ data: Doctor[]; total: number }>(`/health/doctors?page_size=100${deptParam}`);
}
export async function calendarView(startDate: string, endDate: string, doctorId?: string) {
const docParam = doctorId ? `&doctor_id=${doctorId}` : '';
return api.get<DoctorSchedule[]>(`/health/doctor-schedules/calendar?start_date=${startDate}&end_date=${endDate}${docParam}`);
}