Get Future Appointments Flow Template

The Get Future Appointments flow enables the AI Agent to retrieve a list of upcoming appointments for a patient from the Epic EHR.

Overview

This flow acts as a prerequisite for downstream workflows such as appointment confirmation, cancellation, or rescheduling.

Pre-requisites

  • Webex AI Agent Studio
  • EPIC Prebuilt Integration

User Roles

  • Flow Developer: Configures the Webex Connect flow, Epic authentication, and JavaScript logic for result trimming.
  • End User: The patient requesting information about their upcoming schedule.
  • AI Agent: Triggers the flow when a patient asks, "What are my upcoming appointments?"
  • Epic EHR System: Processes the request and returns the list of future appointment records.

Node Breakdown

Node TypePurposeOutcome
Configure AI Agent Event Receives the inbound request from the AI Agent and initializes the flow.

Input Variable: patientId
AuthenticateEstablishes a secure connection with the Epic EHR.Authentication token required for subsequent API calls.
Get Future AppointmentsExecutes a subscription-based API call to Epic to fetch future records.Raw JSON list of appointments.

Behavior: On success, proceeds to Trim Result Set; on error/timeout, triggers the Evaluate nodes for retry handling.
Trim Result SetUses JavaScript to filter and format the raw JSON response.A clean, simplified appointment list (Date, Time, Provider) ready for the AI Agent to present to the user.
Evaluate (Error Handler)Manages scenarios where no future appointments exist or where transient API timeouts occur.

Logic: Implements retry loops for temporary failures and handles empty result sets gracefully.

Input & Output Variables

Input Variables (Configure AI Agent Event)

patientId: The unique identifier for the patient whose appointments are being retrieved.

Output Variables

The flow processes the raw data into a structured format (e.g., appointmentList) that contains the date, time, and provider details for each upcoming visit.

Error Handling

  • API Timeout: If the request to Epic fails due to a network or service issue, the flow routes to the Evaluate node to attempt a retry.
  • No Appointments Found: If the API returns a successful response but the list is empty, the flow exits through the failure path to inform the AI Agent that no upcoming appointments were found.

Script Analysis

Trim Result Set Script

  • Processing: The JavaScript logic iterates through the raw JSON response from Epic. It extracts specific fields—Date, Time, and Provider—and maps them into a simplified array structure.
  • Result: A clean, human-readable list that the AI Agent can easily relay to the patient.

Evaluate Script

  • Processing: Checks the status of the API call. If a retry is required, it increments the retry counter and loops back to the "Get Future Appointments" node. If the maximum number of retries is reached, it terminates the flow.