import {z} from 'zod' export type GetApiFeeScheduleProceduresArgs = {'Nex-Api-Version': string, subdomain: string, location_id: number, fee_schedule_id?: number | undefined, updated_since?: string | undefined, start_cursor?: string | undefined, end_cursor?: string | undefined, per_page?: number | undefined}; export type GetApiFeeScheduleProceduresOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const aPIV2EntitiesPrice = z.object({amount: z.string().optional(), currency: z.string().optional()}); export const aPIV20240412EntitiesFeeScheduleProcedureCode = z.object({procedure_code_id: z.string().nullable().optional(), fee: aPIV2EntitiesPrice.optional(), code: z.string().nullable().optional(), id: z.number().int().optional(), location_id: z.number().int().nullable().optional(), fee_schedule_id: z.number().int().nullable().optional(), updated_at: z.string().optional()}); export const aPIV20240412EntitiesFeeScheduleProcedureCodeCollectionResponseWithCursor = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: z.array(aPIV20240412EntitiesFeeScheduleProcedureCode).optional(), page_info: z.object({}).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 }; /** * View fee schedule procedures * * GET /fee_schedule_procedures */ export const getApiFeeScheduleProcedures = async (args: GetApiFeeScheduleProceduresArgs, options?: GetApiFeeScheduleProceduresOptions) => { const {baseUrl = "https://nexhealth.info", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Nex-Api-Version'] != null) headers.set("Nex-Api-Version", String(args['Nex-Api-Version'])) if (args.subdomain != null) query.append("subdomain", String(args.subdomain)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.fee_schedule_id != null) query.append("fee_schedule_id", String(args.fee_schedule_id)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (args.start_cursor != null) query.append("start_cursor", String(args.start_cursor)) if (args.end_cursor != null) query.append("end_cursor", String(args.end_cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/fee_schedule_procedures${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(aPIV20240412EntitiesFeeScheduleProcedureCodeCollectionResponseWithCursor, await res.json()) };