import {z} from 'zod' export type UpdateGroupSoapNoteRequest = {subjective?: (string | null) | undefined, objective?: (string | null) | undefined, assessment?: (string | null) | undefined, plan?: (string | null) | undefined, cohortLabel?: (string | null) | undefined}; export type PatchApiGroupVisitsAppointmentIdSoapSoapIdArgs = {appointmentId: string, soapId: string, body: UpdateGroupSoapNoteRequest}; export type PatchApiGroupVisitsAppointmentIdSoapSoapIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const memberExceptionDto = z.object({id: z.string().optional(), soapNoteId: z.string().optional(), patientGroupMemberId: z.string().optional(), memberDisplayName: z.string().optional(), exceptionNote: z.string().optional(), differentTreatment: z.boolean().optional(), followUpNeeded: z.boolean().optional(), createdAt: z.string().optional()}); export const groupSoapNoteDto = z.object({id: z.string().optional(), subjective: z.string().optional(), objective: z.string().optional(), assessment: z.string().optional(), plan: z.string().optional(), cohortLabel: z.string().nullable().optional(), status: z.string().optional(), format: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), exceptions: z.array(memberExceptionDto).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 }; /** * PATCH /GroupVisits/{appointmentId}/soap/{soapId} */ export const patchApiGroupVisitsAppointmentIdSoapSoapId = async (args: PatchApiGroupVisitsAppointmentIdSoapSoapIdArgs, options?: PatchApiGroupVisitsAppointmentIdSoapSoapIdOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/GroupVisits/${encodeURIComponent(String(args.appointmentId))}/soap/${encodeURIComponent(String(args.soapId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(groupSoapNoteDto, await res.json()) };