> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> Connect to your Epic app for OAuth.

To setup your Epic app in Refold for OAuth, you will need the following credentials from your [Epic Developer account](https://fhir.epic.com/):

* Client ID
* Client Secret
* Scopes

### Pre-requisites

1. Epic Developer account. You can create one [here](https://fhir.epic.com/Developer/Index).

<Info>If you haven't already created an app in Epic, you'd need to create one.</Info>

### Creating an app in Epic

To create a Epic app and acquire the above mentioned credentials, please follow the steps mentioned below:

1. Log in to your [Epic Developer account](https://fhir.epic.com/).
2. Select the `Build Apps` tab in the top nav bar and click on `Create` button.

<img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Epic/epic_navigation.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=576535479e05bac3d252facf36dfc51c" alt="Navigation for App setup" data-path="images/Epic/epic_navigation.png" />

3. Enter the unique **Application Name** and select `Clinicians or Administrative Users` as **Application Audience**.
4. Go to your [`Apps catalog`](https://app.gocobalt.io/apps) in **Refold** > Search for `Epic` > `Settings` > `Use your credentials` > `Callback Url` > Copy it. Paste the Callback URL under `Redirect URI` in the app.
5. Checkmark the `Is Confidential Client` and `Requires Persistent Access` boxes.
6. Select the required scopes in the **Available** section.

<img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Epic/Epic_config.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=33cd7d96056b97569f047b79d8e10cd2" alt="Setting up Developer app" data-path="images/Epic/Epic_config.png" />

7. Copy the **Non-Production Client ID**. Click on `Generate Secret`, copy the  **Client Secret** generated and click on `Store Hash` button.

<Info>
  Save the Client Secret displayed as it will be shown only once.
</Info>

<img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Epic/Epic_credentials.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=95c0d6eeeb5200e3f3d02fc9111b9054" alt="Getting Credentials" data-path="images/Epic/Epic_credentials.png" />

#### Configuring credentials in Refold

App settings page lets you configure the authentication settings for an `OAuth 2.0` based application. For your customers to provide you authorization to access their data,
they would first need to install your application. This page lets you set up your application credentials.

<img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Epic/Epic_cobalt.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=188496517cee0a6e7e3329f3dfff4bf7" alt="Setting up application client credentials" data-path="images/Epic/Epic_cobalt.png" />

Provide the acquired Client ID and Client Secret under Settings of the app and save it.

#### Configuring Scopes

Refold lets you configure what permissions to ask from your users while they install your application. The scopes can be added or removed from the App settings page, under `Permissions & Scopes`
section.

For some applications Refold sets **mandatory scopes** which cannot be removed. Additional scopes can be selected from the drop down. Refold also has the provision to add any
custom scopes supported by the respective platform.

<img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Epic/Epic_scopes.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=ad3ea0ec59ba627967934db9722e4e38" alt="OAuth Scopes" data-path="images/Epic/Epic_scopes.png" />

<Tip>
  All the scopes listed are R4 version Scopes in Refold.
</Tip>

Once the scopes has been added to the application in Refold, go to your [Epic Developer Account](https://fhir.epic.com/) and update the scopes as added on Refold.

<Warning>
  Epic usually takes around 30 mins for any changes in the OAuth app to work.
</Warning>

Select the OAuth App created for Refold > Add the scopes under `Available` as added in Refold > Click on `Save and Ready for Sandbox`.

<Note>
  If you are facing scopes missing or invalid scope error. Make sure you are not passing any custom scope not supported by the platform.
</Note>

#### Actions and triggers

Once the above setup is completed, you can create orchestrations of your use-cases using Epic actions and triggers. Following are the set of Epic actions and triggers
supported by Refold.

<Tabs>
  <Tab title="Actions">
    <AccordionGroup>
      <Accordion title="Appointments">
        1. **List Appointments** - List all appointments in Epic.
        2. **Get Appointment By Id** - Get an appointment by Id in Epic.
      </Accordion>

      <Accordion title="Patient">
        3. **List Patients** - List all pageatients in Epic.
        4. **Create Patient** - Create new patient in Epic.
        5. **Search Patients** - Search a patient in Epic.
      </Accordion>

      <Accordion title="Task">
        6. **Update Task** - Update a task in Epic.
        7. **Get Task By Id** - Get a task by Id in Epic.
        8. **Search Tasks** - Search a task in Epic.
      </Accordion>

      <Accordion title="Others">
        9. **HTTP Request** - Make HTTP API calls to any Epic documented REST APIs.
      </Accordion>
    </AccordionGroup>
  </Tab>

  <Tab title="Triggers">
    There are no triggers in this application.
  </Tab>
</Tabs>
