import {z} from 'zod' export type FundingSourceEnum = 'Privately funded vaccine stock' | 'Publicly funded vaccine stock' | 'Publicly funded vaccine stock - Non-VFC' | 'Publicly funded vaccine stock - VFC'; export type NullEnum = unknown; export type InfoSourceEnum = 'Historical information - from birth certificate' | 'Historical information - from other provider' | 'Historical information - from other registry' | 'Historical information - from parent's recall' | 'Historical information - from parent's written record' | 'Historical information - from public agency' | 'Historical information - from school record' | 'Historical information - source unspecified' | 'New immunization record'; export type PublicityCodeEnum = 'No reminder/recall' | 'Only recall to provider, no reminder' | 'Only reminder to provider, no recall' | 'Recall only - any method' | 'Recall only - no calls' | 'Recall to provider' | 'Reminder only - any method' | 'Reminder only - no calls' | 'Reminder to provider' | 'Reminder/recall - any method' | 'Reminder/recall - no calls' | 'Reminder/recall - to provider'; export type ImmunizationVaccine = {name?: (string | null) | undefined}; export type VfcEligibilityEnum = '317' | 'CA State General Fund Vaccines' | 'CHIP' | 'HI Adult Insured' | 'HI Adult Not Insured' | 'HI Birthing Hospital Hepatitis B' | 'Local-specific eligibility' | 'ME State Eligible - Insured - Under 19' | 'Medicare' | 'Not VFC eligible' | 'OR Locally Owned' | 'OR Special Projects' | 'State program eligibility' | 'VFC eligible - American Indian/Alaskan Native' | 'VFC eligible - Medicaid/Medicaid Managed Care' | 'VFC eligible - Under-insured' | 'VFC eligible - Uninsured'; export type PatientImmunization = {administered_date: string, administering_physician: number | null, allowed_sharing?: (boolean | null) | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, description?: (string | null) | undefined, dose_in_series?: (number | null) | undefined, expiration_date?: (string | null) | undefined, funding_source?: (FundingSourceEnum | NullEnum) | undefined, id?: number | undefined, info_source?: (InfoSourceEnum | NullEnum) | undefined, lot_number?: (string | null) | undefined, manufacturer_code?: (string | null) | undefined, manufacturer_name?: (string | null) | undefined, method?: (string | null) | undefined, ndc?: (string | null) | undefined, notes?: (string | null) | undefined, ordering_physician: number | null, patient: number, patient_consent?: (boolean | null) | undefined, practice?: (number | null) | undefined, priority_population?: (string | null) | undefined, publicity_code?: (PublicityCodeEnum | NullEnum) | undefined, qty: string | null, qty_units?: (string | null) | undefined, reason?: (string | null) | undefined, service_location_id?: (number | null) | undefined, site?: (string | null) | undefined, vaccine: ImmunizationVaccine, vfc_eligibility?: (VfcEligibilityEnum | NullEnum) | undefined, vis?: (string | null) | undefined, vis_given_date?: (string | null) | undefined}; export type CreateApiApi20ImmunizationsArgs = {body: PatientImmunization}; export type CreateApiApi20ImmunizationsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fundingSourceEnum = z.enum(["Privately funded vaccine stock", "Publicly funded vaccine stock", "Publicly funded vaccine stock - Non-VFC", "Publicly funded vaccine stock - VFC"]); export const nullEnum = z.unknown(); export const infoSourceEnum = z.enum(["Historical information - from birth certificate", "Historical information - from other provider", "Historical information - from other registry", "Historical information - from parent's recall", "Historical information - from parent's written record", "Historical information - from public agency", "Historical information - from school record", "Historical information - source unspecified", "New immunization record"]); export const publicityCodeEnum = z.enum(["No reminder/recall", "Only recall to provider, no reminder", "Only reminder to provider, no recall", "Recall only - any method", "Recall only - no calls", "Recall to provider", "Reminder only - any method", "Reminder only - no calls", "Reminder to provider", "Reminder/recall - any method", "Reminder/recall - no calls", "Reminder/recall - to provider"]); export const immunizationVaccine = z.object({name: z.string().nullable().optional()}); export const vfcEligibilityEnum = z.enum(["317", "CA State General Fund Vaccines", "CHIP", "HI Adult Insured", "HI Adult Not Insured", "HI Birthing Hospital Hepatitis B", "Local-specific eligibility", "ME State Eligible - Insured - Under 19", "Medicare", "Not VFC eligible", "OR Locally Owned", "OR Special Projects", "State program eligibility", "VFC eligible - American Indian/Alaskan Native", "VFC eligible - Medicaid/Medicaid Managed Care", "VFC eligible - Under-insured", "VFC eligible - Uninsured"]); export const patientImmunization = z.object({administered_date: z.string(), administering_physician: z.number().int().nullable(), allowed_sharing: z.boolean().nullable().optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), description: z.string().max(255).nullable().optional(), dose_in_series: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), expiration_date: z.string().nullable().optional(), funding_source: z.union([fundingSourceEnum, nullEnum]).optional(), id: z.number().int().optional(), info_source: z.union([infoSourceEnum, nullEnum]).optional(), lot_number: z.string().max(255).nullable().optional(), manufacturer_code: z.string().max(255).nullable().optional(), manufacturer_name: z.string().max(255).nullable().optional(), method: z.string().max(255).nullable().optional(), ndc: z.string().max(31).nullable().optional(), notes: z.string().nullable().optional(), ordering_physician: z.number().int().nullable(), patient: z.number().int(), patient_consent: z.boolean().nullable().optional(), practice: z.number().int().nullable().optional(), priority_population: z.string().max(8).nullable().optional(), publicity_code: z.union([publicityCodeEnum, nullEnum]).optional(), qty: z.string().nullable(), qty_units: z.string().max(100).nullable().optional(), reason: z.string().nullable().optional(), service_location_id: z.number().int().nullable().optional(), site: z.string().max(255).nullable().optional(), vaccine: immunizationVaccine, vfc_eligibility: z.union([vfcEligibilityEnum, nullEnum]).optional(), vis: z.string().nullable().optional(), vis_given_date: z.string().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 }; /** * Create Immunization * * POST /api/2.0/immunizations/ */ export const createApiApi20Immunizations = async (args: CreateApiApi20ImmunizationsArgs, options?: CreateApiApi20ImmunizationsOptions) => { const {baseUrl = "https://sandbox.elationemr.com/api/2.0", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/2.0/immunizations/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(patientImmunization, await res.json()) };