import {z} from 'zod' export type GetApiQuestionnaireResponsesIdHandoutArgs = {id: string}; export type GetApiQuestionnaireResponsesIdHandoutOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const handoutContentMode = z.number().int(); export const handoutAcknowledgementEvidenceDto = z.object({acknowledgedAt: z.string().nullable().optional(), signerName: z.string().nullable().optional(), signature: z.string().nullable().optional(), intentText: z.string().nullable().optional(), intentAffirmed: z.boolean().nullable().optional(), channel: z.string().nullable().optional(), ipAddress: z.string().nullable().optional(), userAgent: z.string().nullable().optional(), deviceName: z.string().nullable().optional(), capturedByName: z.string().nullable().optional()}); export const handoutResponseViewDto = z.object({responseId: z.string().optional(), questionnaireId: z.string().optional(), questionnaireName: z.string().optional(), version: z.union([z.number().int(), z.string()]).optional(), contentMode: handoutContentMode.optional(), fileName: z.string().nullable().optional(), url: z.string().nullable().optional(), urlExpiresAt: z.string().nullable().optional(), authoredSchema: z.string().nullable().optional(), acknowledgement: handoutAcknowledgementEvidenceDto.nullable().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 }; /** * Exactly what a sent handout showed the client (ITE-1477): the version its link was pinned * to, as a short-lived PDF URL or the authored snapshot, and the acknowledgement evidence. * Patients or Settings, like the signed consent PDF: the evidence carries the signer's * address and device. (The drawn signature itself is also in the response's answers, which * GET {id} serves to any staff user, as it always has for every form.) * * GET /QuestionnaireResponses/{id}/handout */ export const getApiQuestionnaireResponsesIdHandout = async (args: GetApiQuestionnaireResponsesIdHandoutArgs, options?: GetApiQuestionnaireResponsesIdHandoutOptions) => { 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(/\/+$/, '')}/QuestionnaireResponses/${encodeURIComponent(String(args.id))}/handout${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(handoutResponseViewDto, await res.json()) };