This application is meant to serve as an example for the FHIR authentication process. Through the information in this README and the code in the relevant files, you may observe the authentication process as well as how to request Epic resources.
Before you begin, you must install the following dependencies on your machine:
-
Hyperdrive Client Testing Harness (Windows Only)
- Since the testing harness is Windows only, you should install these dependencies on a Windows machine.
-
Node (>=18.18.1)
- app.tsx: Defines routes for web application
- launch.tsx: Page that is intended to be rendered first during an EHR launch. In Epic Hyperdrive, you should enter the URL of this page during setup. This file also contains the authentication logic.
- main.tsx: Page that is intended to be rendered after the authentication process, once Epic redirects. This file also contains the logic for obtaining the access token, passing the access token to the backend, and using the backend to request Epic resources.
- constants.ts: Defines constant variables used in this project. Replace
CLIENT_ID
andREDIRECT_URI
with your own information.
- EpicResource.java: Defines endpoints frontend queries to access Epic resources.
- SecurityConfiguration.java: Defines security configuration for the project.
- Sign up for Vendor Services.
- Once signed in, select "Manage Apps" -> "My Apps."
- Select "Create" or select an existing application.
- Name your app, and select who will be using it. Since this example is developed for EHR use, we have selected "Clinicians, Staff, or Administrative Users."
- Select the features you need. For this example, we only need to select "Incoming API" to gain access to Epic resources.
- Select all the APIs you plan on using. Note: there are 3 types of APIs (DSTU2, STU3, and R4). It does not matter which you select, but your app must make calls to the API corresponding to its FHIR version (see next steps)
- Toggle on "Use OAuth 2.0" and select an App FHIR version.
- Add the URLs of each page of your app in the "Endpoint URI" section. In the case of this example, I have added
http://localhost:8080/
andhttp://localhost:8080/launch/
- Click "Save."
Most likely, the buttons mentioned here will not appear on the top navigation bar. If that is the case, select "More" on the top navigation bar to find the appropriate buttons. You can even drag them around and reorder them so they stay on the top navigation bar.
After request access credentials from Epic and logging into Hyperdrive:
- Click on "Integration Setup" as circled in the screenshot above.
- Select "Smart on FHIR" as the Integration Type.
- Enter the launch URL into the field labeled "URL." This will be the first screen that appears when the application is started.
- Enter the Client ID into the field labled "Client ID." This can be found on your app's page on Vendor Services. Since we are working within the testing harness, this will be the non-production Client ID.
- Select whichever type of Launch Type you prefer. The most useful ones I have found are "External Browser" and "Embedded." By clicking "External Browser," your application opens in a web browser. This has allowed me to use Chrome's Developer Tools when debugging during development. By clicking "Embedded," you application launches directly within Hyperdrive, which is useful if you want to see how your application would look within the EHR.
- Click "Turn Test Integration ON," and proceed to Patient Chart
- Click on "Patient Chart" as circled in the screenshot above.
- Click on "Patient Chart" and double-click to select a patient when prompted.
- Click "Trigger Patient Context," and your application will start with the selected patient as the patient (this will affect the patient ID returned by the token endpoint).
-
Epic launches your application in Hyperdrive using the launch URL specified in Integration Setup and appends two query prameters:
iss
andlaunch
. -
Your application makes a
GET
request to a URL formed by concatenatingiss
with the string/metadata
. -
Your application parses the response to retrieve both the URLs for the authentication endpoint and the token endpoint.
-
Your application authenticates by redirecting to a URL formed by concatenating the following query paramters with the authentication URL received in the previous step:
scope
: set tolaunch
for EHR launchesresponse_type
: set tocode
redirect_uri
: the URI for the page Epic will redirect to after authenticating. Note: this page must also be registered on Vendor Services.client_id
: the Client ID retrieved from your application's page on Vendor Services (the non-production version while testing)launch
: the launch code retrieved from thelaunch
query parameter.aud
: set toiss
, retrieved from the query parameter.
-
Epic authenticates and redirects the application to the
redirect_uri
and appends a query parameter:code
. -
Your application retrieves an access token by sending a
POST
request to the token endpoint (from Step 3) and appends the following query parameters:grant_type
: set toauthorization_code
redirect_uri
: set to the same value asredirect_uri
mentioned in Step 4code
: the code retrieved from thecode
query parameterclient_id
: the Client ID retrieved from your application's page on Vendor Services (the non-production version while testing)
Note: The request must contain the header:
Content-Type': 'application/x-www-form-urlencoded
. -
Now you can access any of the APIs selected when you set up your application by sending an HTTP request to the correct endpoint and attaching the header
Authorization: Bearer [token]
, where[token]
is theaccess_token
returned from the token endpoint.
As mentioned previously, you request epic resources by sending an HTTP request to the correct endpoint and attaching the header Authorization: Bearer [token]
, where [token]
is the access_token
returned from the token endpoint. While we pass the token to the backend and make the requests there in this example, you may also make these requests from the frontend.
Epic's documentation should provide all the information necessary on how to use their APIs.
IMPORTANT: the base URL for all requests will be the value of the iss
query parameter obtained during the Authentication Flow.
- Make sure to replace
CLIENT_ID
andREDIRECT_URI
in constants.ts with your own information. - The web application is run within an iframe in Hyperdrive. This means that iframing must be enabled within your security configuration. This project has allowed iframing by disabling the
X-Frame-Options
andContent-Security-Policy: frame ancestors
headers. A good place to test if your application allows iframing is W3Schools' Iframe Tryit Page. - After updating your application information on Vendor Services, updates often take 20-30 minutes to sync.
- The following patients have genomic data available:
- Annie Beacon
- Henry Clin Doc
./mvnw