import {z} from 'zod' export type GetApiNotesPatientsWithAppointmentsNowArgs = {TENANT: string, 'API-KEY': string, provider_id: string, minutes_before?: number | undefined, minutes_after?: number | undefined}; export type GetApiNotesPatientsWithAppointmentsNowOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const patientWithAppointmentDetail = z.object({id: z.string(), firstName: z.string(), lastName: z.string(), dateOfBirth: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), email: z.string().nullable().optional(), appointmentStart: z.string(), appointmentEnd: z.string(), appointmentType: z.string().nullable().optional(), appointmentTitle: z.string().nullable().optional()}); export const getApiNotesPatientsWithAppointmentsNowResponse = z.array(patientWithAppointmentDetail); 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 Patients With Appointments Now * * GET /notes/patients-with-appointments-now */ export const getApiNotesPatientsWithAppointmentsNow = async (args: GetApiNotesPatientsWithAppointmentsNowArgs, options: GetApiNotesPatientsWithAppointmentsNowOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) if (args.provider_id != null) query.append("provider_id", String(args.provider_id)) if (args.minutes_before != null) query.append("minutes_before", String(args.minutes_before)) if (args.minutes_after != null) query.append("minutes_after", String(args.minutes_after)) const url = `${baseUrl.replace(/\/+$/, '')}/notes/patients-with-appointments-now${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(getApiNotesPatientsWithAppointmentsNowResponse, await res.json()) };