import {z} from 'zod' export type GetApiPatientsArgs = {'Nex-Api-Version': string, subdomain: string, location_id: number, sort?: string | undefined, name?: string | undefined, email?: string | undefined, phone_number?: string | undefined, date_of_birth?: string | undefined, inactive?: boolean | undefined, foreign_id?: string | undefined, updated_since?: string | undefined, new_patient?: boolean | undefined, non_patient?: boolean | undefined, forms_syncable?: boolean | undefined, location_strict?: boolean | undefined, start_cursor?: string | undefined, end_cursor?: string | undefined, per_page?: number | undefined}; export type GetApiPatientsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const aPIV2EntitiesPrivacyAuthorization = z.object({authorization: z.boolean().optional(), authorization_date: z.string().optional(), privacy: z.boolean().optional(), privacy_date: z.string().optional(), consent: z.boolean().optional(), consent_date: z.string().optional()}); export const aPIV20240412EntitiesPatientWithPrivacyAuthorization = z.object({id: z.number().int().optional(), email: z.string().nullable().optional(), first_name: z.string().optional(), middle_name: z.string().nullable().optional(), last_name: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), institution_id: z.number().int().optional(), foreign_id: z.string().nullable().optional(), foreign_id_type: z.string().optional(), bio: z.object({}).optional(), inactive: z.boolean().optional(), last_sync_time: z.string().nullable().optional(), guarantor_id: z.number().int().nullable().optional(), billing_type: z.string().nullable().optional(), chart_id: z.string().nullable().optional(), preferred_language: z.string().nullable().optional(), provider_id: z.number().int().nullable().optional(), hipaa: aPIV2EntitiesPrivacyAuthorization.optional()}); export const aPIV20240412EntitiesPatientWithPrivacyAuthorizationCollectionResponseWithCursor = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: z.array(aPIV20240412EntitiesPatientWithPrivacyAuthorization).optional(), page_info: z.object({}).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 }; /** * View patients * * GET /patients */ export const getApiPatients = async (args: GetApiPatientsArgs, options?: GetApiPatientsOptions) => { const {baseUrl = "https://nexhealth.info", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") 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 (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.name != null) query.append("name", String(args.name)) if (args.email != null) query.append("email", String(args.email)) if (args.phone_number != null) query.append("phone_number", String(args.phone_number)) if (args.date_of_birth != null) query.append("date_of_birth", String(args.date_of_birth)) if (args.inactive != null) query.append("inactive", String(args.inactive)) if (args.foreign_id != null) query.append("foreign_id", String(args.foreign_id)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (args.new_patient != null) query.append("new_patient", String(args.new_patient)) if (args.non_patient != null) query.append("non_patient", String(args.non_patient)) if (args.forms_syncable != null) query.append("forms_syncable", String(args.forms_syncable)) if (args.location_strict != null) query.append("location_strict", String(args.location_strict)) if (args.start_cursor != null) query.append("start_cursor", String(args.start_cursor)) if (args.end_cursor != null) query.append("end_cursor", String(args.end_cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/patients${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(aPIV20240412EntitiesPatientWithPrivacyAuthorizationCollectionResponseWithCursor, await res.json()) };