import {z} from 'zod' export type GetApiApiVaccinationsSchedulePatientIdArgs = {patientId: string}; export type GetApiApiVaccinationsSchedulePatientIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const vaccinationStatus = z.number().int(); export const vaccineScheduleEntryStatus = z.number().int(); export const patientVaccineScheduleEntryDto = z.object({vaccineTypeId: z.string().optional(), code: z.string().optional(), name: z.string().optional(), isCore: z.boolean().optional(), isRabies: z.boolean().optional(), countsTowardStatus: z.boolean().optional(), isSpeciesMismatch: z.boolean().optional(), status: vaccineScheduleEntryStatus.optional(), lastDoseDate: z.string().nullable().optional(), lastDoseRecordId: z.string().nullable().optional(), lastDoseVaccineName: z.string().nullable().optional(), nextDueDate: z.string().nullable().optional(), exemptionId: z.string().nullable().optional(), skipReason: z.string().nullable().optional(), skippedAt: z.string().nullable().optional(), skippedByName: z.string().nullable().optional()}); export const patientVaccineScheduleDto = z.object({patientId: z.string().optional(), species: z.string().optional(), overallStatus: vaccinationStatus.optional(), entries: z.array(patientVaccineScheduleEntryDto).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 computed vaccine schedule for a patient: core requirements for their species plus other * vaccines on file, each with last dose, next due, and standing — the explanation behind the * patient's VaccinationStatus badge (ITE-685). * * GET /api/Vaccinations/schedule/{patientId} */ export const getApiApiVaccinationsSchedulePatientId = async (args: GetApiApiVaccinationsSchedulePatientIdArgs, options?: GetApiApiVaccinationsSchedulePatientIdOptions) => { 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(/\/+$/, '')}/api/Vaccinations/schedule/${encodeURIComponent(String(args.patientId))}${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(patientVaccineScheduleDto, await res.json()) };