import {z} from 'zod' export type GetApiPatientsIdContactsArgs = {id: string}; export type GetApiPatientsIdContactsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const clientSummaryDto = z.object({id: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), email: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional()}); export const contactRelationshipType = z.number().int(); export const contactVerificationMethod = z.number().int(); export const patientContactDto = z.object({id: z.string().optional(), patientId: z.string().optional(), clientId: z.string().optional(), client: clientSummaryDto.nullable().optional(), relationshipType: contactRelationshipType.optional(), isPrimary: z.boolean().optional(), permissions: z.array(z.string()).optional(), verificationMethod: contactVerificationMethod.optional(), verifiedByUserId: z.string().nullable().optional(), verifiedAt: z.string().nullable().optional(), verificationNotes: z.string().nullable().optional(), displayOrder: z.union([z.number().int(), z.string()]).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const getApiPatientsIdContactsResponse = z.array(patientContactDto); 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 the contacts (people) related to a patient, with relationship type and per-patient * permissions. Primary owner first. Part of the patient↔client relationship layer (PAW-626). * * GET /Patients/{id}/contacts */ export const getApiPatientsIdContacts = async (args: GetApiPatientsIdContactsArgs, options?: GetApiPatientsIdContactsOptions) => { 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))}/contacts${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(getApiPatientsIdContactsResponse, await res.json()) };