import {z} from 'zod' export type GetApiAppointmentsAppointmentIdFormHandoffsArgs = {appointmentId: string}; export type GetApiAppointmentsAppointmentIdFormHandoffsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const formHandoffStatus = z.enum(["Pending", "Opened", "Completed", "Cancelled", "Expired"]); export const formHandoffTargetKind = z.enum(["Device", "Qr"]); export const questionnaireType = z.enum(["Intake", "PreVisit", "PostVisit", "Satisfaction", "Custom", "NewClient", "AppointmentConfirmation", "Consent", "Handout"]); export const formHandoffItemDto = z.object({id: z.string(), order: z.union([z.number().int(), z.string()]), questionnaireId: z.string(), questionnaireName: z.string(), questionnaireType: questionnaireType, patientId: z.string().nullable(), patientName: z.string().nullable(), questionnaireResponseId: z.string(), submittedAt: z.string().nullable()}); export const formHandoffQrDto = z.object({url: z.string(), expiresAt: z.string()}); export const formHandoffDto = z.object({id: z.string(), appointmentId: z.string(), clientId: z.string(), status: formHandoffStatus, targetKind: formHandoffTargetKind, targetDeviceId: z.string().nullable(), targetDeviceName: z.string().nullable(), launchedByUserId: z.string().nullable(), expiresAt: z.string(), createdAt: z.string(), openedAt: z.string().nullable(), completedAt: z.string().nullable(), cancelledAt: z.string().nullable(), items: z.array(formHandoffItemDto), qr: formHandoffQrDto.nullable().optional(), cancelledByUserId: z.string().nullable().optional()}); export const getApiAppointmentsAppointmentIdFormHandoffsResponse = z.array(formHandoffDto); 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 }; /** * Every handoff for the visit, newest first, with each form's status. * * GET /appointments/{appointmentId}/form-handoffs */ export const getApiAppointmentsAppointmentIdFormHandoffs = async (args: GetApiAppointmentsAppointmentIdFormHandoffsArgs, options?: GetApiAppointmentsAppointmentIdFormHandoffsOptions) => { 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(/\/+$/, '')}/appointments/${encodeURIComponent(String(args.appointmentId))}/form-handoffs${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(getApiAppointmentsAppointmentIdFormHandoffsResponse, await res.json()) };