import {z} from 'zod' export type GetApiPatientsIdSoapnotesArgs = {id: string}; export type GetApiPatientsIdSoapnotesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const soapNotePatientDto = z.object({id: z.string().optional(), name: z.string().optional(), species: z.string().optional(), breed: z.string().optional(), dateOfBirth: z.string().nullable().optional(), sex: z.string().optional()}); export const soapNoteAppointmentDto = z.object({id: z.string().optional(), reasonForVisit: z.string().optional(), status: z.string().optional()}); export const soapNoteUserDto = z.object({id: z.string().optional(), displayName: z.string().nullable().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().optional()}); export const soapAmendmentDto = z.object({id: z.string().optional(), soapNoteId: z.string().optional(), section: z.string().nullable().optional(), originalContent: z.string().optional(), amendedContent: z.string().optional(), reason: z.string().optional(), createdBy: soapNoteUserDto.nullable().optional(), createdById: z.string().optional(), createdAt: z.string().optional()}); export const soapNoteDto = z.object({id: z.string().optional(), patientId: z.string().optional(), appointmentId: z.string().nullable().optional(), subjective: z.string().optional(), objective: z.string().optional(), assessment: z.string().optional(), plan: z.string().optional(), format: z.string().optional(), status: z.string().optional(), createdById: z.string().optional(), lockedAt: z.string().nullable().optional(), lockedById: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), aiGenerated: z.boolean().optional(), aiConfidence: z.union([z.number(), z.string()]).nullable().optional(), aiFlags: z.string().nullable().optional(), appointmentRecordingId: z.string().nullable().optional(), patient: soapNotePatientDto.nullable().optional(), appointment: soapNoteAppointmentDto.nullable().optional(), createdBy: soapNoteUserDto.nullable().optional(), lockedBy: soapNoteUserDto.nullable().optional(), problemCount: z.union([z.number().int(), z.string()]).optional(), hasAmendments: z.boolean().optional(), amendments: z.array(soapAmendmentDto).nullable().optional(), isEditable: z.boolean().optional()}); export const getApiPatientsIdSoapnotesResponse = z.array(soapNoteDto); 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 }; /** * Get all SOAP notes for a patient * * GET /Patients/{id}/soapnotes */ export const getApiPatientsIdSoapnotes = async (args: GetApiPatientsIdSoapnotesArgs, options?: GetApiPatientsIdSoapnotesOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/Patients/${encodeURIComponent(String(args.id))}/soapnotes${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(getApiPatientsIdSoapnotesResponse, await res.json()) };