import {z} from 'zod' export type MedicationDrugType = 'user' | 'medispan' | 'ss' | 'disp'; export type MedicationType = 'otc' | 'prescription' | 'discontinued'; export type Medication = {active_ndcs?: Array | undefined, brand_name?: string | undefined, created_date?: (string | null) | undefined, creation_type?: MedicationDrugType | undefined, form?: string | undefined, generic_name?: string | undefined, id?: number | undefined, is_controlled?: boolean | undefined, market_end_date?: (string | null) | undefined, name?: string | undefined, ndcs?: Array | undefined, obsolete_date?: (string | null) | undefined, practice?: number | undefined, route?: string | undefined, rxnorm_cuis?: Array | undefined, strength?: (string | null) | undefined, type?: MedicationType | undefined}; export type QtyUnitsEnum = 'BAG' | 'BOTTLE' | 'BOX' | 'CAPSULE' | 'CARTRIDGE' | 'CONTAINER' | 'DROP' | 'GRAM' | 'INHALER' | 'INTERNATIONAL UNITE' | 'KIT' | 'LITER' | 'LOZENGE' | 'MILLIGRAM' | 'MILLILITER' | 'MILLION UNITS' | 'MUTUALLY DEFINED' | 'FLUID OUNCE' | 'NOT SPECIFIED' | 'PACK' | 'PACKET' | 'PINT' | 'SUPPOSITORY' | 'SYRINGE' | 'TABLESPOON' | 'TABLET' | 'TEASPOON' | 'TRANSDERMAL PATCH' | 'TUBE' | 'UNIT' | 'VIAL' | 'EACH' | 'GUM' | 'AMPULE' | 'APPLICATOR' | 'APPLICATORFUL' | 'BAR' | 'BEAD' | 'BLISTER' | 'BLOCK' | 'BOLUS' | 'CAN' | 'CANISTER' | 'CAPLET' | 'CARTON' | 'CASE' | 'CASSETTE' | 'CYLINDER' | 'DISK' | 'DOSE PACK' | 'DUAL PACK' | 'FILM' | 'GALLON' | 'IMPLANT' | 'INHALATION' | 'INHALER REFILL' | 'INSERT' | 'INTRAVENOUS BAG' | 'KILOGRAM' | 'METRIC DROP' | 'MILLIMETER' | 'NEBULE' | 'NEEDLE FREE INJECTION' | 'OCULAR SYSTEM' | 'OUNCE' | 'PACKAGE' | 'PAD' | 'PAPER' | 'PATCH' | 'PEN NEEDLE' | 'POUCH' | 'POUND' | 'PRE-FILLED PEN SYRINGE' | 'PUFF' | 'QUART' | 'RING' | 'SACHET' | 'SCOOPFUL' | 'SPONGE' | 'SPRAY' | 'STICK' | 'STRIP' | 'SWAB' | 'TABMINDER' | 'TAMPON' | 'TRAY' | 'TROCHE' | 'WAFER'; export type BlankEnum = ''; export type NullEnum = unknown; export type PatchedMedOrderTemplate = {auth_refills?: (number | null) | undefined, deleted_date?: (string | null) | undefined, directions?: (string | null) | undefined, id?: number | undefined, medication?: Medication | undefined, practice?: number | undefined, qty?: (unknown | null) | undefined, qty_units?: (QtyUnitsEnum | BlankEnum | NullEnum) | undefined, rank?: number | undefined, specific_ndc?: (string | null) | undefined}; export type PatchApiApi20MedicationOrderTemplatesIdArgs = {id: number, body: PatchedMedOrderTemplate}; export type PatchApiApi20MedicationOrderTemplatesIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const medicationDrugType = z.enum(["user", "medispan", "ss", "disp"]); export const medicationType = z.enum(["otc", "prescription", "discontinued"]); export const medication = z.object({active_ndcs: z.array(z.string()).optional(), brand_name: z.string().optional(), created_date: z.string().nullable().optional(), creation_type: medicationDrugType.optional(), form: z.string().optional(), generic_name: z.string().optional(), id: z.number().int().optional(), is_controlled: z.boolean().optional(), market_end_date: z.string().nullable().optional(), name: z.string().optional(), ndcs: z.array(z.string()).optional(), obsolete_date: z.string().nullable().optional(), practice: z.number().int().optional(), route: z.string().optional(), rxnorm_cuis: z.array(z.string()).optional(), strength: z.string().max(255).nullable().optional(), type: medicationType.optional()}); export const qtyUnitsEnum = z.enum(["BAG", "BOTTLE", "BOX", "CAPSULE", "CARTRIDGE", "CONTAINER", "DROP", "GRAM", "INHALER", "INTERNATIONAL UNITE", "KIT", "LITER", "LOZENGE", "MILLIGRAM", "MILLILITER", "MILLION UNITS", "MUTUALLY DEFINED", "FLUID OUNCE", "NOT SPECIFIED", "PACK", "PACKET", "PINT", "SUPPOSITORY", "SYRINGE", "TABLESPOON", "TABLET", "TEASPOON", "TRANSDERMAL PATCH", "TUBE", "UNIT", "VIAL", "EACH", "GUM", "AMPULE", "APPLICATOR", "APPLICATORFUL", "BAR", "BEAD", "BLISTER", "BLOCK", "BOLUS", "CAN", "CANISTER", "CAPLET", "CARTON", "CASE", "CASSETTE", "CYLINDER", "DISK", "DOSE PACK", "DUAL PACK", "FILM", "GALLON", "IMPLANT", "INHALATION", "INHALER REFILL", "INSERT", "INTRAVENOUS BAG", "KILOGRAM", "METRIC DROP", "MILLIMETER", "NEBULE", "NEEDLE FREE INJECTION", "OCULAR SYSTEM", "OUNCE", "PACKAGE", "PAD", "PAPER", "PATCH", "PEN NEEDLE", "POUCH", "POUND", "PRE-FILLED PEN SYRINGE", "PUFF", "QUART", "RING", "SACHET", "SCOOPFUL", "SPONGE", "SPRAY", "STICK", "STRIP", "SWAB", "TABMINDER", "TAMPON", "TRAY", "TROCHE", "WAFER"]); export const blankEnum = z.literal(""); export const nullEnum = z.unknown(); export const medOrderTemplate = z.object({auth_refills: z.number().int().gte(0).lte(99).nullable().optional(), deleted_date: z.string().nullable().optional(), directions: z.string().max(300).nullable().optional(), id: z.number().int().optional(), medication: medication, practice: z.number().int(), qty: z.string().nullable().optional(), qty_units: z.union([qtyUnitsEnum, blankEnum, nullEnum]).optional(), rank: z.number().int().optional(), specific_ndc: 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 }; /** * Partially Update Medication Order Template * * PATCH /api/2.0/medication_order_templates/{id}/ */ export const patchApiApi20MedicationOrderTemplatesId = async (args: PatchApiApi20MedicationOrderTemplatesIdArgs, options?: PatchApiApi20MedicationOrderTemplatesIdOptions) => { 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/medication_order_templates/${encodeURIComponent(String(args.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(medOrderTemplate, await res.json()) };