import {z} from 'zod' export type GetApiPersonsArgs = {patientsOnly: string, $top: string, $filter: string, $orderby: string, $skip: string, $inlinecount: string, $count: string, Accept: string}; export type GetApiPersonsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({href: z.string(), method: z.string(), rel: z.string(), description: z.string(), vendorExtensions: z.string()}); export const item34 = z.object({_links: z.array(link), checkInDateTime: z.string(), checkInTimezone: z.string(), checkOutDateTime: z.string(), checkOutTimezone: z.string(), encounterNumber: z.string(), enterpriseId: z.string(), id: z.string(), isLocked: z.string(), isSensitive: z.string(), locationId: z.string(), locationName: z.string(), personId: z.string(), practiceId: z.string(), printOnStatements: z.string(), referringProviderId: z.string(), referringProviderName: z.string(), renderingProviderId: z.string(), renderingProviderName: z.string(), status: z.string(), suppressOutreach: z.string(), suppressPortal: z.string(), timestamp: z.string(), timestampTimezone: z.string()}); export const oK78 = z.object({Count: z.string(), Items: z.array(item34), NextPageLink: z.string()}); 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 }; /** * {{baseUrl}}/persons * * GET /persons */ export const getApiPersons = async (args: GetApiPersonsArgs, options?: GetApiPersonsOptions) => { const {baseUrl = "https://nativeapi.nextgen.com/nge/prod/nge-api/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.patientsOnly != null) query.append("patientsOnly", String(args.patientsOnly)) if (args.$top != null) query.append("$top", String(args.$top)) if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$orderby != null) query.append("$orderby", String(args.$orderby)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$inlinecount != null) query.append("$inlinecount", String(args.$inlinecount)) if (args.$count != null) query.append("$count", String(args.$count)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) const url = `${baseUrl.replace(/\/+$/, '')}/persons${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(oK78, await res.json()) };