Skip to content

Commit a6b248c

Browse files
author
“Carmel
committed
Add ldot study configs
1 parent 5f13d1d commit a6b248c

3 files changed

Lines changed: 40 additions & 29 deletions

File tree

app.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask, render_template, request, jsonify
1+
from flask import Flask, json, render_template, request, jsonify
22
import requests
33

44
from new_ldot_workflows.b_2_get_qualtrics_links import add_individuals_to_survey
@@ -7,24 +7,7 @@
77

88
app = Flask(__name__)
99

10-
# Study configurations - modify these as needed
11-
STUDIES = {
12-
"LDOT-001": {"name": "PIAMA study", "variables": {"survey_id": "SV_efCMOg6wHU0T8ii",
13-
"directory_id": "POOL_10pyxk9leSUisrT",
14-
"distribution_id": "EMD_7AEa416lRwFhrkF",
15-
"mailing_list_id": "CG_2dMbO6WUBMnCeIK",
16-
"embedded_data_field": "study_id_child"}},
17-
"LDOT-002": {"name": "LDOT Study 002", "variables": {"survey_id": "value3",
18-
"directory_id": "POOL_10pyxk9leSUisrT",
19-
"distribution_id": "EMD_7AEa416lRwFhrkF",
20-
"mailing_list_id": "value4",
21-
"embedded_data_field": "study_id_child"}},
22-
"LDOT-003": {"name": "LDOT Study 003", "variables": {"survey_id": "value5",
23-
"directory_id": "POOL_10pyxk9leSUisrT",
24-
"distribution_id": "EMD_7AEa416lRwFhrkF",
25-
"mailing_list_id": "value6",
26-
"embedded_data_field": "study_id_child"}},
27-
}
10+
STUDIES = json.load(open("ldot_study_configs.json"))
2811

2912

3013
@app.route("/")

ldot_study_configs.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"LDOT-001": {"name": "PIAMA study", "variables": {"survey_id": "SV_efCMOg6wHU0T8ii",
3+
"directory_id": "POOL_10pyxk9leSUisrT",
4+
"distribution_id": "EMD_7AEa416lRwFhrkF",
5+
"mailing_list_id": "CG_2dMbO6WUBMnCeIK",
6+
"embedded_data_field": "study_id_child"}},
7+
"LDOT-002": {"name": "LDOT Study 002", "variables": {"survey_id": "value3",
8+
"directory_id": "POOL_10pyxk9leSUisrT",
9+
"distribution_id": "EMD_7AEa416lRwFhrkF",
10+
"mailing_list_id": "value4",
11+
"embedded_data_field": "study_id_child"}},
12+
"LDOT-003": {"name": "LDOT Study 003", "variables": {"survey_id": "value5",
13+
"directory_id": "POOL_10pyxk9leSUisrT",
14+
"distribution_id": "EMD_7AEa416lRwFhrkF",
15+
"mailing_list_id": "value6",
16+
"embedded_data_field": "study_id_child"}},
17+
}

new_ldot_workflows/b_1_get_new_subjects.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1+
12
# 1. First, query Ldot to find new people who need to be added to Qualtrics. This will be done by looking for people who have been added to Ldot in the last 24 hours and checking if they are already in Qualtrics.
23
# 2. For each new person, add them to the appropriate mailing list in Qualtrics. This will involve using the Qualtrics API to add the person's information to the mailing list.
34
# 3. After adding the person to the mailing list, send them an email invitation to
45

6+
# Grab the client ID and secret from the config file new_ldot_workflows\ldot_config.json
57

68

7-
# I think it would be nice to make this a little app on openshift
8-
# So let's make everything into sepaate functions and then connect them to buttons in the UI. We can use Flask for the backend and React for the frontend..
9-
# And yes save the reuslts in the meantime
109

10+
import json
1111
import requests
1212

13-
# I think I ned to get the list of people and their IDs where they are at the state of point where they're ready to be sent a survey invitation
13+
with open("new_ldot_workflows/ldot_config.json") as f:
14+
config = json.load(f)
15+
CLIENT_ID = config["client_id"]
16+
CLIENT_SECRET = config["client_secret"]
17+
LDOT_API_URL = config["LDOT_API_URL"]
1418

1519

16-
LDOT_API_URL = "https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/"
17-
STUDY_GUID = "5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b"
20+
response = requests.post(
21+
"https://accware.memic.maastrichtuniversity.nl/ldot_identity_server/connect/token",
22+
data={
23+
"grant_type": "client_credentials",
24+
"client_id": CLIENT_ID,
25+
"client_secret": CLIENT_SECRET
26+
}
27+
)
1828

19-
study_events_url = f"{LDOT_API_URL}{STUDY_GUID}/Action"
29+
token = response.json()["access_token"]
30+
print(token)
2031

21-
headers={"accept": "application/json"
32+
headers={"accept": "application/json",
33+
"Authorization": f"Bearer {token}"
2234
}
2335

2436
response = requests.get(
25-
study_events_url,
26-
auth=(),
37+
"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b/Action",
2738
headers=headers
2839
)
2940

0 commit comments

Comments
 (0)