import {z} from 'zod' export type MedicalSpecialtyCategory = {abbreviation?: (string | null) | undefined, created_date?: (string | null) | undefined, id?: number | undefined, name: string}; export type MedicalSpecialty = {abbreviation: string, category?: MedicalSpecialtyCategory | undefined, created_date?: (string | null) | undefined, id?: number | undefined, name: string, practice_created?: (number | null) | undefined}; export type Contact = {accepting_insurance?: (boolean | null) | undefined, accepting_new_patients?: (boolean | null) | undefined, address?: string | undefined, back_office_phone?: string | undefined, cell_phone?: string | undefined, city?: string | undefined, contact_type: string, created_date?: (string | null) | undefined, credentials: string, deleted_date?: (string | null) | undefined, direct_address?: string | undefined, email?: string | undefined, fax?: string | undefined, first_name: string, id?: number | undefined, is_elation_confirmed?: (boolean | null) | undefined, is_verified?: (boolean | null) | undefined, last_name: string, middle_name: string, npi?: string | undefined, org_name?: (string | null) | undefined, other_specialties?: Array | undefined, phone?: string | undefined, practice: number, specialty?: MedicalSpecialty | undefined, specialty_categories?: Array | undefined, state?: string | undefined, suite?: string | undefined, user?: number | undefined, zip?: string | undefined}; export type UpdateApiApi20ContactsIdArgs = {id: number, body: Contact}; export type UpdateApiApi20ContactsIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const medicalSpecialtyCategory = z.object({abbreviation: z.string().max(20).nullable().optional(), created_date: z.string().nullable().optional(), id: z.number().int().optional(), name: z.string().max(100)}); export const medicalSpecialty = z.object({abbreviation: z.string().max(20), category: medicalSpecialtyCategory.optional(), created_date: z.string().nullable().optional(), id: z.number().int().optional(), name: z.string().max(100), practice_created: z.number().int().nullable().optional()}); export const contact = z.object({accepting_insurance: z.boolean().nullable().optional(), accepting_new_patients: z.boolean().nullable().optional(), address: z.string().max(200).optional(), back_office_phone: z.string().max(20).optional(), cell_phone: z.string().max(20).optional(), city: z.string().max(50).optional(), contact_type: z.string().max(15), created_date: z.string().nullable().optional(), credentials: z.string().max(200), deleted_date: z.string().nullable().optional(), direct_address: z.string().max(500).optional(), email: z.string().optional(), fax: z.string().max(15).optional(), first_name: z.string().max(50), id: z.number().int().optional(), is_elation_confirmed: z.boolean().nullable().optional(), is_verified: z.boolean().nullable().optional(), last_name: z.string().max(60), middle_name: z.string().max(50), npi: z.string().optional(), org_name: z.string().max(100).nullable().optional(), other_specialties: z.array(medicalSpecialty).optional(), phone: z.string().max(20).optional(), practice: z.number().int(), specialty: medicalSpecialty.optional(), specialty_categories: z.array(z.unknown()).optional(), state: z.string().max(2).optional(), suite: z.string().max(20).optional(), user: z.number().int().optional(), zip: z.string().max(10).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 Contact * * PUT /api/2.0/contacts/{id}/ */ export const updateApiApi20ContactsId = async (args: UpdateApiApi20ContactsIdArgs, options?: UpdateApiApi20ContactsIdOptions) => { 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/contacts/${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(contact, await res.json()) };