import {z} from 'zod' export type PostPatients = {provider: {provider_id: number}, patient: {first_name: string, last_name: string, email: string, bio: {date_of_birth: string, phone_number: string, home_phone_number?: string | undefined, cell_phone_number?: string | undefined, work_phone_number?: string | undefined, custom_contact_number?: string | undefined, gender?: ('Male' | 'Female' | 'Other') | undefined, weight?: number | undefined, height?: number | undefined, street_address?: string | undefined, address_line_1?: string | undefined, address_line_2?: string | undefined, city?: string | undefined, state?: string | undefined, zip_code?: string | undefined, insurance_name?: string | undefined, ssn?: string | undefined, race?: string | undefined}}, return_existing_if_match?: boolean | undefined}; export type CreateApiPatientsArgs = {'Nex-Api-Version': string, subdomain: string, location_id: number, body: PostPatients}; export type CreateApiPatientsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const aPIV2EntitiesPatientBasic = 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(), preferred_locale: z.string().nullable().optional(), location_ids: z.array(z.number().int()).optional()}); export const aPIV2EntitiesPatientsResponsesCreate = z.object({user: aPIV2EntitiesPatientBasic.optional()}); export const aPIV2EntitiesPatientsResponsesCreateResponse = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: aPIV2EntitiesPatientsResponsesCreate.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 }; /** * Create patient * * POST /patients */ export const createApiPatients = async (args: CreateApiPatientsArgs, options?: CreateApiPatientsOptions) => { 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/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 (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/patients${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(aPIV2EntitiesPatientsResponsesCreateResponse, await res.json()) };