Skip to content

Commit

Permalink
adds basic export task and needed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gedankenstuecke committed Jun 5, 2020
1 parent 2bdd049 commit c8d5368
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
10 changes: 9 additions & 1 deletion env.sample
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
SECRET_KEY="SOME_KEY"
DEBUG="True"

# Setup for Open Humans backend
OPENHUMANS_APP_BASE_URL="http://127.0.0.1:5000/"
OPENHUMANS_CLIENT_ID="CLIENT_ID"
OPENHUMANS_CLIENT_SECRET="CLIENT_SECRET"

ON_HEROKU='True'

# Setup for Open Clinica
## Username for adding participants & scheduling data ('site investigator' role)

OPENCLINICA_USERNAME="Username"
OPENCLINICA_PASSWORD="Password"
OPENCLINICA_PASSWORD="Password"

## Username for exporting data ('data manager' role)
OPENCLINICA_DATA_USERNAME="AnotherUsername"
OPENCLINICA_DATA_PASSWORD="Password"


OPENCLINICA_STUDY="DEMO_NAME(TEST)"
Expand Down
8 changes: 6 additions & 2 deletions main/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
from django.shortcuts import reverse


def get_access_token():
def get_access_token(download=False):
url = 'https://opencovid.build.openclinica.io/user-service/api/oauth/token'
headers = {'Content-Type': "application/json"}
data = json.dumps(
{'username': settings.OPENCLINICA_USERNAME, 'password': settings.OPENCLINICA_PASSWORD}
{'username': settings.OPENCLINICA_SITE_USERNAME, 'password': settings.OPENCLINICA_SITE_PASSWORD}
)
if download:
data = json.dumps(
{'username': settings.OPENCLINICA_DATA_USERNAME, 'password': settings.OPENCLINICA_DATA_PASSWORD}
)
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
return response.text
Expand Down
21 changes: 21 additions & 0 deletions main/management/commands/get_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.core.management.base import BaseCommand
import requests
from main.helpers import get_access_token


class Command(BaseCommand):
help = "Exports data for all members"

def handle(self, *args, **options):
headers = {
"Authorization": "bearer {}".format(get_access_token(download=True)),
"Accept": "application/json"
}
url = "https://opencovid.openclinica.io/OpenClinica/pages/auth/api/clinicaldata/S_DEMO_BGT(TEST)/91048557/*/*?includeAudits=n&includeDNs=n&includeMetadata=y&showArchived=n"
# download all data:
# url = "https://opencovid.openclinica.io/OpenClinica/pages/auth/api/clinicaldata/S_DEMO_BGT(TEST)/*/*/*?includeAudits=n&includeDNs=n&includeMetadata=y&showArchived=n"
response = requests.get(url, headers=headers)
print(response.json())

# TODO: so far it doesn't process the data, next step:
# - Save data to Open Humans for each member
8 changes: 5 additions & 3 deletions main/management/commands/send_emails.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from django.core.management.base import BaseCommand
from main.models import SurveyAccount
import datetime
from main.helpers import create_openclinica_event, get_openclinica_token
from main.helpers import get_openclinica_token
from main.helpers import send_user_survey_link


class Command(BaseCommand):
help = "Updates all data for all members"

def handle(self, *args, **options):
for survey_account in SurveyAccount.objects.all():
#create_openclinica_event(survey_account, "SE_DAILY", str(datetime.date.today()))
# we no longer create events on sending out email, it's dynamically
# done when clicking the email link now
# create_openclinica_event(survey_account, "SE_DAILY", str(datetime.date.today()))
get_openclinica_token(survey_account)
send_user_survey_link(survey_account)
9 changes: 7 additions & 2 deletions open_survey/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

OPENCLINICA_USERNAME = os.getenv("OPENCLINICA_USERNAME", "OPENCLINICA_TOKEN")
# OC user for adding new participants & scheduling events
OPENCLINICA_SITE_USERNAME = os.getenv("OPENCLINICA_USERNAME", "OPENCLINICA_TOKEN")
OPENCLINICA_SITE_PASSWORD = os.getenv("OPENCLINICA_PASSWORD", "OPENCLINICA_TOKEN")

# OC user for exporting data from participants
OPENCLINICA_DATA_USERNAME = os.getenv("OPENCLINICA_DATA_USERNAME", "OPENCLINICA_TOKEN")
OPENCLINICA_DATA_PASSWORD = os.getenv("OPENCLINICA_DATA_PASSWORD", "OPENCLINICA_TOKEN")

OPENCLINICA_PASSWORD = os.getenv("OPENCLINICA_PASSWORD", "OPENCLINICA_TOKEN")

OPENCLINICA_STUDY = os.getenv("OPENCLINICA_STUDY", "OPENCLINICA_STUDY ")

Expand Down

0 comments on commit c8d5368

Please sign in to comment.