Skip to content

Commit 6145b96

Browse files
author
“Carmel
committed
Set up GET to get subjects ready for a survey
1 parent a6b248c commit 6145b96

3 files changed

Lines changed: 43 additions & 53 deletions

File tree

app.py

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

4+
from new_ldot_workflows.b_1_get_new_subjects import get_new_subjects
45
from new_ldot_workflows.b_2_get_qualtrics_links import add_individuals_to_survey
56
from new_ldot_workflows.b_2_send_links_to_ldot import send_links_to_ldot
67
from new_ldot_workflows.b_4_get_individual_progress import get_individual_progress
@@ -9,7 +10,6 @@
910

1011
STUDIES = json.load(open("ldot_study_configs.json"))
1112

12-
1313
@app.route("/")
1414
def index():
1515
return render_template("index.html", studies=STUDIES)
@@ -22,7 +22,7 @@ def button1():
2222
study_id = data.get("study_id")
2323

2424
# TODO: Replace this with your actual API call that returns subject IDs
25-
subject_ids = ["subject1", "subject2", "subject3"]
25+
subject_ids = get_new_subjects(study_id)
2626

2727
message = f"Found {len(subject_ids)} subject IDs for study {study_id}" if study_id else f"Found {len(subject_ids)} subject IDs"
2828
return jsonify({"success": True, "message": message, "subject_ids": subject_ids})

ldot_study_configs.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
{
2-
"LDOT-001": {"name": "PIAMA study", "variables": {"survey_id": "SV_efCMOg6wHU0T8ii",
2+
"LDOT-001": {"name": "PIAMA study", "variables": {"ldot_study_id": "96a54061-555d-d74b-8e0b-84d43853897e",
3+
"survey_id": "SV_efCMOg6wHU0T8ii",
34
"directory_id": "POOL_10pyxk9leSUisrT",
45
"distribution_id": "EMD_7AEa416lRwFhrkF",
56
"mailing_list_id": "CG_2dMbO6WUBMnCeIK",
67
"embedded_data_field": "study_id_child"}},
7-
"LDOT-002": {"name": "LDOT Study 002", "variables": {"survey_id": "value3",
8+
"LDOT-002": {"name": "LDOT Study 002", "variables": {"ldot_study_id": "value1",
9+
"survey_id": "value3",
810
"directory_id": "POOL_10pyxk9leSUisrT",
911
"distribution_id": "EMD_7AEa416lRwFhrkF",
1012
"mailing_list_id": "value4",
1113
"embedded_data_field": "study_id_child"}},
12-
"LDOT-003": {"name": "LDOT Study 003", "variables": {"survey_id": "value5",
14+
"LDOT-003": {"name": "LDOT Study 003", "variables": {"ldot_study_id": "value2",
15+
"survey_id": "value5",
1316
"directory_id": "POOL_10pyxk9leSUisrT",
1417
"distribution_id": "EMD_7AEa416lRwFhrkF",
1518
"mailing_list_id": "value6",
16-
"embedded_data_field": "study_id_child"}},
19+
"embedded_data_field": "study_id_child"}}
1720
}
Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
2-
# 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.
3-
# 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.
4-
# 3. After adding the person to the mailing list, send them an email invitation to
5-
6-
# Grab the client ID and secret from the config file new_ldot_workflows\ldot_config.json
7-
8-
9-
101
import json
112
import requests
123

@@ -16,41 +7,37 @@
167
CLIENT_SECRET = config["client_secret"]
178
LDOT_API_URL = config["LDOT_API_URL"]
189

19-
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-
)
28-
29-
token = response.json()["access_token"]
30-
print(token)
31-
32-
headers={"accept": "application/json",
33-
"Authorization": f"Bearer {token}"
34-
}
35-
36-
response = requests.get(
37-
"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b/Action",
38-
headers=headers
39-
)
40-
41-
print(response.status_code)
42-
print(response.text)
43-
44-
45-
46-
47-
# Assuming the response contains a list of participants under the key 'participants'
48-
49-
50-
51-
52-
# Client ID for the PIAMA study: piama_api_qualtrics
53-
# Study GUID: 5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b
54-
55-
56-
#
10+
def get_new_subjects(study_id: str, link_creation_eaid: str) -> list:
11+
"""Get subjects that have not yet been added to Qualtrics by checking their event actions"""
12+
13+
response = requests.post(
14+
"https://accware.memic.maastrichtuniversity.nl/ldot_identity_server/connect/token",
15+
data={
16+
"grant_type": "client_credentials",
17+
"client_id": CLIENT_ID,
18+
"client_secret": CLIENT_SECRET
19+
}
20+
)
21+
22+
token = response.json()["access_token"]
23+
24+
headers={"accept": "application/json",
25+
"Authorization": f"Bearer {token}"
26+
}
27+
28+
response = requests.get(
29+
f"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/{study_id}/Action/{link_creation_eaid}",
30+
headers=headers
31+
)
32+
33+
response.raise_for_status()
34+
payload = response.json()
35+
study_event_actions = payload.get("Data", {}).get("StudyEventActions", [])
36+
return [
37+
action["SubjectGuid"]
38+
for action in study_event_actions
39+
if action.get("SubjectGuid")
40+
]
41+
42+
if __name__ == "__main__":
43+
print(get_new_subjects("5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b", "5d31129c-d814-5d4b-a96f-048cadc150ce"))

0 commit comments

Comments
 (0)