# Integrating with Epic

This article details the process of integrating your application with Epic using Vidyo SDK. This integration enables launching video calls directly from the Epic workflow. A critical component is the proper handling of Epic's context data (`extData`) to ensure seamless data flow.&#x20;

## Prerequisites

* Connector SDK integrated into your application.
* Access to an Epic environment configured on your VidyoPortal

## Integration Steps

### Obtain Epic data from VidyoPortal

At this step you acquire the room key and display name by making an https request to the VidyoPortal, passing it the Epic encrypted data.

{% tabs %}
{% tab title="Objective-C" %}
```objectivec
NSString *url = [NSString stringWithFormat:@"%@/join/?extDataType=1&extData=%@", [portal text], [encryptedData text]];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                             cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                             timeoutInterval:10];
[urlRequest setHTTPMethod: @"GET"];
...
```
{% endtab %}

{% tab title="Java" %}
```java
String requestUrl = String.format("%1$s/join/?extDataType=1&extData=%2$s", portal, epicData);
URL url = new URL(strings[0]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("User-Agent", "...");
```
{% endtab %}
{% endtabs %}

* `portal`: The base URL of the video conferencing service.
* `extDataType=1`: A parameter indicating the type of external data (should be `1`).
* `extData`: The encrypted data received from Epic (crucially included in the request).

Now you parse the response to construct the protocol handler URL, get actual room key and your display name for connecting.

{% tabs %}
{% tab title="Objective-C" %}
```objectivec
NSRange r1 = [urlResponseStr rangeOfString:@"vidyo://join?"];
NSString *substr = [urlResponseStr substringFromIndex:r1.location];
NSRange r2 = [substr rangeOfString:@"\";"];
NSString *protocolHandlerURL = [substr substringToIndex:r2.location];

NSURLComponents *urlComponents = [NSURLComponents componentsWithString:protocolHandlerURL];
NSArray *queryItems = urlComponents.queryItems;
NSString *portal = [self valueForKey:@"portal" fromQueryItems:queryItems];
NSString *roomKey = [self valueForKey:@"roomKey" fromQueryItems:queryItems];
NSString *displayName = [self valueForKey:@"dispName" fromQueryItems:queryItems];
NSString *extData = [self valueForKey:@"extData" fromQueryItems:queryItems]; // Extract extData
```
{% endtab %}

{% tab title="Java" %}
```java
int index_of_protocol_handler = response.indexOf(vidyoSubString);
if (index_of_protocol_handler != -1) {
  int index_of_end_protocol_handler = response.indexOf("\"", index_of_protocol_handler);
  protocolHandler = response.substring(index_of_protocol_handler, index_of_end_protocol_handler);
}

Map<String, String> params = splitQuery(protocolHandler);
String portal = params.get("portal");
String roomKey = params.get("roomKey");
String displayName = params.get("dispName");
String extData = params.get("extData"); // Extract extData
```
{% endtab %}
{% endtabs %}

Parameters being extracted:

* `portal`: The VidyoPortal service URL.
* `roomKey`: The unique identifier for the video call.
* `displayName`: The name of the user joining the call.
* **`extData`:** Epic's context data.

### Set Epic context into Connector SDK

Before connecting to the call, use the `setAdvancedOptions()` API of the Video Conferencing SDK to provide the `extData`. This step is essential for the Epic integration, as it passes context about the patient into the call.

{% tabs %}
{% tab title="Objective-C" %}
```objectivec
NSString *advancedOptions = [NSString stringWithFormat:@"{ \"extDataType\": \"1\", \"extData\": \"%@\" }", [encryptedData text]]; // Use original Epic encryptedData
[vc setAdvancedOptions:[advancedOptions UTF8String]];
```
{% endtab %}

{% tab title="Java" %}
```java
String advancedOptions = String.format("{ \"extDataType\": \"1\", \"extData\": \"%1$s\" }", extData); // Use extracted extData
mVidyoConnector.setAdvancedOptions(advancedOptions);
```
{% endtab %}
{% endtabs %}

### Connect to the Call

Finally, use the `connectToRoomAsGuest()` API of the Connector SDK to establish the video call connection using the extracted parameters.

{% tabs %}
{% tab title="Objective-C" %}
```objectivec
[vc connectToRoomAsGuest:[[portal text] UTF8String]
                        DisplayName:[[displayName text] UTF8String]
                            RoomKey:[[roomKey text] UTF8String]
                            RoomPin:@""
                  ConnectorIConnect:self];
```
{% endtab %}

{% tab title="Java" %}
```java
mVidyoConnector.connectToRoomAsGuest(
          portal,
          displayName.trim(),
          roomKey,
          roomPin,
          this);
```
{% endtab %}
{% endtabs %}
