import {z} from 'zod' export type GetApiApiV1PatientPatientTokenPatientSurveyArgs = {patient_token: string}; export type GetApiApiV1PatientPatientTokenPatientSurveyOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const model105 = z.object({weight_value: z.number().optional(), weight_unit: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), asthma_breathing: z.boolean().optional(), heart_disease: z.boolean().optional(), arthritis: z.boolean().optional(), lung_disorder: z.boolean().optional(), bleeding_clotting_disorder: z.boolean().optional(), neurological_chronic_headaches: z.boolean().optional(), blood_transfusion: z.boolean().optional(), psychiatric_disorder: z.boolean().optional(), bowel_stomach: z.boolean().optional(), pulmonary_embolism: z.boolean().optional(), cancer: z.boolean().optional(), stroke: z.boolean().optional(), cholesterol_disorder: z.boolean().optional(), seizure_epilepsy: z.boolean().optional(), diabetes: z.boolean().optional(), thyroid_disorder: z.boolean().optional(), eye_disorder: z.boolean().optional(), urinary_kidney_disorder: z.boolean().optional(), conditions: z.string().optional(), smoking_frequency: z.string().optional(), drinking_frequency: z.string().optional(), other_medications: z.string().optional(), known_allergies: z.boolean().optional(), url_token: z.string().optional(), pregnancy: z.boolean().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 }; /** * Get Patient Survey * * GET /api/v1/patient/{patient_token}/patient_survey */ export const getApiApiV1PatientPatientTokenPatientSurvey = async (args: GetApiApiV1PatientPatientTokenPatientSurveyArgs, options?: GetApiApiV1PatientPatientTokenPatientSurveyOptions) => { const {baseUrl = "https://api.truepill.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/patient/${encodeURIComponent(String(args.patient_token))}/patient_survey${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(model105, await res.json()) };