import {z} from 'zod' export type GetApiApiVitalTypesArgs = {includeInactive?: boolean | undefined}; export type GetApiApiVitalTypesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const vitalTypeDetailDto = z.object({id: z.string(), code: z.string(), label: z.string(), unit: z.string().nullable().optional(), color: z.string().nullable().optional(), dataType: z.string(), minValue: z.union([z.number(), z.string()]).nullable().optional(), maxValue: z.union([z.number(), z.string()]).nullable().optional(), displayOrder: z.union([z.number().int(), z.string()]).optional(), isActive: z.boolean().optional(), isSystem: z.boolean().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const getApiApiVitalTypesResponse = z.array(vitalTypeDetailDto); 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 }; /** * List vital measurement types. Active-only by default (clinical pickers / the exam * template palette); pass `includeInactive=true` for the management surface. * * GET /api/vital-types */ export const getApiApiVitalTypes = async (args: GetApiApiVitalTypesArgs, options?: GetApiApiVitalTypesOptions) => { 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 (args.includeInactive != null) query.append("includeInactive", String(args.includeInactive)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/vital-types${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(getApiApiVitalTypesResponse, await res.json()) };