import {z} from 'zod' export type GetApiClaimsArgs = {'Nex-Api-Version': string, subdomain: string, location_id: number, sort?: string | undefined, patient_id?: number | undefined, guarantor_id?: number | undefined, provider_id?: number | undefined, updated_since?: string | undefined, date_of_service?: string | undefined, include_deleted?: boolean | undefined, start_cursor?: string | undefined, end_cursor?: string | undefined, per_page?: number | undefined}; export type GetApiClaimsOptions = {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 aPIV20240412EntitiesLedgerChargeClaimTotals = z.object({amount_billed_to_insurance: aPIV2EntitiesPrice.optional(), estimated_insurance_payment: aPIV2EntitiesPrice.optional(), insurance_payment: aPIV2EntitiesPrice.optional(), write_off: aPIV2EntitiesPrice.optional()}); export const aPIV20240412EntitiesLedgerInsuranceClaimBasicWithDelete = z.object({id: z.number().int().optional(), location_id: z.number().int().nullable().optional(), patient_id: z.number().int().nullable().optional(), provider_id: z.number().int().nullable().optional(), guarantor_id: z.number().int().nullable().optional(), status: z.enum(["draft", "sent", "received", "canceled"]).nullable().optional(), received_at: z.string().nullable().optional(), sent_at: z.string().nullable().optional(), note: z.string().nullable().optional(), primary_insurance_plan_id: z.number().int().nullable().optional(), secondary_insurance_plan_id: z.number().int().nullable().optional(), date_of_service: z.string().nullable().optional(), totals: aPIV20240412EntitiesLedgerChargeClaimTotals.optional(), updated_at: z.string().optional(), deleted_at: z.string().nullable().optional()}); export const aPIV20240412EntitiesLedgerInsuranceClaimBasicWithDeleteCollectionResponseWithCursor = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: z.array(aPIV20240412EntitiesLedgerInsuranceClaimBasicWithDelete).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 claims * * GET /claims */ export const getApiClaims = async (args: GetApiClaimsArgs, options?: GetApiClaimsOptions) => { 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.sort != null) query.append("sort", String(args.sort)) if (args.patient_id != null) query.append("patient_id", String(args.patient_id)) if (args.guarantor_id != null) query.append("guarantor_id", String(args.guarantor_id)) if (args.provider_id != null) query.append("provider_id", String(args.provider_id)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (args.date_of_service != null) query.append("date_of_service", String(args.date_of_service)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) 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(/\/+$/, '')}/claims${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(aPIV20240412EntitiesLedgerInsuranceClaimBasicWithDeleteCollectionResponseWithCursor, await res.json()) };