import {z} from 'zod' export type BiDiLabConnection = {alias?: (string | null) | undefined, enabled?: boolean | undefined, id?: number | undefined, priority?: number | undefined, protocol?: (string | null) | undefined}; export type PatchedFacilityIdentifier = {active?: boolean | undefined, bidi_connection?: (BiDiLabConnection | null) | undefined, compendium?: (number | null) | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, description?: (string | null) | undefined, id?: number | undefined, lab_connection?: (number | null) | undefined, lab_facility?: string | undefined, practice?: number | undefined, practice_facility?: string | undefined, practice_secondary_id?: (string | null) | undefined, user_facing?: boolean | undefined, vendor?: ({display_name?: string | undefined, id?: number | undefined, name?: string | undefined}) | undefined}; export type PatchApiApi20LabFacilityIdentifiersIdArgs = {id: number, body: PatchedFacilityIdentifier}; export type PatchApiApi20LabFacilityIdentifiersIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const biDiLabConnection = z.object({alias: z.string().nullable().optional(), enabled: z.boolean().optional(), id: z.number().int().optional(), priority: z.number().int().gte(0).lte(65535).optional(), protocol: z.string().nullable().optional()}); export const facilityIdentifier = z.object({active: z.boolean(), bidi_connection: biDiLabConnection.nullable().optional(), compendium: z.number().int().nullable().optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), description: z.string().max(255).nullable().optional(), id: z.number().int().optional(), lab_connection: z.number().int().nullable().optional(), lab_facility: z.string().max(50), practice: z.number().int(), practice_facility: z.string().max(50), practice_secondary_id: z.string().nullable().optional(), user_facing: z.boolean().optional(), vendor: z.object({display_name: z.string().optional(), id: z.number().int().optional(), name: z.string().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 Lab Facility Identifier * * PATCH /api/2.0/lab_facility_identifiers/{id}/ */ export const patchApiApi20LabFacilityIdentifiersId = async (args: PatchApiApi20LabFacilityIdentifiersIdArgs, options?: PatchApiApi20LabFacilityIdentifiersIdOptions) => { 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/lab_facility_identifiers/${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(facilityIdentifier, await res.json()) };