import {z} from 'zod' export type AppointmentBillingDetails = {billing_note?: (string | null) | undefined, prior_authorization?: (string | null) | undefined, referring_provider?: (string | null) | undefined, referring_provider_state?: (string | null) | undefined}; export type ModeEnum = 'IN_PERSON' | 'VIDEO'; export type Payment = {amount: unknown, appointment?: (number | null) | undefined, bill?: (number | null) | undefined, create_date?: (string | null) | undefined, delete_date?: (string | null) | undefined, id?: number | undefined, when_collected: string}; export type AppointmentStatusStatusEnum = 'Billed' | 'Cancelled' | 'Checked In' | 'Checked Out' | 'Confirmed' | 'In Room' | 'In Room - Vitals Taken' | 'Not Seen' | 'Scheduled' | 'With Doctor'; export type AppointmentStatus = {room?: (string | null) | undefined, status: AppointmentStatusStatusEnum, status_date?: (string | null) | undefined, status_detail?: (string | null) | undefined}; export type TimeSlotStatusEnum = 'not_avail_for_self_schedule'; export type NullEnum = unknown; export type TimeSlotTypeEnum = 'appointment' | 'appointment_slot' | 'event'; export type TransportationDetails = {is_required?: boolean | undefined, notes?: (string | null) | undefined}; export type Appointment = {appointment_type_id?: (number | null) | undefined, billing_details?: (AppointmentBillingDetails | null) | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, description?: (string | null) | undefined, duration?: number | undefined, id?: number | undefined, instructions?: (string | null) | undefined, is_blocking?: boolean | undefined, last_modified_date?: string | undefined, metadata?: ({data?: Record | undefined, object_id?: string | undefined, object_web_link?: string | undefined} | null) | undefined, mode?: ModeEnum | undefined, patient: number | null, payment?: (Payment | null) | undefined, physician: number, practice: number, reason?: (string | null) | undefined, recurring_event_schedule?: (number | null) | undefined, scheduled_date: string, service_location?: ({address_line1?: (string | null) | undefined, address_line2?: (string | null) | undefined, city?: (string | null) | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, id?: number | undefined, is_primary?: boolean | undefined, name?: string | undefined, phone?: (string | null) | undefined, place_of_service?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 34 | 41 | 42 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 60 | 61 | 62 | 65 | 66 | 71 | 72 | 81 | 99 | null) | undefined, state?: (string | null) | undefined, zip?: (string | null) | undefined} | number | null) | undefined, status?: (AppointmentStatus | null) | undefined, telehealth_details?: (string | null) | undefined, time_slot_status?: (TimeSlotStatusEnum | NullEnum) | undefined, time_slot_type?: TimeSlotTypeEnum | undefined, transportation_details?: (TransportationDetails | null) | undefined}; export type UpdateApiApi20AppointmentsIdArgs = {id: number, body: Appointment}; export type UpdateApiApi20AppointmentsIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const appointmentBillingDetails = z.object({billing_note: z.string().nullable().optional(), prior_authorization: z.string().max(50).nullable().optional(), referring_provider: z.string().max(100).nullable().optional(), referring_provider_state: z.string().max(2).nullable().optional()}); export const modeEnum = z.enum(["IN_PERSON", "VIDEO"]); export const payment = z.object({amount: z.string(), appointment: z.number().int().nullable().optional(), bill: z.number().int().nullable().optional(), create_date: z.string().nullable().optional(), delete_date: z.string().nullable().optional(), id: z.number().int().optional(), when_collected: z.string()}); export const appointmentStatusStatusEnum = z.enum(["Billed", "Cancelled", "Checked In", "Checked Out", "Confirmed", "In Room", "In Room - Vitals Taken", "Not Seen", "Scheduled", "With Doctor"]); export const appointmentStatus = z.object({room: z.string().nullable().optional(), status: appointmentStatusStatusEnum, status_date: z.string().nullable().optional(), status_detail: z.string().nullable().optional()}); export const timeSlotStatusEnum = z.literal("not_avail_for_self_schedule"); export const nullEnum = z.unknown(); export const timeSlotTypeEnum = z.enum(["appointment", "appointment_slot", "event"]); export const transportationDetails = z.object({is_required: z.boolean().optional(), notes: z.string().nullable().optional()}); export const appointment = z.object({appointment_type_id: z.number().int().nullable().optional(), billing_details: appointmentBillingDetails.nullable().optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), description: z.string().nullable().optional(), duration: z.number().int().gte(-2147483648).lte(2147483647).optional(), id: z.number().int().optional(), instructions: z.string().nullable().optional(), is_blocking: z.boolean().optional(), last_modified_date: z.string().optional(), metadata: z.object({data: z.object({}).optional(), object_id: z.string().optional(), object_web_link: z.string().optional()}).nullable().optional(), mode: modeEnum.optional(), patient: z.number().int().nullable(), payment: payment.nullable().optional(), physician: z.number().int(), practice: z.number().int(), reason: z.string().max(50).nullable().optional(), recurring_event_schedule: z.number().int().nullable().optional(), scheduled_date: z.string(), service_location: z.union([z.object({address_line1: z.string().nullable().optional(), address_line2: z.string().nullable().optional(), city: z.string().nullable().optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), id: z.number().int().optional(), is_primary: z.boolean().optional(), name: z.string().optional(), phone: z.string().nullable().optional(), place_of_service: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23), z.literal(24), z.literal(25), z.literal(26), z.literal(27), z.literal(31), z.literal(32), z.literal(33), z.literal(34), z.literal(41), z.literal(42), z.literal(49), z.literal(50), z.literal(51), z.literal(52), z.literal(53), z.literal(54), z.literal(55), z.literal(56), z.literal(57), z.literal(60), z.literal(61), z.literal(62), z.literal(65), z.literal(66), z.literal(71), z.literal(72), z.literal(81), z.literal(99)]).nullable().optional(), state: z.string().nullable().optional(), zip: z.string().nullable().optional()}), z.number().int()]).nullable().optional(), status: appointmentStatus.nullable().optional(), telehealth_details: z.string().nullable().optional(), time_slot_status: z.union([timeSlotStatusEnum, nullEnum]).optional(), time_slot_type: timeSlotTypeEnum.optional(), transportation_details: transportationDetails.nullable().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 }; /** * Update Appointment * * PUT /api/2.0/appointments/{id}/ */ export const updateApiApi20AppointmentsId = async (args: UpdateApiApi20AppointmentsIdArgs, options?: UpdateApiApi20AppointmentsIdOptions) => { const {baseUrl = "https://sandbox.elationemr.com/api/2.0", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/2.0/appointments/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(appointment, await res.json()) };