import {z} from 'zod' export type FastingMethodEnum = 'fasting_12_hour' | 'fasting_8_hours' | 'fasting_2_hours' | 'fasting_none' | 'fasting_random'; export type BlankEnum = ''; export type NullEnum = unknown; export type ICD10Code = {code: string, description?: (string | null) | undefined}; export type StatMethodEnum = 'wet_reading_phone' | 'wet_reading_fax' | 'stat_phone' | 'stat_fax' | 'stat_phone_fax'; export type LabOrderAOEQuestionChoice = {code: string, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, id?: number | undefined, value: string}; export type QuestionTypeEnum = 'enum' | 'enum_multiselect' | 'freetext' | 'y_or_n' | 'numeric' | 'yyyymmdd' | '2_numeric_1_decimal'; export type LabOrderAOEQuestion = {choices: Array, code: string, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, example_format?: (string | null) | undefined, id?: number | undefined, max_length?: (number | null) | undefined, question_type?: QuestionTypeEnum | undefined, secondary_code?: (string | null) | undefined, value: string}; export type LabOrderTestToLabOrderAOEQuestion = {question: LabOrderAOEQuestion, required?: boolean | undefined, sequence: number, test?: number | undefined}; export type LabOrderTestWithDiagnoses = {code?: (string | null) | undefined, compendium?: (number | null) | undefined, cpts?: Array | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, icd10_codes: Array, id?: number | undefined, lab_vendor?: (number | null) | undefined, name: string, practice_created?: (number | null) | undefined, procedure_class?: (string | null) | undefined, questions?: Array | undefined, synonyms?: Array | undefined}; export type LabOrderContent = {collection_datetime?: (string | null) | undefined, fasting_method?: (FastingMethodEnum | BlankEnum | NullEnum) | undefined, icd10_codes?: Array | undefined, id?: number | undefined, patient_instructions?: string | undefined, standing_order_end_date?: (string | null) | undefined, standing_order_frequency?: (string | null) | undefined, stat_method?: (StatMethodEnum | BlankEnum | NullEnum) | undefined, test_center_notes?: string | undefined, tests?: Array | undefined}; export type LabOrderSet = {compendium_code?: string | undefined, content: LabOrderContent, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, id?: number | undefined, lab_vendor?: (number | null) | undefined, name: string, practice: number}; export type UpdateApiApi20LabOrderSetsIdArgs = {id: number, body: LabOrderSet}; export type UpdateApiApi20LabOrderSetsIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fastingMethodEnum = z.enum(["fasting_12_hour", "fasting_8_hours", "fasting_2_hours", "fasting_none", "fasting_random"]); export const blankEnum = z.literal(""); export const nullEnum = z.unknown(); export const iCD10Code = z.object({code: z.string().max(50), description: z.string().max(500).nullable().optional()}); export const statMethodEnum = z.enum(["wet_reading_phone", "wet_reading_fax", "stat_phone", "stat_fax", "stat_phone_fax"]); export const labOrderAOEQuestionChoice = z.object({code: z.string().max(100), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), id: z.number().int().optional(), value: z.string()}); export const questionTypeEnum = z.enum(["enum", "enum_multiselect", "freetext", "y_or_n", "numeric", "yyyymmdd", "2_numeric_1_decimal"]); export const labOrderAOEQuestion = z.object({choices: z.array(labOrderAOEQuestionChoice), code: z.string().max(100), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), example_format: z.string().nullable().optional(), id: z.number().int().optional(), max_length: z.number().int().gte(0).lte(65535).nullable().optional(), question_type: questionTypeEnum.optional(), secondary_code: z.string().max(100).nullable().optional(), value: z.string()}); export const labOrderTestToLabOrderAOEQuestion = z.object({question: labOrderAOEQuestion, required: z.boolean().optional(), sequence: z.number().int().gte(0).lte(65535), test: z.number().int().optional()}); export const labOrderTestWithDiagnoses = z.object({code: z.string().max(50).nullable().optional(), compendium: z.number().int().nullable().optional(), cpts: z.array(z.string()).optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), icd10_codes: z.array(iCD10Code), id: z.number().int().optional(), lab_vendor: z.number().int().nullable().optional(), name: z.string().max(255), practice_created: z.number().int().nullable().optional(), procedure_class: z.string().max(50).nullable().optional(), questions: z.array(labOrderTestToLabOrderAOEQuestion).optional(), synonyms: z.array(z.string()).optional()}); export const labOrderContent = z.object({collection_datetime: z.string().nullable().optional(), fasting_method: z.union([fastingMethodEnum, blankEnum, nullEnum]).optional(), icd10_codes: z.array(iCD10Code).optional(), id: z.number().int().optional(), patient_instructions: z.string().optional(), standing_order_end_date: z.string().nullable().optional(), standing_order_frequency: z.string().max(50).nullable().optional(), stat_method: z.union([statMethodEnum, blankEnum, nullEnum]).optional(), test_center_notes: z.string().optional(), tests: z.array(labOrderTestWithDiagnoses).optional()}); export const labOrderSet = z.object({compendium_code: z.string().optional(), content: labOrderContent, created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), id: z.number().int().optional(), lab_vendor: z.number().int().nullable().optional(), name: z.string().max(250), practice: z.number().int()}); 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 Lab Order Set * * PUT /api/2.0/lab_order_sets/{id}/ */ export const updateApiApi20LabOrderSetsId = async (args: UpdateApiApi20LabOrderSetsIdArgs, options?: UpdateApiApi20LabOrderSetsIdOptions) => { 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/lab_order_sets/${encodeURIComponent(String(args.id))}/${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(labOrderSet, await res.json()) };