import {z} from 'zod' export type PatchPatientsIdAlertsAlertId = {patient_alert: {disabled?: boolean | undefined}}; export type PatchApiPatientsIdAlertsAlertIdArgs = {'Nex-Api-Version': string, id: number, alert_id: number, subdomain: string, body: PatchPatientsIdAlertsAlertId}; export type PatchApiPatientsIdAlertsAlertIdOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const aPIV2EntitiesPatientAlert = z.object({id: z.number().int().optional(), patient_id: z.number().int().optional(), note: z.string().optional(), disabled_at: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const aPIV2EntitiesPatientAlertResponse = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: aPIV2EntitiesPatientAlert.optional(), count: z.number().int().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 }; /** * Edit patient alert * * PATCH /patients/{id}/alerts/{alert_id} */ export const patchApiPatientsIdAlertsAlertId = async (args: PatchApiPatientsIdAlertsAlertIdArgs, options?: PatchApiPatientsIdAlertsAlertIdOptions) => { const {baseUrl = "https://nexhealth.info", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/vnd.Nexhealth+json;version=2") if (args['Nex-Api-Version'] != null) headers.set("Nex-Api-Version", String(args['Nex-Api-Version'])) if (args.subdomain != null) query.append("subdomain", String(args.subdomain)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/patients/${encodeURIComponent(String(args.id))}/alerts/${encodeURIComponent(String(args.alert_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(aPIV2EntitiesPatientAlertResponse, await res.json()) };