import {z} from 'zod' export type NonVisitNoteBullet = {author?: number | undefined, id?: number | undefined, text: string, updated_date?: string | undefined, version?: number | undefined}; 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 NonVisitNoteDocument = {document: Document, id?: number | undefined, summary?: (string | null) | undefined}; export type PatientItem = {created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, id?: number | undefined, is_confidential: boolean, patient: number, type: string}; export type NonVisitNotePatientItem = {id?: number | undefined, item: PatientItem}; export type NonVisitNote = {bullets?: Array | undefined, chart_date: string, created_date?: (string | null) | undefined, deleted_date?: (string | null) | undefined, document_date: string, id?: number | undefined, note_documents?: (Array) | undefined, note_items?: (Array) | undefined, patient: number, signed_by?: (number | null) | undefined, signed_date?: (string | null) | undefined, tags?: Array | undefined, type: string}; export type UpdateApiApi20NonVisitNotesIdArgs = {id: number, body: NonVisitNote}; export type UpdateApiApi20NonVisitNotesIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const nonVisitNoteBullet = z.object({author: z.number().int().optional(), id: z.number().int().optional(), text: z.string(), updated_date: z.string().optional(), version: z.number().int().gte(0).lte(65535).optional()}); 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 nonVisitNoteDocument = z.object({document: document, id: z.number().int().optional(), summary: z.string().nullable().optional()}); export const patientItem = z.object({created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), id: z.number().int().optional(), is_confidential: z.boolean(), patient: z.number().int(), type: z.string()}); export const nonVisitNotePatientItem = z.object({id: z.number().int().optional(), item: patientItem}); export const nonVisitNote = z.object({bullets: z.array(nonVisitNoteBullet).optional(), chart_date: z.string(), created_date: z.string().nullable().optional(), deleted_date: z.string().nullable().optional(), document_date: z.string(), id: z.number().int().optional(), note_documents: z.array(nonVisitNoteDocument.nullable()).optional(), note_items: z.array(nonVisitNotePatientItem.nullable()).optional(), patient: z.number().int(), signed_by: z.number().int().nullable().optional(), signed_date: z.string().nullable().optional(), tags: z.array(z.number().int()).optional(), type: z.string()}); 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 Non Visit Note * * PUT /api/2.0/non_visit_notes/{id}/ */ export const updateApiApi20NonVisitNotesId = async (args: UpdateApiApi20NonVisitNotesIdArgs, options?: UpdateApiApi20NonVisitNotesIdOptions) => { 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/non_visit_notes/${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(nonVisitNote, await res.json()) };