import {z} from 'zod' export type GetApiPaymentsArgs = {'Nex-Api-Version': string, subdomain: string, location_id: number, patient_id?: number | undefined, provider_id?: number | undefined, guarantor_id?: number | undefined, charge_id?: number | undefined, claim_id?: number | undefined, transaction_id?: string | undefined, updated_since?: string | undefined, include_deleted?: boolean | undefined, sort?: string | undefined, start_cursor?: string | undefined, end_cursor?: string | undefined, per_page?: number | undefined}; export type GetApiPaymentsOptions = {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 aPIV20240412EntitiesLedgerPayment = z.object({id: z.number().int().optional(), foreign_id: z.string().optional(), location_id: z.number().int().nullable().optional(), patient_id: z.number().int().nullable().optional(), guarantor_id: z.number().int().nullable().optional(), provider_id: z.number().int().nullable().optional(), updated_at: z.string().optional(), description: z.string().nullable().optional(), deleted_at: z.string().nullable().optional(), payment_amount: aPIV2EntitiesPrice.optional(), paid_at: z.string().nullable().optional(), transaction_id: z.string().nullable().optional(), charge_id: z.number().int().nullable().optional(), claim_id: z.number().int().nullable().optional(), payment_plan_id: z.number().int().nullable().optional(), insurance_plan_id: z.number().int().nullable().optional(), payment_type_id: z.number().int().nullable().optional()}); export const aPIV20240412EntitiesLedgerPaymentCollectionResponseWithCursor = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: z.array(aPIV20240412EntitiesLedgerPayment).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 payments * * GET /payments */ export const getApiPayments = async (args: GetApiPaymentsArgs, options?: GetApiPaymentsOptions) => { 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.patient_id != null) query.append("patient_id", String(args.patient_id)) if (args.provider_id != null) query.append("provider_id", String(args.provider_id)) if (args.guarantor_id != null) query.append("guarantor_id", String(args.guarantor_id)) if (args.charge_id != null) query.append("charge_id", String(args.charge_id)) if (args.claim_id != null) query.append("claim_id", String(args.claim_id)) if (args.transaction_id != null) query.append("transaction_id", String(args.transaction_id)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.sort != null) query.append("sort", String(args.sort)) 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(/\/+$/, '')}/payments${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(aPIV20240412EntitiesLedgerPaymentCollectionResponseWithCursor, await res.json()) };