import {z} from 'zod' export type GetApiDrV1AppointmentAppointmentIdArgs = {auth: string, appointment_id: string, partner_id?: string | undefined}; export type GetApiDrV1AppointmentAppointmentIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiDrV1AppointmentAppointmentIdResponse = z.object({appointment_id: z.string().optional(), created_at: z.number().int().optional(), doctor_id: z.string().optional(), patient_id: z.string().optional(), clinic_id: z.string().optional(), channel: z.string().optional(), status: z.enum(["BK", "OG", "CM", "CMNP", "CN", "CND", "CNS"]).optional(), mode: z.enum(["tele", "in_clinic"]).optional(), start_time: z.number().int().optional(), end_time: z.number().int().optional(), payment: z.object({payment_id: z.string().nullable().optional(), payment_status: z.string().nullable().optional(), amount: z.number().nullable().optional()}).optional(), prescription_id: z.string().optional(), service: z.object({created_at: z.number().int().optional(), mode: z.array(z.string()).optional(), price: z.number().nullable().optional(), post_pay: z.boolean().optional(), service_name: z.string().optional(), book_ahead_days: z.number().int().optional(), appointment_type: z.string().optional(), allow_patient_booking: z.boolean().optional()}).optional(), prescription_url: z.string().optional(), custom_attributes: z.object({}).optional(), partner_meta: z.object({}).optional(), notes: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Appointment Details * * GET /dr/v1/appointment/{appointment_id} */ export const getApiDrV1AppointmentAppointmentId = async (args: GetApiDrV1AppointmentAppointmentIdArgs, options?: GetApiDrV1AppointmentAppointmentIdOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.auth != null) headers.set("auth", String(args.auth)) if (args.partner_id != null) query.append("partner_id", String(args.partner_id)) const url = `${baseUrl.replace(/\/+$/, '')}/dr/v1/appointment/${encodeURIComponent(String(args.appointment_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiDrV1AppointmentAppointmentIdResponse, await res.json()) };