import {z} from 'zod' export type DX = {icd10_code: string, icd9_codes?: Array | undefined}; export type NdcMeasureEnum = 'GR' | 'F2' | 'ME' | 'ML' | 'UN'; export type NullEnum = unknown; export type CPT = {cpt: string, dxs: Array, modifier_1?: (string | null) | undefined, modifier_2?: (string | null) | undefined, modifier_3?: (string | null) | undefined, modifier_4?: (string | null) | undefined, ndc?: (string | null) | undefined, ndc_dose?: (unknown | null) | undefined, ndc_measure?: (NdcMeasureEnum | NullEnum) | undefined, unit_charge: string, units: string}; export type ReferringProvider = {name: string, npi?: (string | null) | undefined, state: string}; export type BillUpdatePlaceOfServiceEnum = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '31' | '32' | '33' | '34' | '41' | '42' | '49' | '50' | '51' | '52' | '53' | '54' | '55' | '56' | '57' | '60' | '61' | '62' | '65' | '66' | '71' | '72' | '81' | '99'; export type PatchedBillUpdate = {billing_date?: (string | null) | undefined, billing_error?: (string | null) | undefined, billing_provider?: (number | null) | undefined, billing_raw_error?: (string | null) | undefined, cpts?: Array | undefined, metadata?: {[key: string]: unknown} | undefined, notes?: (string | null) | undefined, ordering_provider?: (ReferringProvider | null) | undefined, payment_amount?: (unknown | null) | undefined, place_of_service?: (BillUpdatePlaceOfServiceEnum | NullEnum) | undefined, practice?: number | undefined, prior_authorization?: (string | null) | undefined, ref_number?: string | undefined, referring_provider?: (ReferringProvider | null) | undefined, rendering_provider?: (number | null) | undefined, service_location?: number | undefined, supervising_provider?: (number | null) | undefined, visit_note?: number | undefined}; export type PatchApiApi20BillsIdArgs = {id: number, body: PatchedBillUpdate}; export type PatchApiApi20BillsIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const dX = z.object({icd10_code: z.string(), icd9_codes: z.array(z.string()).optional()}); export const ndcMeasureEnum = z.enum(["GR", "F2", "ME", "ML", "UN"]); export const nullEnum = z.unknown(); export const cPT = z.object({cpt: z.string(), dxs: z.array(dX), modifier_1: z.string().max(2).nullable().optional(), modifier_2: z.string().max(2).nullable().optional(), modifier_3: z.string().max(2).nullable().optional(), modifier_4: z.string().max(2).nullable().optional(), ndc: z.string().max(11).nullable().optional(), ndc_dose: z.string().nullable().optional(), ndc_measure: z.union([ndcMeasureEnum, nullEnum]).optional(), unit_charge: z.string(), units: z.string()}); export const referringProvider = z.object({name: z.string(), npi: z.string().max(10).nullable().optional(), state: z.string()}); export const billUpdatePlaceOfServiceEnum = z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "31", "32", "33", "34", "41", "42", "49", "50", "51", "52", "53", "54", "55", "56", "57", "60", "61", "62", "65", "66", "71", "72", "81", "99"]); export const billUpdate = z.object({billing_date: z.string().nullable().optional(), billing_error: z.string().max(200).nullable().optional(), billing_provider: z.number().int().nullable().optional(), billing_raw_error: z.string().nullable().optional(), cpts: z.array(cPT).optional(), metadata: z.record(z.string(), z.unknown()).optional(), notes: z.string().max(1000).nullable().optional(), ordering_provider: referringProvider.nullable().optional(), payment_amount: z.string().nullable().optional(), place_of_service: z.union([billUpdatePlaceOfServiceEnum, nullEnum]).optional(), practice: z.number().int().optional(), prior_authorization: z.string().max(50).nullable().optional(), ref_number: z.string().optional(), referring_provider: referringProvider.nullable().optional(), rendering_provider: z.number().int().nullable().optional(), service_location: z.number().int().optional(), supervising_provider: z.number().int().nullable().optional(), visit_note: 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 }; /** * Partially Update Bill * * PATCH /api/2.0/bills/{id}/ */ export const patchApiApi20BillsId = async (args: PatchApiApi20BillsIdArgs, options?: PatchApiApi20BillsIdOptions) => { const {baseUrl = "https://sandbox.elationemr.com", 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/bills/${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(billUpdate, await res.json()) };