import {z} from 'zod' export type AmendmentSourceEnum = 'Patient' | 'Provider or Organization'; export type AmendmentRequestStatusEnum = 'accepted' | 'denied'; export type AmendmentRequest = {amendment_source: AmendmentSourceEnum, request_date?: (string | null) | undefined, request_description: string, status: AmendmentRequestStatusEnum, status_updated_date?: (string | null) | undefined}; export type CategoryEnum = 'Allergies' | 'Assessment' | 'Assessplan' | 'Attending' | 'Consultant' | 'Data' | 'Dateprocedure' | 'ElationNoteColOne' | 'ElationNoteColTwo' | 'ElationNoteCustomBlock' | 'ElationNoteOtherData' | 'Family' | 'Followup' | 'Habits' | 'Hpi' | 'Instr' | 'Med' | 'Narrative' | 'Objective' | 'Orders' | 'PE' | 'Past' | 'Plan' | 'Problem' | 'Procedure' | 'ROS' | 'Reason' | 'Referenced' | 'Social' | 'Surgical' | 'Test' | 'Tx'; export type Document = {authoring_practice: number, chart_date: string, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, document_date: string, document_type?: (number | null) | undefined, id: number, last_modified?: string | undefined, patient: number, sign_date?: (string | null) | undefined, signed_by?: number | undefined}; export type VisitNoteDocument = {document: Document, id?: number | undefined, summary?: (string | null) | undefined}; export type BulletWithMeta = {author?: number | undefined, category: CategoryEnum, deleted_date?: (string | null) | undefined, edit?: (number | null) | undefined, note_document?: (VisitNoteDocument | null) | undefined, replaced_by?: (number | null) | undefined, replaced_by_edit?: (number | null) | undefined, sequence?: number | undefined, text: string, updated_date?: (string | null) | undefined, version?: number | undefined}; export type VisitNoteEdit = {create_user?: number | undefined, created_date?: (string | null) | undefined, new_bmi?: number | undefined, new_note_time?: string | undefined, new_note_type?: string | undefined, new_prev_bmi?: number | undefined, new_prev_time?: string | undefined, new_prev_weight?: string | undefined, previous_bmi?: number | undefined, previous_note_time?: string | undefined, previous_note_type?: string | undefined, previous_prev_bmi?: number | undefined, previous_prev_time?: string | undefined, previous_prev_weight?: string | undefined, visit_note: number}; export type VisitNoteSignatureList = Array<{comments: string, role: string, signed_date: string, user: string, user_name: string}>; export type TemplateEnum = 'Complete H&P (1 col)' | 'Complete H&P (2 col A/P)' | 'Complete H&P (2 col)' | 'Pre-Op' | 'SOAP' | 'Simple'; export type VisitNote = {amendment_request?: AmendmentRequest | undefined, bullets: Array, chart_date: string, checklists?: {[key: string]: Array<{name: string, sequence: number, value: string}>} | undefined, clinical_summary_link?: string | undefined, confidential?: boolean | undefined, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, document_date: string, edits?: Array | undefined, id?: number | undefined, last_modified?: string | undefined, patient: number, physician: number, practice?: number | undefined, signatures?: VisitNoteSignatureList | undefined, signed_by?: (number | null) | undefined, signed_date?: (string | null) | undefined, template: TemplateEnum, type?: string | undefined, visit_summary_link?: string | undefined}; export type CreateApiApi20VisitNotesArgs = {body: VisitNote}; export type CreateApiApi20VisitNotesOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const amendmentSourceEnum = z.enum(["Patient", "Provider or Organization"]); export const amendmentRequestStatusEnum = z.enum(["accepted", "denied"]); export const amendmentRequest = z.object({amendment_source: amendmentSourceEnum, request_date: z.string().nullable().optional(), request_description: z.string(), status: amendmentRequestStatusEnum, status_updated_date: z.string().nullable().optional()}); export const categoryEnum = z.enum(["Allergies", "Assessment", "Assessplan", "Attending", "Consultant", "Data", "Dateprocedure", "ElationNoteColOne", "ElationNoteColTwo", "ElationNoteCustomBlock", "ElationNoteOtherData", "Family", "Followup", "Habits", "Hpi", "Instr", "Med", "Narrative", "Objective", "Orders", "PE", "Past", "Plan", "Problem", "Procedure", "ROS", "Reason", "Referenced", "Social", "Surgical", "Test", "Tx"]); export const document = z.object({authoring_practice: z.number().int(), chart_date: z.string(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), document_date: z.string(), document_type: z.number().int().nullable().optional(), id: z.number().int(), last_modified: z.string().optional(), patient: z.number().int(), sign_date: z.string().nullable().optional(), signed_by: z.number().int().optional()}); export const visitNoteDocument = z.object({document: document, id: z.number().int().optional(), summary: z.string().nullable().optional()}); export const bulletWithMeta = z.object({author: z.number().int().optional(), category: categoryEnum, deleted_date: z.string().nullable().optional(), edit: z.number().int().nullable().optional(), note_document: visitNoteDocument.nullable().optional(), replaced_by: z.number().int().nullable().optional(), replaced_by_edit: z.number().int().nullable().optional(), sequence: z.number().int().gte(0).optional(), text: z.string(), updated_date: z.string().nullable().optional(), version: z.number().int().gte(0).lte(65535).optional()}); export const visitNoteEdit = z.object({create_user: z.number().int().optional(), created_date: z.string().nullable().optional(), new_bmi: z.number().optional(), new_note_time: z.string().optional(), new_note_type: z.string().optional(), new_prev_bmi: z.number().optional(), new_prev_time: z.string().optional(), new_prev_weight: z.string().max(10).optional(), previous_bmi: z.number().optional(), previous_note_time: z.string().optional(), previous_note_type: z.string().optional(), previous_prev_bmi: z.number().optional(), previous_prev_time: z.string().optional(), previous_prev_weight: z.string().max(10).optional(), visit_note: z.number().int()}); export const visitNoteSignatureList = z.array(z.object({comments: z.string(), role: z.string(), signed_date: z.string(), user: z.string(), user_name: z.string()})); export const templateEnum = z.enum(["Complete H&P (1 col)", "Complete H&P (2 col A/P)", "Complete H&P (2 col)", "Pre-Op", "SOAP", "Simple"]); export const visitNote = z.object({amendment_request: amendmentRequest.optional(), bullets: z.array(bulletWithMeta), chart_date: z.string(), checklists: z.record(z.string(), z.array(z.object({name: z.string(), sequence: z.number().int(), value: z.string()}))).optional(), clinical_summary_link: z.string().optional(), confidential: z.boolean().optional(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), document_date: z.string(), edits: z.array(visitNoteEdit).optional(), id: z.number().int().optional(), last_modified: z.string().optional(), patient: z.number().int(), physician: z.number().int(), practice: z.number().int().optional(), signatures: visitNoteSignatureList.optional(), signed_by: z.number().int().nullable().optional(), signed_date: z.string().nullable().optional(), template: templateEnum, type: z.string().optional(), visit_summary_link: z.string().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 Visit Note * * POST /api/2.0/visit_notes/ */ export const createApiApi20VisitNotes = async (args: CreateApiApi20VisitNotesArgs, options?: CreateApiApi20VisitNotesOptions) => { 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/visit_notes/${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(visitNote, await res.json()) };