import {z} from 'zod' export type GetApiSurgicalRecordsIdAnesthesiaChartArgs = {id: string}; export type GetApiSurgicalRecordsIdAnesthesiaChartOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const anesthesiaChartAxis = z.number().int(); export const anesthesiaChartPointDto = z.object({at: z.string().optional(), value: z.union([z.number(), z.string()]).optional(), rowId: z.string().nullable().optional()}); export const anesthesiaChartSeriesDto = z.object({metric: z.string().optional(), label: z.string().optional(), unit: z.string().optional(), axis: anesthesiaChartAxis.optional(), points: z.array(anesthesiaChartPointDto).optional()}); export const anesthesiaChartMarkerKind = z.number().int(); export const anesthesiaChartMarkerDto = z.object({at: z.string().optional(), kind: anesthesiaChartMarkerKind.optional(), label: z.string().optional(), detail: z.string().nullable().optional(), eventId: z.string().optional()}); export const surgeryPhase = z.number().int(); export const anesthesiaChartBandDto = z.object({phase: surgeryPhase.optional(), from: z.string().optional(), to: z.string().optional()}); export const anesthesiaChartDto = z.object({temperatureUnit: z.string().optional(), series: z.array(anesthesiaChartSeriesDto).optional(), markers: z.array(anesthesiaChartMarkerDto).optional(), phaseBands: z.array(anesthesiaChartBandDto).optional(), unplacedRowCount: z.union([z.number().int(), z.string()]).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 }; /** * The anesthesia record as chart data (ITE-1331, flag `AnesthesiaChart`): grid series on * a real time axis, drug / fluid / milestone markers and phase bands. Built on read, like the * phases, so a corrected time or a late grid edit shows on the next read; a finalized record * reads the same way. * * GET /SurgicalRecords/{id}/anesthesia-chart */ export const getApiSurgicalRecordsIdAnesthesiaChart = async (args: GetApiSurgicalRecordsIdAnesthesiaChartArgs, options?: GetApiSurgicalRecordsIdAnesthesiaChartOptions) => { 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(/\/+$/, '')}/SurgicalRecords/${encodeURIComponent(String(args.id))}/anesthesia-chart${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(anesthesiaChartDto, await res.json()) };