import {z} from 'zod' export type AddressAnswer = {address: string, addressLineTwo?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zipCode?: (string | null) | undefined, country?: (string | null) | undefined}; export type SubmittedDemographicsBlock = {id: string, blockType?: 'DEMOGRAPHICS' | undefined, email: string, dateOfBirth: string, gender: string, address: AddressAnswer}; export type RainforestCard = {brand: string, last4: string, expMonth: number, expYear: number}; export type RainforestACH = {accountHolderType: string, accountNumberLast4: string, bankName: string, routingNumber: string}; export type ApplePay = {type: string, brand: string, brandDesc: string, description: string}; export type BillingContact = {name: string | null, addressLine1: string | null, addressLine2: string | null, city: string | null, state: string | null, postalCode: string | null, country: string | null, email: string | null, phone: string | null}; export type RainforestPaymentMethod = {paymentMethodId: string, paymentMethodConfigId: string, fingerprint: string | null, methodType: string, card: RainforestCard | null, ach: RainforestACH | null, applePay: ApplePay | null, billingContact: BillingContact | null, metadata: Record, createdAt: string, updatedAt: string}; export type SubmittedPaymentMethodBlock = {id: string, blockType?: 'PAYMENT_METHODS' | undefined, rainforestPaymentMethod?: (RainforestPaymentMethod | null) | undefined}; export type SubmittedMedicalHistoryBlock = {id: string, blockType?: 'MEDICAL_HISTORY' | undefined, allergies?: (Array | null) | undefined, medications?: (Array | null) | undefined, familyHistory?: (Array | null) | undefined, medicalHistory?: (Array | null) | undefined, prescriptions?: (Array | null) | undefined, surgicalHistory?: (Array | null) | undefined, socialHistory?: (Array | null) | undefined}; export type FormInsuranceCoverage = {insuranceCoverageId?: (string | null) | undefined, pverifyCode?: (string | null) | undefined, memberId?: (string | null) | undefined, insurerName?: (string | null) | undefined, policyHolderName?: (string | null) | undefined, policyHolderDob?: (string | null) | undefined, groupId?: (string | null) | undefined, phoneNumber?: (string | null) | undefined}; export type SubmittedInsuranceBlock = {id: string, blockType?: 'INSURANCE' | undefined, primary?: (FormInsuranceCoverage | null) | undefined, secondary?: (FormInsuranceCoverage | null) | undefined}; export type SubmittedDynamicBlock = {id: string, blockType?: 'DYNAMIC' | undefined} | {[key: string]: unknown}; export type FormSubmissionData = {blocks?: (Array) | undefined, patientId: string, hadUploadError?: (boolean | null) | undefined, isCompleteSubmission?: boolean | undefined}; export type UpdateApiFormsFormIdSubmitArgs = {TENANT: string, 'API-KEY': string, form_id: string, body: FormSubmissionData}; export type UpdateApiFormsFormIdSubmitOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const updateApiFormsFormIdSubmitResponse = z.boolean(); 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 }; /** * Patient Form Submission * * PUT /forms/{form_id}/submit */ export const updateApiFormsFormIdSubmit = async (args: UpdateApiFormsFormIdSubmitArgs, options: UpdateApiFormsFormIdSubmitOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/forms/${encodeURIComponent(String(args.form_id))}/submit${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(updateApiFormsFormIdSubmitResponse, await res.json()) };