import {z} from 'zod' export type GetApiPatientsPatientIdPatientStarPlotSummaryArgs = {patient_id: number, date_since: string, date_until: string, disaggregated: boolean, daily_avg_method: boolean, include_statements?: boolean | undefined, n_frequency_items?: number | undefined, include_non_ranked_items?: boolean | undefined, include_custom_items?: boolean | undefined, enforce_unique_base_food?: boolean | undefined}; export type GetApiPatientsPatientIdPatientStarPlotSummaryOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patientFoodFrequencyItemsResponse = z.object({both_fat: z.array(z.string()).nullable().optional(), fibre: z.array(z.string()).nullable(), fruit: z.array(z.string()).nullable(), healthy_fat: z.array(z.string()).nullable(), omega_three: z.array(z.string()).nullable(), plant_based: z.array(z.string()).nullable(), protein: z.array(z.string()).nullable(), refined_grain: z.array(z.string()).nullable().optional(), sugary_beverage: z.array(z.string()).nullable(), ultra_processed: z.array(z.string()).nullable(), unhealthy_fat: z.array(z.string()).nullable(), vegetable: z.array(z.string()).nullable(), whole_grain: z.array(z.string()).nullable()}); export const patientStarPlotResponse = z.object({calorie_ratio: z.number(), doing_right_statement: z.array(z.string()).nullable().optional(), fat_ratio_pct_of_target: z.number(), fiber_pct_of_target: z.number(), food_frequency_items: patientFoodFrequencyItemsResponse.optional(), fruit_pct_of_target: z.number(), header_statement: z.string().nullable().optional(), healthy_bev_pct_of_total: z.number(), healthy_fat_kcal_pct_of_total: z.number().optional(), non_red_meat_pct_of_protein: z.number(), patient_id: z.number().int(), plant_based_pct: z.number(), poultry_frequency_weekly: z.number(), redmeat_frequency_weekly: z.number(), ultra_processed_pct_of_total: z.number().optional(), ultraprocessed_pct_of_total: z.number(), unhealthy_fat_kcal_pct_of_total: z.number(), vegetable_pct_of_target: z.number(), whole_foods_and_low_processed_foods: z.number(), whole_grain_pct: z.number()}); 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 patient's summary metrics for the star plot graph * * GET /patients/{patient_id}/patient_star_plot_summary */ export const getApiPatientsPatientIdPatientStarPlotSummary = async (args: GetApiPatientsPatientIdPatientStarPlotSummaryArgs, options: GetApiPatientsPatientIdPatientStarPlotSummaryOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.date_since != null) query.append("date_since", String(args.date_since)) if (args.date_until != null) query.append("date_until", String(args.date_until)) if (args.disaggregated != null) query.append("disaggregated", String(args.disaggregated)) if (args.daily_avg_method != null) query.append("daily_avg_method", String(args.daily_avg_method)) if (args.include_statements != null) query.append("include_statements", String(args.include_statements)) if (args.n_frequency_items != null) query.append("n_frequency_items", String(args.n_frequency_items)) if (args.include_non_ranked_items != null) query.append("include_non_ranked_items", String(args.include_non_ranked_items)) if (args.include_custom_items != null) query.append("include_custom_items", String(args.include_custom_items)) if (args.enforce_unique_base_food != null) query.append("enforce_unique_base_food", String(args.enforce_unique_base_food)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/patients/${encodeURIComponent(String(args.patient_id))}/patient_star_plot_summary${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(patientStarPlotResponse, await res.json()) };