import {z} from 'zod' export type GetApiApi20MedicationOrderTemplatesIdArgs = {id: number}; export type GetApiApi20MedicationOrderTemplatesIdOptions = {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 }; /** * Retrieve Medication Order Template * * GET /api/2.0/medication_order_templates/{id}/ */ export const getApiApi20MedicationOrderTemplatesId = async (args: GetApiApi20MedicationOrderTemplatesIdArgs, options?: GetApiApi20MedicationOrderTemplatesIdOptions) => { const {baseUrl = "https://sandbox.elationemr.com/api/2.0", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) 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()) };