import {z} from 'zod' export type GetApiPatientsPatientIdTreatmentNotesArgs = {patient_id: unknown, page?: number | undefined, per_page?: number | undefined, sort?: Array | undefined, order?: ('asc' | 'desc') | undefined, 'q[]'?: Array | undefined}; export type GetApiPatientsPatientIdTreatmentNotesOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const treatmentNoteQuestionText = z.object({answer: z.string().optional(), name: z.string().max(255), type: z.literal("text").nullable()}); export const treatmentNoteQuestionParagraph = z.object({answer: z.string().optional(), name: z.string().max(255), type: z.literal("paragraph").nullable()}); export const treatmentNoteQuestionDate = z.object({answer: z.string().optional(), name: z.string().max(255), type: z.literal("date").nullable()}); export const treatmentNoteQuestionBodycharts = z.object({body_chart_ids: z.array(z.string()).optional(), name: z.string().max(255), type: z.literal("bodycharts").nullable()}); export const treatmentNoteQuestionCheckboxes = z.object({answers: z.array(z.object({value: z.string().max(255).nullable().optional(), selected: z.boolean().nullable().optional()})).optional(), other: z.object({enabled: z.boolean().optional(), selected: z.boolean().optional(), value: z.string().max(255).optional()}).optional(), name: z.string().max(255), type: z.literal("checkboxes").nullable()}); export const treatmentNoteQuestionRadiobuttons = z.object({answers: z.array(z.object({value: z.string().max(255).nullable().optional(), selected: z.boolean().nullable().optional()})).optional(), other: z.object({enabled: z.boolean().optional(), selected: z.boolean().optional(), value: z.string().max(255).optional()}).optional(), name: z.string().max(255), type: z.literal("radiobuttons").nullable()}); export const treatmentNote = z.object({archived_at: z.string().nullable().optional(), attendee: z.object({links: z.object({self: z.string().optional()}).optional()}).optional(), author_name: z.string().nullable().optional(), body_charts: z.object({links: z.object({self: z.string().optional()}).optional()}).optional(), booking: z.object({links: z.object({self: z.string().optional()}).optional()}).optional(), content: z.object({sections: z.array(z.object({name: z.string().max(255).nullable().optional(), description: z.string().nullable().optional(), questions: z.array(z.union([treatmentNoteQuestionText, treatmentNoteQuestionParagraph, treatmentNoteQuestionDate, treatmentNoteQuestionBodycharts, treatmentNoteQuestionCheckboxes, treatmentNoteQuestionRadiobuttons])).optional()})).optional()}).nullable().optional(), created_at: z.string().optional(), deleted_at: z.string().nullable().optional(), draft: z.boolean().optional(), finalized_at: z.string().nullable().optional(), id: z.string().optional(), links: z.object({self: z.string().optional()}).optional(), patient: z.object({links: z.object({self: z.string().optional()}).optional()}).optional(), pinned_at: z.string().nullable().optional(), practitioner: z.object({links: z.object({self: z.string().optional()}).optional()}).optional(), title: z.string().optional(), treatment_note_template: z.object({links: z.object({self: z.string().optional()}).optional()}).optional(), updated_at: z.string().optional()}); export const getApiPatientsPatientIdTreatmentNotesResponse = z.object({treatment_notes: z.array(treatmentNote).optional(), total_entries: z.number().int().optional(), links: z.object({self: z.string().optional(), previous: z.string().optional(), next: z.string().optional()}).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 }; /** * List treatment notes for patient * * GET /patients/{patient_id}/treatment_notes */ export const getApiPatientsPatientIdTreatmentNotes = async (args: GetApiPatientsPatientIdTreatmentNotesArgs, options?: GetApiPatientsPatientIdTreatmentNotesOptions) => { const {baseUrl = "https://api.au1.cliniko.com/v1", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort != null) query.append("sort", args.sort.join(',')) if (args.order != null) query.append("order", String(args.order)) for (const item of args['q[]'] ?? []) query.append("q[]", String(item)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/patients/${encodeURIComponent(String(args.patient_id))}/treatment_notes${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(getApiPatientsPatientIdTreatmentNotesResponse, await res.json()) };