import {z} from 'zod' export type UpdateApiPeoplePersonIdArgs = {person_id: string, body: {person?: ({first_name?: string | undefined, last_name?: string | undefined, born_at?: string | undefined, gender?: string | undefined, phone_country_id?: unknown | undefined, telephone2?: string | undefined, email?: string | undefined, account_id?: string | undefined, person_attributes?: ({send_reminders?: boolean | undefined, insurance_name?: string | undefined, insurance_file?: string | undefined, insurance_number?: string | undefined, insurance_plan?: string | undefined, insurance_type?: string | undefined, insurance_taxed?: boolean | undefined, insurance_claim_insured_name?: string | undefined, insurance_claim_birthplace?: string | undefined, insurance_claim_folio?: string | undefined, insurance_claim_number?: string | undefined, insurance_claim_movement?: string | undefined, insurance_claim_adjuster?: string | undefined, insurance_claim_risk?: string | undefined, insurance_claim_sinister_date?: string | undefined, insurance_claim_issue_date?: string | undefined, insurance_claim_initial_date?: string | undefined, insurance_claim_admission_date?: string | undefined, insurance_claim_departure_date?: string | undefined, insurance_claim_institution_name?: string | undefined, insurance_claim_institution_address?: string | undefined}) | undefined}) | undefined}}; export type UpdateApiPeoplePersonIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiPeoplePersonIdResponse = z.object({person: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), links: z.object({consultations: z.string().optional(), consultation_lab_test_results: z.string().optional(), consultation_schedules: z.string().optional(), vital_signs_sets: z.string().optional(), medical_history: z.string().optional(), deffers: z.string().optional(), medical_notes: z.string().optional(), insurance_coverage: z.string().optional()}).optional(), full_name: z.string().optional(), telephone: z.unknown(), email: z.unknown(), born_at: z.string().optional(), gender: z.string().optional(), avatar_url_small: z.string().optional(), avatar_url_medium: z.string().optional(), telephone2: z.string().optional(), address_state_id: z.number().int().optional(), address_city: z.unknown(), address_street: z.unknown(), address_zipcode: z.unknown(), identity_number: z.unknown(), account_id: z.number().int().optional(), avatar_url_large: z.string().optional(), notes: z.unknown(), person_attributes: z.object({}).optional(), phone_country_id: z.number().int().optional(), is_migrated: z.boolean().optional(), without_cellphone: z.boolean().optional(), nimbochat_invitation_sent: z.boolean().optional(), medical_record: z.unknown(), cirrus_patient_id: z.unknown()}).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 }; /** * PUT /people/{person_id} * * PUT /people/{person_id} */ export const updateApiPeoplePersonId = async (args: UpdateApiPeoplePersonIdArgs, options?: UpdateApiPeoplePersonIdOptions) => { const {baseUrl = "https://api.example.test", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/people/${encodeURIComponent(String(args.person_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiPeoplePersonIdResponse, await res.json()) };