import {z} from 'zod' export type RecordDischargeSignOffRequest = {instructionsAcknowledged?: boolean | undefined, instructionsHash?: (string | null) | undefined, signedName?: (string | null) | undefined, signatureData?: (string | null) | undefined, disclaimerVersionIds?: (Array | null) | undefined}; export type CreateApiDischargeDocumentsDocumentIdSignOffArgs = {documentId: string, body: RecordDischargeSignOffRequest}; export type CreateApiDischargeDocumentsDocumentIdSignOffOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const disclaimerAcknowledgementDto = z.object({id: z.string().optional(), disclaimerId: z.string().optional(), disclaimerVersionId: z.string().optional(), versionNumber: z.union([z.number().int(), z.string()]).optional(), title: z.string().optional(), body: z.string().optional(), contentHash: z.string().optional(), requiredAcknowledgement: z.boolean().optional(), signedName: z.string().nullable().optional(), createdAt: z.string().optional()}); export const dischargeSignOffDto = z.object({id: z.string().optional(), signedName: z.string().optional(), signedAt: z.string().optional(), isCurrent: z.boolean().optional(), acknowledgements: z.array(disclaimerAcknowledgementDto).optional()}); export const dischargeSignOffStatusDto = z.object({requiresSignOff: z.boolean().optional(), signOff: dischargeSignOffDto.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 }; /** * Records a sign-off. 409 `INSTRUCTIONS_CHANGED` when the instructions were edited * after the screen showed them (the request carries a fingerprint of the text shown), and * 409 `DISCLAIMERS_CHANGED` with the live blocks when the client was shown a stale set * of notices. The document row is locked while checking and writing, so an edit can't * land between the check and the sign-off. * * POST /discharge-documents/{documentId}/sign-off */ export const createApiDischargeDocumentsDocumentIdSignOff = async (args: CreateApiDischargeDocumentsDocumentIdSignOffArgs, options?: CreateApiDischargeDocumentsDocumentIdSignOffOptions) => { 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(/\/+$/, '')}/discharge-documents/${encodeURIComponent(String(args.documentId))}/sign-off${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(dischargeSignOffStatusDto, await res.json()) };