import {z} from 'zod' export type NonInsurancePayerPaymentsV1NonInsurancePayerPaymentId = string; export type FinancialsNoteUpdate = {type: 'set', value: string} | {type: 'remove'}; export type CommonsInvoiceId = string; export type FinancialsInvoiceUpdate = {type: 'set', value: CommonsInvoiceId} | {type: 'remove'}; export type PatchApiApiNonInsurancePayerPaymentsV1NonInsurancePayerPaymentIdArgs = {non_insurance_payer_payment_id: NonInsurancePayerPaymentsV1NonInsurancePayerPaymentId, body: {payment_timestamp?: string | undefined, payment_note?: FinancialsNoteUpdate | undefined, invoice_id?: FinancialsInvoiceUpdate | undefined}}; export type PatchApiApiNonInsurancePayerPaymentsV1NonInsurancePayerPaymentIdOptions = {baseUrl?: string | undefined, OAuthScheme?: string | undefined, fetch?: typeof fetch | undefined}; export const nonInsurancePayerPaymentsV1NonInsurancePayerPaymentId = z.string(); export const nonInsurancePayersV1NonInsurancePayerId = z.string(); export const commonsState = z.enum(["AA", "AE", "AP", "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "FM", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MH", "MI", "MN", "MP", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "PR", "PW", "RI", "SC", "SD", "TN", "TX", "UT", "VI", "VT", "VA", "WA", "WV", "WI", "WY", "FC"]); export const commonsStreetAddressShortZip = z.object({address1: z.string(), address2: z.string().optional(), city: z.string(), state: commonsState, zip_code: z.string(), zip_plus_four_code: z.string().optional()}); export const clinicalTrialsV1ClinicalTrialPhase = z.enum(["Phase 1", "Phase 2", "Phase 3"]); export const commonsClinicalTrialId = z.string(); export const clinicalTrialsV1ClinicalTrial = z.object({name: z.string(), clinical_trial_number: z.string(), clinical_trial_phase: clinicalTrialsV1ClinicalTrialPhase.optional(), clinical_trial_id: commonsClinicalTrialId, non_insurance_payer_id: nonInsurancePayersV1NonInsurancePayerId, is_active: z.boolean()}); export const nonInsurancePayersV1NonInsurancePayer = z.object({non_insurance_payer_id: nonInsurancePayersV1NonInsurancePayerId, name: z.string(), description: z.string().optional(), category: z.string().optional(), payer_id: z.string().optional(), enabled: z.boolean(), address: commonsStreetAddressShortZip.optional(), clinical_trials: z.array(clinicalTrialsV1ClinicalTrial)}); export const commonsAllocationId = z.string(); export const commonsServiceLineId = z.string(); export const commonsClaimId = z.string(); export const commonsEncounterId = z.string(); export const commonsProviderId = z.string(); export const commonsAppointmentId = z.string(); export const commonsPatientExternalId = z.string(); export const financialsAllocationTarget = z.discriminatedUnion("type", [z.object({type: z.literal("service_line"), service_line_id: commonsServiceLineId, claim_id: commonsClaimId, encounter_id: commonsEncounterId}), z.object({type: z.literal("claim"), claim_id: commonsClaimId, encounter_id: commonsEncounterId}), z.object({type: z.literal("billing_provider_id"), billing_provider_id: commonsProviderId}), z.object({type: z.literal("appointment"), appointment_id: commonsAppointmentId, patient_external_id: commonsPatientExternalId}), z.object({type: z.literal("unattributed")})]); export const commonsDate = z.string(); export const commonsEncounterExternalId = z.string(); export const financialsAllocationEarmarkType = z.discriminatedUnion("type", [z.object({type: z.literal("date_of_service"), value: commonsDate}), z.object({type: z.literal("external_encounter_id"), value: commonsEncounterExternalId})]); export const financialsBalanceEarmark = z.object({id: z.string(), target: financialsAllocationEarmarkType, amount_earmarked_cents: z.number().int().optional(), created_by_allocation_id: commonsAllocationId.optional()}); export const financialsAllocation = z.object({allocation_id: commonsAllocationId.optional(), amount_cents: z.number().int(), target: financialsAllocationTarget, earmark: financialsBalanceEarmark.optional(), allocated_on: z.string().optional()}); export const commonsInvoiceId = z.string(); export const nonInsurancePayerPaymentsV1NonInsurancePayerPayment = z.object({non_insurance_payer_payment_id: nonInsurancePayerPaymentsV1NonInsurancePayerPaymentId, non_insurance_payer: nonInsurancePayersV1NonInsurancePayer, amount_cents: z.number().int(), check_number: z.string().optional(), payment_timestamp: z.string().optional(), payment_note: z.string().optional(), allocations: z.array(financialsAllocation), invoice_id: commonsInvoiceId.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 }; /** * Update * * PATCH /api/non-insurance-payer-payments/v1/{non_insurance_payer_payment_id} */ export const patchApiApiNonInsurancePayerPaymentsV1NonInsurancePayerPaymentId = async (args: PatchApiApiNonInsurancePayerPaymentsV1NonInsurancePayerPaymentIdArgs, options?: PatchApiApiNonInsurancePayerPaymentsV1NonInsurancePayerPaymentIdOptions) => { const {baseUrl = "https://pre-api.joincandidhealth.com", fetch: fetchFn = fetch, OAuthScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuthScheme !== undefined) headers.set('authorization', `Bearer ${OAuthScheme}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/non-insurance-payer-payments/v1/${encodeURIComponent(String(args.non_insurance_payer_payment_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(nonInsurancePayerPaymentsV1NonInsurancePayerPayment, await res.json()) };