import {z} from 'zod' export type GetApiPaymentsIdArgs = {'Nex-Api-Version': string, id: number, subdomain: string, 'include[]'?: (Array<'patient' | 'provider' | 'guarantor' | 'claim' | 'charge' | 'payment_plan' | 'payment_type'>) | undefined}; export type GetApiPaymentsIdOptions = {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 aPIV2EntitiesPatientBasic = z.object({id: z.number().int().optional(), email: z.string().nullable().optional(), first_name: z.string().optional(), middle_name: z.string().nullable().optional(), last_name: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), institution_id: z.number().int().optional(), foreign_id: z.string().nullable().optional(), foreign_id_type: z.string().optional(), bio: z.object({}).optional(), inactive: z.boolean().optional(), last_sync_time: z.string().nullable().optional(), guarantor_id: z.number().int().nullable().optional(), billing_type: z.string().nullable().optional(), chart_id: z.string().nullable().optional(), preferred_language: z.string().nullable().optional(), preferred_locale: z.string().nullable().optional(), location_ids: z.array(z.number().int()).optional()}); export const aPIV2EntitiesProvider = z.object({id: z.number().int().optional(), email: z.string().nullable().optional(), first_name: z.string().optional(), middle_name: z.string().nullable().optional(), last_name: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), institution_id: z.number().int().optional(), foreign_id: z.string().nullable().optional(), foreign_id_type: z.string().optional(), bio: z.object({}).optional(), inactive: z.boolean().optional(), last_sync_time: z.string().nullable().optional(), display_name: z.string().optional(), npi: z.string().optional(), tin: z.string().optional(), state_license: z.string().optional(), specialty_code: z.string().optional()}); export const aPIV2EntitiesLedgerInsuranceClaimBasic = z.object({id: z.number().int().optional(), location_id: z.number().int().optional(), patient_id: z.number().int().optional(), provider_id: z.number().int().optional(), guarantor_id: z.number().int().optional(), subscription_id: z.number().int().optional(), status: z.enum(["draft", "sent", "received", "approved", "paid", "rejected", "canceled"]).optional(), finalized_at: z.string().optional(), sent_at: z.string().optional(), note: z.string().optional(), payment_estimate_total: aPIV2EntitiesPrice.optional(), write_off_estimate_total: aPIV2EntitiesPrice.optional(), write_off_total: aPIV2EntitiesPrice.optional(), deleted_at: z.string().optional()}); export const aPIV2EntitiesPatientLedgerCharge = 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(), fee: aPIV2EntitiesPrice.optional(), charged_at: z.string().optional(), procedure_id: z.string().optional(), claim_ids: z.array(z.number().int()).optional(), payment_estimate_total: aPIV2EntitiesPrice.optional(), write_off_estimate_total: aPIV2EntitiesPrice.optional(), write_off_total: aPIV2EntitiesPrice.optional()}); export const aPIV2EntitiesPaymentPlan = z.object({id: z.number().int().optional(), patient_id: z.number().int().optional(), guarantor_id: z.number().int().optional(), first_payment_due_date: z.string().optional(), created_date: z.string().optional(), active: z.boolean().optional()}); export const aPIV20240412EntitiesLedgerPaymentType = z.object({id: z.number().int().optional(), name: z.string().optional(), active: z.boolean().optional(), updated_at: z.string().optional()}); export const aPIV20240412EntitiesLedgerPaymentWithIncludes = 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(), patient: aPIV2EntitiesPatientBasic.optional(), provider: aPIV2EntitiesProvider.optional(), guarantor: aPIV2EntitiesPatientBasic.optional(), claim: aPIV2EntitiesLedgerInsuranceClaimBasic.optional(), charge: aPIV2EntitiesPatientLedgerCharge.optional(), payment_plan: aPIV2EntitiesPaymentPlan.optional(), payment_type: aPIV20240412EntitiesLedgerPaymentType.optional(), payment_type_id: z.number().int().nullable().optional()}); export const aPIV20240412EntitiesLedgerPaymentWithIncludesResponse = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: aPIV20240412EntitiesLedgerPaymentWithIncludes.optional(), count: 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 }; /** * View payment * * GET /payments/{id} */ export const getApiPaymentsId = async (args: GetApiPaymentsIdArgs, options?: GetApiPaymentsIdOptions) => { 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)) for (const item of args['include[]'] ?? []) query.append("include[]", String(item)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/payments/${encodeURIComponent(String(args.id))}${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(aPIV20240412EntitiesLedgerPaymentWithIncludesResponse, await res.json()) };