# Blackbalsam

## Exporting REDCap Data into R

1\. Get a REDCap account for a project URL and API key

{% hint style="info" %}
if you don’t have an account contact Adam Lee to get one

if you have an existing account use the credentials associated with it
{% endhint %}

2\. Go to <https://reccap.cloudapps.unc.edu/accounts/login>

3\. Click “New Application” and choose **Blackbalsam Clinical**

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fhelx-documentation%2F-MEU1gVsQnOSnT8-hqRj%2F-MEU5UzOJGdl1t-R591S%2F0.png?generation=1597175890513899\&alt=media)

4\. Click on “black balsam” folder and then click on RedCapAPIRDemo.ipynb

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fhelx-documentation%2F-MEU1gVsQnOSnT8-hqRj%2F-MEU5UzP2mvO3nX5ZZ_p%2F1.png?generation=1597175890527074\&alt=media)

5\. In the notebook, on cell 2 substitute REDCap URL and API key with your credentials

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fhelx-documentation%2F-MEU1gVsQnOSnT8-hqRj%2F-MEU5UzQ3E3VlRNja9Dj%2F2.png?generation=1597175890462772\&alt=media)

6\. Run first three cells in the notebook

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fhelx-documentation%2F-MEU1gVsQnOSnT8-hqRj%2F-MEU5UzRY7jmComtR_Xv%2F3.png?generation=1597175890463502\&alt=media)

7\. To export records, use show\_forms, show\_fields, or show\_all\_records cells

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fhelx-documentation%2F-MEU1gVsQnOSnT8-hqRj%2F-MEU5UzSovE2GKE8T0vY%2F4.png?generation=1597175890463057\&alt=media)

## Using the restartr notebook to get data into mongodb

1. Go to <https://reccap.cloudapps.unc.edu/accounts/login> and login.&#x20;
2. Click on “New Application”, choose **Blackbalsam Clinical** then click "Create Application"**.**\
   &#x20;&#x20;

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4PzirRaG11KS9ja1o1%2F-MEZBU6aOTmSHRMz2S9B%2F-MEZL6AFZEz_sErGfH8i%2FScreen%20Shot%202020-08-12%20at%204.21.38%20PM.png?alt=media\&token=c8af5e4e-bfb0-4896-a07c-a926e0157a6d)

3\. Click on the "blackbalsam" directory and then launch the RestartrApiDemo.ipynb notebook. \
&#x20;&#x20;

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4PzirRaG11KS9ja1o1%2F-MEZBU6aOTmSHRMz2S9B%2F-MEZOV5oZvdqJ5trx7hO%2FScreen%20Shot%202020-08-12%20at%204.38.53%20PM.png?alt=media\&token=f906cd9f-4856-4f52-b956-18457386460e)

4\. In cells 3 to 6 substitute your api-key here "\<put-api-key>".\
&#x20;&#x20;

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4PzirRaG11KS9ja1o1%2F-MEcJqJZrwhEGb087QWc%2F-MEcN_jGl1_DGWrbbqIE%2FScreen%20Shot%202020-08-13%20at%2011.13.07%20AM.png?alt=media\&token=14656781-a1ea-49fe-ba97-1da1875cc18c)

5\. Run the first two cells in the notebook. \
&#x20;&#x20;

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4PzirRaG11KS9ja1o1%2F-MEcJqJZrwhEGb087QWc%2F-MEcP45NwZnlX_qWQv6b%2FScreen%20Shot%202020-08-13%20at%2011.20.02%20AM.png?alt=media\&token=a34b025e-50be-4dce-8931-1b99ae12ec66)

* The first cell imports the required dependencies.&#x20;
* The second cell is where data can be formatted to insert into mongodb. &#x20;

6\. Run the third cell to persist data into mongodb. \
&#x20;&#x20;

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4PzirRaG11KS9ja1o1%2F-MEcJqJZrwhEGb087QWc%2F-MEcRa9E1wRzTmlDCY7z%2FScreen%20Shot%202020-08-13%20at%2011.31.00%20AM.png?alt=media\&token=d7a7769c-6bbe-44ae-b4ac-8fbc7690d371)

* This cell will call the observation api and insert data into mongodb.
* Upon a successful call it will return an id, for example {"id": "\\"5f355dd39e55e62921768dec\\""}.&#x20;

7\. To query the data use, query by "\_id", query by sub-field, or just use query methods provided in the RestartrApiDemo.ipynb notebook.

&#x20;

![](https://1990944641-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4PzirRaG11KS9ja1o1%2F-MEcJqJZrwhEGb087QWc%2F-MEcXeRX5SpXWMgZ5JGs%2FScreen%20Shot%202020-08-13%20at%2011.55.57%20AM.png?alt=media\&token=f7ed862c-f94a-4381-aa14-0ac560b6f4d8)
