Skip to content

Commit 33b294d

Browse files
author
“Carmel
committed
Complete button 1
1 parent c7d57c3 commit 33b294d

8 files changed

Lines changed: 51 additions & 65 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
venv/
22
new_ldot_workflows/ldot_config.json
3-
new_ldot_workflows/qualtrics_settings.py
3+
new_ldot_workflows/qualtrics_settings.py
4+
scratch.py

app.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def index():
2929

3030
@app.route("/api/button1", methods=["POST"])
3131
def button1():
32-
"""Get the participants who have not yet been added to Qualtrics"""
32+
"""Get the participants who have not yet been given a survey link and return their subjectIDs"""
33+
3334
data = request.json
3435
study_id = data.get("study_id")
3536
print(f"Received study_id: {study_id}")
@@ -39,61 +40,61 @@ def button1():
3940
return jsonify({"success": False, "message": f"Unknown study_id: {study_id}"}), 400
4041

4142
ldot_study_id = ldot_vars.get("ldot_study_id")
42-
link_creation_eaid = ldot_vars.get("link_creation_eaid") or ldot_vars.get("survey_progress_wait_for_entry_eaid")
43+
link_creation_eaid = ldot_vars.get("eaid_qualtrics_survey_link_creation_to_do_date")
4344

44-
subject_ids = get_new_subjects(ldot_study_id, link_creation_eaid)
45+
new_subjects_ids = get_new_subjects(ldot_study_id, link_creation_eaid)
4546

46-
message = f"Found {len(subject_ids)} subject IDs for study {study_id}" if study_id else f"Found {len(subject_ids)} subject IDs"
47-
return jsonify({"success": True, "message": message, "subject_ids": subject_ids})
47+
message = f"Found {len(new_subjects_ids)} new subjects in this study"
48+
return jsonify({"success": True, "message": message, "new_subject_ids": new_subjects_ids})
4849

4950

5051

5152
@app.route("/api/button2", methods=["POST"])
5253
def button2():
53-
"""Second API call - uses subjectIDs from button1"""
54+
"""Uses subjectIDs from button 1 to add them to Qualtrics and send the links back to LDOT"""
5455
data = request.json
5556
study_id = data.get("study_id")
56-
subject_ids = data.get("subject_ids")
57+
new_subject_ids = data.get("new_subject_ids")
5758

5859
if not study_id:
5960
return jsonify({"success": False, "message": "Missing study_id in request"}), 400
6061

61-
if not subject_ids:
62-
return jsonify({"success": False, "message": "Missing subject_ids in request"}), 400
62+
if not new_subject_ids:
63+
return jsonify({"success": False, "message": "Missing new_subject_ids in request"}), 400
6364

6465
# Lookup study variables from STUDIES config
6566
study, ldot_vars, qualtrics_vars = get_study_settings(study_id)
66-
if not study:
67-
return jsonify({"success": False, "message": f"Unknown study_id: {study_id}"}), 400
6867

6968
ldot_study_id = ldot_vars.get("ldot_study_id")
70-
survey_id = qualtrics_vars.get("survey_id")
69+
qualtrics_survey_id = qualtrics_vars.get("survey_id")
7170
mailing_list_id = qualtrics_vars.get("mailing_list_id")
7271
embedded_data_field = qualtrics_vars.get("embedded_data_field")
7372
directory_id = qualtrics_vars.get("directory_id")
7473
distribution_id = qualtrics_vars.get("distribution_id")
75-
link_creation_eaid = ldot_vars.get("link_creation_eaid") or ldot_vars.get("survey_progress_wait_for_entry_eaid")
76-
74+
75+
76+
# link_creation_eaid = ldot_vars.get("eaid_qualtrics_survey_link_creation_to_do_date") or ldot_vars.get("eaid_qualtrics_survey_link_creation_completed")
77+
7778
if not ldot_study_id:
7879
return jsonify({"success": False, "message": f"Missing ldot_study_id for study_id: {study_id}"}), 400
7980

8081
debug_inputs = {
8182
"study_id": study_id,
8283
"ldot_study_id": ldot_study_id,
83-
"subject_ids": subject_ids,
84-
"survey_id": survey_id,
84+
"new_subject_ids": new_subject_ids,
85+
"qualtrics_survey_id": qualtrics_survey_id,
8586
"mailing_list_id": mailing_list_id,
8687
"embedded_data_field": embedded_data_field,
8788
"directory_id": directory_id,
8889
"distribution_id": distribution_id
8990
}
9091

91-
participant_to_link_dict = add_individuals_to_survey(subject_ids, embedded_data_field, distribution_id, survey_id, mailing_list_id, directory_id)
92-
send_links_to_ldot(ldot_study_id, link_creation_eaid)
92+
participant_to_link_dict = add_individuals_to_survey(new_subject_ids, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id)
93+
# send_links_to_ldot(ldot_study_id, link_creation_eaid)
9394

9495
return jsonify({
9596
"success": True,
96-
"message": f"Processed {len(subject_ids)} subject IDs for study {study_id}",
97+
"message": f"Processed {len(new_subject_ids)} subject IDs for study {study_id}",
9798
"debug_inputs": debug_inputs,
9899
"participant_to_link_dict": participant_to_link_dict,
99100
})
@@ -142,17 +143,17 @@ def button4():
142143
if not study:
143144
return jsonify({"success": False, "message": f"Unknown study_id: {study_id}"}), 400
144145

145-
survey_id = vars.get("survey_id")
146+
qualtrics_survey_id = vars.get("qualtrics_survey_id")
146147
embedded_data_field = vars.get("embedded_data_field")
147148

148-
participant_to_progress_dict = get_individual_progress(subject_ids, embedded_data_field, survey_id)
149+
participant_to_progress_dict = get_individual_progress(subject_ids, embedded_data_field, qualtrics_survey_id)
149150

150151

151152
return jsonify({
152153
"success": True,
153154
"message": f"Retrieved progress for {len(participant_to_progress_dict)} subjects",
154155
"study_id": study_id,
155-
"survey_id": survey_id,
156+
"qualtrics_survey_id": qualtrics_survey_id,
156157
"embedded_data_field": embedded_data_field,
157158
"progress_results": participant_to_progress_dict,
158159
})
Binary file not shown.
Binary file not shown.

new_ldot_workflows/b_1_get_new_subjects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ def get_new_subjects(study_id: str, link_creation_eaid: str) -> list:
4040
]
4141

4242
if __name__ == "__main__":
43+
# For testing purposes
4344
print(get_new_subjects("5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b", "5d31129c-d814-5d4b-a96f-048cadc150ce"))

new_ldot_workflows/b_2_get_qualtrics_links.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def check_contact_in_mailing_list(participant_study_id: str, mailing_list_id: st
2929

3030
def add_contact_to_mailing_list(participant_study_id: str, embedded_data_field: str, mailing_list_id: str, directory_id: str) -> None:
3131
"""Add contact to a mailing list"""
32-
print(participant_study_id)
3332

3433
endpoint = f"{BASE_URL}/directories/{directory_id}/mailinglists/{mailing_list_id}/contacts"
3534
contact_information_payload ={
@@ -40,7 +39,6 @@ def add_contact_to_mailing_list(participant_study_id: str, embedded_data_field:
4039
}
4140
try:
4241
response = requests.post(endpoint, headers=HEADERS, json=contact_information_payload)
43-
print(response.json())
4442
response.raise_for_status()
4543

4644
except requests.exceptions.RequestException as exc:
@@ -52,14 +50,14 @@ def add_contact_to_mailing_list(participant_study_id: str, embedded_data_field:
5250
f"Unexpected response format when adding contact to mailing list."
5351
) from exc
5452

55-
def get_personal_link(survey_id: str, distribution_id: str, participant_study_id: str) -> str:
53+
def get_personal_link(qualtrics_survey_id: str, distribution_id: str, participant_study_id: str) -> str:
5654
"""Get the person link of an individual for a specified survey. Returns personal link for the participant, looks like
5755
https://survey.uu.nl/jfe/form/SV_efCMOg6wHU0T8ii?Q_CHLqe2Pdrma&_g_=g
5856
"""
5957
print(f"Fetching personal link for {participant_study_id}... ")
6058
endpoint = f"{BASE_URL}/distributions/{distribution_id}/links"
6159
parameters = {
62-
"surveyId": str(survey_id)
60+
"surveyId": str(qualtrics_survey_id)
6361
}
6462
try:
6563
response = requests.get(endpoint, headers=HEADERS, params=parameters)
@@ -77,7 +75,7 @@ def get_personal_link(survey_id: str, distribution_id: str, participant_study_id
7775
f"Unexpected response format when fetching personal link of individual {participant_study_id}."
7876
) from exc
7977

80-
def add_individuals_to_survey(participant_ids_list: list, embedded_data_field, distribution_id, survey_id, mailing_list_id, directory_id):
78+
def add_individuals_to_survey(participant_ids_list: list, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id):
8179
participant_to_link_dict = {}
8280
for participant_id in participant_ids_list:
8381
contact_exists = check_contact_in_mailing_list(participant_id, mailing_list_id, directory_id)
@@ -87,27 +85,25 @@ def add_individuals_to_survey(participant_ids_list: list, embedded_data_field, d
8785
else:
8886
print(f"Participant study ID {participant_id} already exists in this mailing list")
8987

90-
personal_link = get_personal_link(survey_id, distribution_id, participant_id)
88+
personal_link = get_personal_link(qualtrics_survey_id, distribution_id, participant_id)
9189

9290
participant_to_link_dict[participant_id] = personal_link
9391

94-
print(participant_to_link_dict)
9592
return participant_to_link_dict
9693

9794
if __name__ == "__main__":
9895
# # Example usage
9996
participant_study_id = ["11111TEST11111", "22222TEST22222", "33333TEST33333"]
10097
embedded_data_field = "study_id_child"
101-
survey_id="SV_efCMOg6wHU0T8ii"
98+
qualtrics_survey_id="SV_efCMOg6wHU0T8ii"
10299
mailing_list_id="CG_2dMbO6WUBMnCeIK"
103100
distribution_id="EMD_7AEa416lRwFhrkF"
104101
directory_id="POOL_10pyxk9leSUisrT"
105102

106103

104+
link = add_individuals_to_survey(participant_study_id, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id)
107105

106+
print(link)
108107

109-
link = add_individuals_to_survey(participant_study_id, embedded_data_field, distribution_id, survey_id, mailing_list_id, directory_id)
110-
111-
112-
# print(link)
108+
113109
# print(get_mailing_list_id_of_distribution("SV_efCMOg6wHU0T8ii", "EMD_SZFeoK7LAJBHU4d"))

study_configs.yaml

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
LDOT-001:
22
name: PIAMA study
33
ldot_variables:
4-
ldot_study_id: 96a54061-555d-d74b-8e0b-84d43853897e
5-
link_creation_eaid: 5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b #Action event
6-
linked_created_survey_eaid: "?"
7-
survey_progress_wait_for_entry_eaid: 9f09f2cf-32cc-844d-9a41-7a44accd3dfd
8-
survey_progress_completed_eaid: 120d298d-9aa9-084b-abc6-432148db0e10
4+
ldot_study_id: 5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b
5+
eaid_qualtrics_survey_link_creation_to_do_date: 5d31129c-d814-5d4b-a96f-048cadc150ce #Action event for when the qualtrics survey link creation hasn't been done
6+
eaid_qualtrics_survey_link_creation_completed: 31599192-8e9b-4341-b7f4-8b8967dd846a #Action event for when the qualtrics survey link creation is completed
7+
# survey_progress_wait_for_entry_eaid: 9f09f2cf-32cc-844d-9a41-7a44accd3dfd
8+
# survey_progress_completed_eaid: 120d298d-9aa9-084b-abc6-432148db0e10
99
qualtrics_variables:
10-
survey_id: SV_efCMOg6wHU0T8ii
10+
qualtrics_survey_id: SV_efCMOg6wHU0T8ii
1111
directory_id: POOL_10pyxk9leSUisrT
1212
distribution_id: EMD_7AEa416lRwFhrkF
1313
mailing_list_id: CG_2dMbO6WUBMnCeIK
14-
embedded_data_field: study_id_child
15-
16-
LDOT-002:
17-
name:
18-
ldot_variables:
19-
ldot_study_id:
20-
qualtrics_variables:
21-
survey_id:
22-
mailing_list_id:
23-
embedded_data_field:
24-
25-
LDOT-003:
26-
name:
27-
ldot_variables:
28-
ldot_study_id:
29-
qualtrics_variables:
30-
survey_id:
31-
directory_id:
32-
distribution_id:
33-
mailing_list_id:
34-
embedded_data_field:
14+
embedded_data_field: study_id_child

templates/index.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ <h1>LDOT Qualtrics API Workflow</h1>
219219
</div>
220220

221221
<script>
222+
const buttonLabels = {
223+
1: 'Find new subjects in Ldot',
224+
2: 'Create Qualtrics survey links and send to Ldot',
225+
3: "Find subjects' survey completion status",
226+
4: 'Send survey completion status to Ldot'
227+
};
228+
222229
const state = {
223230
selectedStudy: null,
224231
completed: [false, false, false, false],
@@ -287,7 +294,7 @@ <h1>LDOT Qualtrics API Workflow</h1>
287294
row.classList.add('completed');
288295
row.classList.remove('error');
289296
btn.className = '';
290-
btn.textContent = `Step ${step} ✓`;
297+
btn.textContent = buttonLabels[step];
291298

292299
// Store subject_ids if returned
293300
if (data.subject_ids) {
@@ -311,7 +318,7 @@ <h1>LDOT Qualtrics API Workflow</h1>
311318
row.classList.add('error');
312319
row.classList.remove('completed');
313320
btn.className = '';
314-
btn.textContent = `Execute Step ${step}`;
321+
btn.textContent = buttonLabels[step];
315322
}
316323
}
317324

@@ -326,7 +333,7 @@ <h1>LDOT Qualtrics API Workflow</h1>
326333
const row = document.getElementById(`row-${i}`);
327334

328335
btn.className = '';
329-
btn.textContent = `Execute Step ${i}`;
336+
btn.textContent = buttonLabels[i];
330337
btn.disabled = true;
331338
output.textContent = 'No output yet';
332339
output.className = 'output empty';

0 commit comments

Comments
 (0)