import {z} from 'zod' export type InsurancePaymentProgram = 'medicare_part_b' | 'medicare_advantage' | 'medicaid' | 'commercial_hmsa' | 'commercial_sfhp' | 'commercial_other' | 'workers_compensation'; export type InsurerRelationship = 'self' | 'child' | 'spouse' | 'other'; export type Status = 'active' | 'inactive'; export type PolicyPutRequestBasic = {address?: (string | null) | undefined, carrier_id?: (number | null) | undefined, carrier_name?: (string | null) | undefined, city?: (string | null) | undefined, copay?: (string | null) | undefined, county_code?: (string | null) | undefined, deductible?: (string | null) | undefined, end_date?: (string | null) | undefined, extension?: (string | null) | undefined, group_id?: (string | null) | undefined, id?: (number | null) | undefined, insured_person_address?: (string | null) | undefined, insured_person_city?: (string | null) | undefined, insured_person_dob?: (string | null) | undefined, insured_person_first_name?: (string | null) | undefined, insured_person_id?: (string | null) | undefined, insured_person_last_name?: (string | null) | undefined, insured_person_sex_at_birth?: (string | null) | undefined, insured_person_ssn?: (string | null) | undefined, insured_person_state?: (string | null) | undefined, insured_person_zip?: (string | null) | undefined, medicare_secondary_code?: (string | null) | undefined, member_id?: (string | null) | undefined, patient_dob: string, patient_first_name: string, patient_last_name: string, payment_program?: (InsurancePaymentProgram | null) | undefined, phone?: (string | null) | undefined, plan_id?: (number | null) | undefined, plan_name?: (string | null) | undefined, rank?: (number | null) | undefined, relationship_to_insured?: (InsurerRelationship | null) | undefined, start_date?: (string | null) | undefined, state?: (string | null) | undefined, status?: (Status | null) | undefined, suite?: (string | null) | undefined, vendor_company_id?: (number | null) | undefined, vendor_external_id?: (string | null) | undefined, zip?: (string | null) | undefined}; export type PolicyPutRequestBasicList = Array; export type UpdateApiPatientsPatientIdPoliciesArgs = {patient_id: number, body: PolicyPutRequestBasicList}; export type UpdateApiPatientsPatientIdPoliciesOptions = {baseUrl?: string | undefined, RequireAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const insurancePaymentProgram = z.enum(["medicare_part_b", "medicare_advantage", "medicaid", "commercial_hmsa", "commercial_sfhp", "commercial_other", "workers_compensation"]); export const insurerRelationship = z.enum(["self", "child", "spouse", "other"]); export const status = z.enum(["active", "inactive"]); export const policyResponse = z.object({address: z.string().max(200).nullable().optional(), back_image_path: z.string().nullable().optional(), can_check_eligibility: z.boolean().nullable().optional(), carrier_id: z.number().int().nullable().optional(), carrier_name: z.string().max(200).nullable().optional(), city: z.string().max(50).nullable().optional(), copay: z.string().max(19).nullable().optional(), county_code: z.string().max(10).nullable().optional(), deductible: z.string().max(19).nullable().optional(), end_date: z.string().nullable().optional(), extension: z.string().max(6).nullable().optional(), front_image_path: z.string().nullable().optional(), group_id: z.string().max(50).nullable().optional(), hippospace: z.string().max(255), id: z.number().int(), insured_person_address: z.string().max(200).nullable().optional(), insured_person_city: z.string().max(50).nullable().optional(), insured_person_dob: z.string().nullable().optional(), insured_person_first_name: z.string().max(200).nullable().optional(), insured_person_id: z.string().max(50).nullable().optional(), insured_person_last_name: z.string().max(200).nullable().optional(), insured_person_sex_at_birth: z.string().max(1).nullable().optional(), insured_person_ssn: z.string().max(11).nullable().optional(), insured_person_state: z.string().max(2).nullable().optional(), insured_person_zip: z.string().max(10).nullable().optional(), is_legacy_insurance: z.boolean().optional(), medicare_secondary_code: z.string().max(5).nullable().optional(), member_id: z.string().max(50).nullable().optional(), patient_dob: z.string(), patient_first_name: z.string().max(70), patient_id: z.number().int(), patient_last_name: z.string().max(70), payment_program: insurancePaymentProgram.nullable().optional(), phone: z.string().max(20).nullable().optional(), plan_id: z.number().int().nullable().optional(), plan_name: z.string().max(200).nullable().optional(), practice_id: z.number().int(), rank: z.number().int().nullable().optional(), relationship_to_insured: insurerRelationship.nullable().optional(), start_date: z.string().nullable().optional(), state: z.string().max(2).nullable().optional(), status: status, suite: z.string().max(40).nullable().optional(), vendor_company_id: z.number().int().nullable().optional(), vendor_external_id: z.string().max(100).nullable().optional(), zip: z.string().max(10).nullable().optional()}); export const policiesResponse = z.object({current_page_num: z.number().int().nullable().optional(), next_page_url: z.string().nullable().optional(), page_first_item_num: z.number().int().nullable().optional(), page_last_item_num: z.number().int().nullable().optional(), previous_page_url: z.string().nullable().optional(), results: z.array(policyResponse), total_item_count: z.number().int().nullable().optional(), total_page_count: z.number().int().nullable().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 }; /** * Put Policies * * PUT /patients/{patient_id}/policies */ export const updateApiPatientsPatientIdPolicies = async (args: UpdateApiPatientsPatientIdPoliciesArgs, options?: UpdateApiPatientsPatientIdPoliciesOptions) => { const {baseUrl = "https://sandbox.elationemr.com/api/2.0", fetch: fetchFn = fetch, RequireAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (RequireAuthentication !== undefined) headers.set('authorization', `Bearer ${RequireAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/patients/${encodeURIComponent(String(args.patient_id))}/policies${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(policiesResponse, await res.json()) };