EPIC Reschedule Appointment Flow Template

The Reschedule Appointment flow automates the re-scheduling of a patient's appointment within the Epic EHR system via the Webex AI Agent.

Overview

This flow receives rescheming and last appointment details, triggers the booking service to book a new appointment, parses the confirmation data, and evaluates the outcome to ensure the appointment and then cancels the last appointment.

Pre-requisite

  • Webex AI Agent Studio
  • EPIC Prebuilt Integration

User Roles

  • Flow Developer: Configures the Webex Connect flow, Epic authentication, request/response mappings, and JavaScript logic for data parsing and evaluation.
  • End User: The patient interacting with the AI Agent to confirm their desired appointment slot.
  • AI Agent: Captures the final scheduling intent and triggers the booking fulfillment flow.
  • Epic EHR System: Processes the booking request and returns a confirmation status.

Create Flow

To begin building the flow from template, follow these steps:

  1. Select or Create a Service: Navigate to the Services dashboard. You may either select an existing service from your list or create a new one to serve as the foundation for your flow.
  2. Initiate Flow Creation: Once your service is selected, click the Create Flow.
  3. Choose the Template: Within the "Create Flow" window, provide a friendly flow name (Note – the same flow name will have to be selected under AI Agent Studio Action to complete the configuration) and choose the template.
  4. The AI Agent Start node configuration is shown in the next screen. You can observe the input received from the AI Agent and click Save.
  5. Next, click on make live and publish the flow.

Go to AI Agent Studio, configure this flow under appropriate AI Agent studio Action.

Node Breakdown


Node TypePurposeOutcome
AI Agent EventThis node receives the inbound request from the AI Agent in JSON format and initializes the flow with the selected appointment parameters (e.g., patient ID, appointment ID, date, time, provider, department, and visit type).
• Accept input payload from the AI Agent
• Generates request variables as output variables for downstream processing

Input Received from AI Agent as trigger:

• patientId": "",
• appointmentId": "",
• appointmentDate": "",
• "appointmentTime": "",
• "providerId": "",
• "departmentId": "",
• "visitTypeId": "",
• "reschedule": " }``
EPIC Patient OAuthThis node performs Epic authentication using OAuth 2.0 before any scheduling API request is made.

• Retrieve access token
Method Name: Specifies the action to be executed, choose Authenticate.
AzureURL: Determines the target environment endpoint. Setting this to "Staging" ensures the flow connects to your staging or production environment.
SubscriptionKey: Maps the necessary API subscription key for your chosen environment, ensuring that the request is properly authorized by the API Management layer.
EpicTokenURL: Defines the specific endpoint used to exchange credentials for an access token. It utilizes the $(epicBaseURL) variable to allow for dynamic environment switching. The variable value can be configured in the flow settings under custom variables.
EpicClientId: Represents the unique identifier for your application, as registered in the Epic App. The variable value can be configured in the flow settings under custom variables.
• On success, the flow proceeds to Schedule Appointment
• On failure, the flow terminates.
Schedule AppointmentThis node invokes the Epic scheduling service to schedule the appointment.
• Submit the appointment booking request to Epic
• Receive the appointment details
• On success, the flow proceeds to Data Parser
• On error, the flow proceeds to Evaluate for retry handling
Data ParserThis node processes the raw response received from the Epic booking service.
Extract relevant confirmation details (such as the appointment confirmation number or status) from the JSON response.
Find Appointment IDThis node verifies the validity of the newly created appointment ID within the system to ensure the booking was correctly registered.

Check for epicAppointmentIdType variable from Schedule appointment node. It should be of type epicNewApptID0, ….., epicNewApptID4.
Reschedule Branch NodeThis node acts as the branching step, it updates the variables in transition actions for new appointment.

Set appointment booked and schedule type variables.
Cancel AppointmentThis node calls the EPIC system to cancel the user’s previous/old appointment.

Cancel the last appointment. The cancellation Comment field is left empty. If you want to customize the template use a variable that contains cancellation comments. Reason for cancellation is configured as Reschedule.
• On success, the flow proceeds shares the JSON (Key Value pairs) configured in Flow Outcome to AI Agent.
• On failure, the flow retries to cancel appointment.
Retry Logic ScriptThe JavaScript in the Evaluate node implements the standard retry pattern used across Epic fulfillment flows.
apiStatusCode , retryCount and maxRetryCount variable values can be updated in the flow settings under custom variables.

• Convert retryCount and maxRetryCount to numbers
• Compare current retries against the maximum allowed retries
• If retries remain, increment retryCount and return retry
• If retries are exhausted, return fail
• Temporary failures are retried automatically
• Repeated failures terminate the flow after the retry threshold is reached

Payload Description

Input Payload

  • patientId: Unique identifier for the patient.
  • appointmentId: Identifier for the last appointment slot.
  • appointmentDate: The date of the requested appointment.
  • appointmentTime: The time of the requested appointment.
  • providerId: Identifier for the assigned healthcare provider.
  • departmentId: Identifier for the department where the appointment will be scheduled.
  • visitTypeId: Code representing the type of visit (e.g., check-up, consultation).
  • reschedule: Boolean or flag indicating if this is a rescheduling request.

Output Payload

The following variables from the flow is shared with AI Agent

{ "transactionID": "$(transid)", "flowname": "$(flowname)", "serviceName": "$(serviceName)", "statuscode": 1000, "patientInstructions": "$(n4.appointmentPatientInstructions)", "newAppointmentId": "$(epicNewApptID)", "appointmentBooked": "$(appointmentBooked)", "scheduleOutcome": "$(scheduleType)" }

Error Handling

  • API Timeout / Transient Failure: If the booking request fails due to a temporary issue, the flow routes to an error path to notify the AI Agent.
  • Invalid Data: If the appointment parameters provided are invalid or if Epic rejects the booking due to scheduling conflicts, the flow returns a failure status.

Script Analysis

Data Parser Script

The JavaScript in the Data Parser node processes the raw response from Epic.

  • Processing: Converts the response string to JSON, extracts the confirmation object, and maps specific fields (like appointmentID) to the flow variables.

Evaluate Script

The JavaScript in the Evaluate node checks the final status of the booking.

  • Processing: It verifies if the success flag is true and if an appointmentID was returned. If the criteria are met, it returns an "OK" status; otherwise, it marks the flow as failed.