import {z} from 'zod' export type PatchedPhysician = {credentials?: (string | null) | undefined, email?: string | undefined, fax?: string | undefined, first_name?: string | undefined, id?: number | undefined, is_active?: boolean | undefined, last_name?: string | undefined, license?: string | undefined, license_state?: string | undefined, metadata?: ({data?: Record | undefined, object_id?: string | undefined, object_web_link?: string | undefined} | null) | undefined, npi?: string | undefined, practice?: number | undefined, specialty?: string | undefined, user_id?: (number | null) | undefined}; export type PatchApiApi20PhysiciansIdArgs = {id: number, body: PatchedPhysician}; export type PatchApiApi20PhysiciansIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const physician = z.object({credentials: z.string().max(20).nullable().optional(), email: z.string(), fax: z.string().optional(), first_name: z.string().max(50), id: z.number().int().optional(), is_active: z.boolean().optional(), last_name: z.string().max(60), license: z.string(), license_state: z.string(), metadata: z.object({data: z.object({}).optional(), object_id: z.string().optional(), object_web_link: z.string().optional()}).nullable().optional(), npi: z.string(), practice: z.number().int().optional(), specialty: z.string().optional(), user_id: z.number().int().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 }; /** * Partially Update Physician * * PATCH /api/2.0/physicians/{id}/ */ export const patchApiApi20PhysiciansId = async (args: PatchApiApi20PhysiciansIdArgs, options?: PatchApiApi20PhysiciansIdOptions) => { 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/physicians/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(physician, await res.json()) };