import {z} from 'zod' export type InsuranceTypeEnum = 'Capitated' | 'Commercial' | 'Managed Medicaid' | 'Medicaid' | 'Medicare' | 'Medicare Advantage' | 'Medicare Supplement' | 'Self Pay' | 'Workers Compensation/Third Party Liability' | 'None'; export type NullEnum = unknown; export type PatchedInsuranceCompanySingleInstance = {address?: string | undefined, aliases?: (string | null) | undefined, carrier?: string | undefined, city?: string | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, eligibility_payer_id?: (string | null) | undefined, extension?: (string | null) | undefined, external_vendor_id?: (string | null) | undefined, id?: number | undefined, insurance_type?: (InsuranceTypeEnum | NullEnum) | undefined, is_credentialed?: (boolean | null) | undefined, is_enrolled?: (boolean | null) | undefined, patients?: Array | undefined, payer_id?: (string | null) | undefined, phone?: (string | null) | undefined, plans?: Array | undefined, practice?: number | undefined, state?: string | undefined, suite?: (string | null) | undefined, zip?: string | undefined}; export type PatchApiApi20InsuranceCompaniesIdArgs = {id: number, body: PatchedInsuranceCompanySingleInstance}; export type PatchApiApi20InsuranceCompaniesIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const insuranceTypeEnum = z.enum(["Capitated", "Commercial", "Managed Medicaid", "Medicaid", "Medicare", "Medicare Advantage", "Medicare Supplement", "Self Pay", "Workers Compensation/Third Party Liability", "None"]); export const nullEnum = z.unknown(); export const insuranceCompanySingleInstance = z.object({address: z.string().max(200).optional(), aliases: z.string().max(300).nullable().optional(), carrier: z.string().max(200), city: z.string().max(50).optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), eligibility_payer_id: z.string().max(200).nullable().optional(), extension: z.string().max(6).nullable().optional(), external_vendor_id: z.string().max(200).nullable().optional(), id: z.number().int().optional(), insurance_type: z.union([insuranceTypeEnum, nullEnum]).optional(), is_credentialed: z.boolean().nullable().optional(), is_enrolled: z.boolean().nullable().optional(), patients: z.array(z.number().int()).optional(), payer_id: z.string().max(200).nullable().optional(), phone: z.string().max(20).nullable().optional(), plans: z.array(z.number().int()).optional(), practice: z.number().int(), state: z.string().max(2).optional(), suite: z.string().max(40).nullable().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 }; /** * Partially Update Insurance Company * * PATCH /api/2.0/insurance_companies/{id}/ */ export const patchApiApi20InsuranceCompaniesId = async (args: PatchApiApi20InsuranceCompaniesIdArgs, options?: PatchApiApi20InsuranceCompaniesIdOptions) => { 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/insurance_companies/${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(insuranceCompanySingleInstance, await res.json()) };