import {z} from 'zod' export type PatientPhoto = {base_64: string, content_type?: string | undefined, created_date?: (string | null) | undefined, file?: string | undefined, file_size?: number | undefined, height?: number | undefined, id?: number | undefined, last_updated?: string | undefined, original_filename: string, patient: number, practice: number, width?: number | undefined}; export type CreateApiApi20PatientsIdProfileImageArgs = {id: number, body: PatientPhoto}; export type CreateApiApi20PatientsIdProfileImageOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const patientPhoto = z.object({base_64: z.string(), content_type: z.string().optional(), created_date: z.string().nullable().optional(), file: z.string().optional(), file_size: z.number().int().optional(), height: z.number().int().optional(), id: z.number().int().optional(), last_updated: z.string().optional(), original_filename: z.string(), patient: z.number().int(), practice: z.number().int(), width: z.number().int().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 }; /** * Create Patients Profile Image * * POST /api/2.0/patients/{id}/profile_image/ */ export const createApiApi20PatientsIdProfileImage = async (args: CreateApiApi20PatientsIdProfileImageArgs, options?: CreateApiApi20PatientsIdProfileImageOptions) => { 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/patients/${encodeURIComponent(String(args.id))}/profile_image/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(patientPhoto, await res.json()) };