Skip to content

Commit 7687612

Browse files
author
“Carmel
committed
Populate links in Ldot
1 parent c0707d3 commit 7687612

4 files changed

Lines changed: 32 additions & 33 deletions

File tree

app.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def button2():
6666
study, ldot_vars, qualtrics_vars = get_study_settings(study_id)
6767

6868
ldot_study_id = ldot_vars.get("ldot_study_id")
69-
eaid_deelnemer_entity = ldot_vars.get("eaid_deelnemer_entity")
69+
id_deelnemer_entity = ldot_vars.get("id_deelnemer_entity")
70+
id_location = ldot_vars.get("id_location")
71+
custom_var_qualtrics_link = ldot_vars.get("custom_var_qualtrics_link")
7072
qualtrics_survey_id = qualtrics_vars.get("survey_id")
7173
mailing_list_id = qualtrics_vars.get("mailing_list_id")
7274
embedded_data_field = qualtrics_vars.get("embedded_data_field")
@@ -79,7 +81,8 @@ def button2():
7981
debug_inputs = {
8082
"study_id": study_id,
8183
"ldot_study_id": ldot_study_id,
82-
"eaid_deelnemer_entity": eaid_deelnemer_entity,
84+
"id_deelnemer_entity": id_deelnemer_entity,
85+
"id_location": id_location,
8386
"new_subject_ids": new_subject_ids,
8487
"qualtrics_survey_id": qualtrics_survey_id,
8588
"mailing_list_id": mailing_list_id,
@@ -88,8 +91,8 @@ def button2():
8891
"distribution_id": distribution_id
8992
}
9093

91-
subject_id_to_link_dict = add_individuals_to_survey(new_subject_ids, ldot_study_id, eaid_deelnemer_entity, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id)
92-
send_links_to_ldot(ldot_study_id, eaid_deelnemer_entity, subject_id_to_link_dict)
94+
subject_id_to_link_dict = add_individuals_to_survey(new_subject_ids, ldot_study_id, id_deelnemer_entity, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id)
95+
send_links_to_ldot(ldot_study_id, id_deelnemer_entity, id_location, custom_var_qualtrics_link, subject_id_to_link_dict)
9396

9497
return jsonify({
9598
"success": True,

new_ldot_workflows/b_2_get_qualtrics_links.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_personal_link(qualtrics_survey_id: str, distribution_id: str, study_iden
8888
f"Unexpected response format when fetching personal link of individual {study_identifier}."
8989
) from exc
9090

91-
def add_individuals_to_survey(new_subject_ids: list, ldot_study_id: str, eaid_deelnemer_entity: str, embedded_data_field: str, distribution_id: str, qualtrics_survey_id: str, mailing_list_id: str, directory_id: str):
91+
def add_individuals_to_survey(new_subject_ids: list, ldot_study_id: str, id_deelnemer_entity: str, embedded_data_field: str, distribution_id: str, qualtrics_survey_id: str, mailing_list_id: str, directory_id: str):
9292
def convert_api_subject_id_to_study_identifier(api_subject_id):
9393
"""Convert subject ID used by the Ldot API to study identifier that can be used in Qualtrics surveys"""
9494

@@ -106,7 +106,7 @@ def convert_api_subject_id_to_study_identifier(api_subject_id):
106106
}
107107

108108
response = requests.get(
109-
f"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/{ldot_study_id}/Entity/{eaid_deelnemer_entity}",
109+
f"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/{ldot_study_id}/Entity/{id_deelnemer_entity}",
110110
headers=headers
111111
)
112112

@@ -140,14 +140,14 @@ def convert_api_subject_id_to_study_identifier(api_subject_id):
140140
# # Example usage
141141
participant_study_id = ["352fb9d8-962f-4735-9fc7-7b4e18109a51"]
142142
ldot_study_id = "5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b"
143-
eaid_deelnemer_entity = "7f61b810-00ed-1d41-8a33-4164f25ebad0"
143+
id_deelnemer_entity = "7f61b810-00ed-1d41-8a33-4164f25ebad0"
144144
embedded_data_field = "study_id_child"
145145
qualtrics_survey_id="SV_efCMOg6wHU0T8ii"
146146
mailing_list_id="CG_2dMbO6WUBMnCeIK"
147147
distribution_id="EMD_7AEa416lRwFhrkF"
148148
directory_id="POOL_10pyxk9leSUisrT"
149149

150-
link = add_individuals_to_survey(participant_study_id, ldot_study_id, eaid_deelnemer_entity, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id)
150+
link = add_individuals_to_survey(participant_study_id, ldot_study_id, id_deelnemer_entity, embedded_data_field, distribution_id, qualtrics_survey_id, mailing_list_id, directory_id)
151151

152152
print(link)
153153

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
# {'11111TEST11111': 'https://survey.uu.nl/jfe/form/SV_efCMOg6wHU0T8ii?Q_CHL=gl&Q_DL=EMD_7AEa416lRwFhrkF_efCMOg6wHU0T8ii_CGC_CJK3jAlcohFgRMS&_g_=g', '22222TEST22222': 'https://survey.uu.nl/jfe/form/SV_efCMOg6wHU0T8ii?Q_CHL=gl&Q_DL=EMD_7AEa416lRwFhrkF_efCMOg6wHU0T8ii_CGC_M6crsA37s6sSOeE&_g_=g'}
3-
41
import json
52
import requests
63

@@ -11,9 +8,7 @@
118
LDOT_API_URL = config["LDOT_API_URL"]
129

1310

14-
#### I then need to flip it to the next status
15-
16-
def send_links_to_ldot(study_id: str, eaid_deelnemer_entity, subject_id_to_link_dict: dict) -> list:
11+
def send_links_to_ldot(ldot_study_id: str, id_deelnemer_entity: str, id_location: str, custom_var_qualtrics_link: str, subject_id_to_link_dict: dict) -> list:
1712
"""Post the Qualtrics links back to Ldot for new subjects"""
1813

1914
response = requests.post(
@@ -24,31 +19,30 @@ def send_links_to_ldot(study_id: str, eaid_deelnemer_entity, subject_id_to_link_
2419
"client_secret": CLIENT_SECRET
2520
}
2621
)
27-
2822
token = response.json()["access_token"]
29-
3023
headers={"accept": "application/json",
3124
"Authorization": f"Bearer {token}"
3225
}
3326

34-
subject_alias = "a5335cfd-b96a-4c08-b860-700cc4867ec3"
35-
response = requests.post(
36-
f"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/{study_id}/Subject/VerifySubject",
37-
headers=headers
38-
)
27+
for subject_id, link in subject_id_to_link_dict.items():
28+
response = requests.post(
29+
f"https://accware.memic.maastrichtuniversity.nl/memic_ldot_api/api/v1.1/{ldot_study_id}/Subject/",
30+
headers=headers,
31+
json = {
32+
"subjectGuid": subject_id,
33+
"entityId": id_deelnemer_entity,
34+
"locationSubjectId": id_location,
35+
custom_var_qualtrics_link: link, # Custom var that corresponds to the Qualtrics link in Ldot
36+
"doOverwriteNulls": False,
37+
}
38+
)
3939

40-
response.raise_for_status()
41-
payload = response.json()
42-
print(payload)
43-
# study_event_actions = payload.get("Data", {}).get("StudyEventActions", [])
44-
# return [
45-
# action["SubjectGuid"]
46-
# for action in study_event_actions
47-
# if action.get("SubjectGuid")
48-
# ]
4940

5041
if __name__ == "__main__":
51-
study_id = "5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b"
42+
ldot_study_id = "5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b"
43+
id_deelnemer_entity = "7f61b810-00ed-1d41-8a33-4164f25ebad0"
44+
id_location = "427f304f-9d95-44f5-8f7b-d6a1ce1db293"
5245
subject_id_to_link_dict = {'352fb9d8-962f-4735-9fc7-7b4e18109a51': 'https://survey.uu.nl/jfe/form/SV_efCMOg6wHU0T8ii?Q_CHL=gl&Q_DL=EMD_7AEa416lRwFhrkF_efCMOg6wHU0T8ii_CGC_4WW2MwOaEB01XsM&_g_=g'}
46+
custom_var_qualtrics_link = "customVar01"
5347

54-
send_links_to_ldot(study_id, subject_id_to_link_dict)
48+
send_links_to_ldot(ldot_study_id, id_deelnemer_entity, id_location, custom_var_qualtrics_link, subject_id_to_link_dict)

study_configs.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ LDOT-001:
22
name: PIAMA study
33
ldot_variables:
44
ldot_study_id: 5c9c6a47-c8d7-8142-a8c8-ccdcb8a8044b
5-
eaid_deelnemer_entity: 7f61b810-00ed-1d41-8a33-4164f25ebad0 # Entity ID for the participant entity in the study
5+
id_deelnemer_entity: 7f61b810-00ed-1d41-8a33-4164f25ebad0 # Entity ID for the participant entity in the study
6+
id_location: 427f304f-9d95-44f5-8f7b-d6a1ce1db293
7+
custom_var_qualtrics_link: customVar01
68
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
79
eaid_qualtrics_survey_link_creation_completed: 31599192-8e9b-4341-b7f4-8b8967dd846a #Action event for when the qualtrics survey link creation is completed
810
eaid_survey_invitation_completed: 337ecba2-3dd3-1141-8c38-6cffdcfbd7eb #Action event for when the survey invitation has been sent

0 commit comments

Comments
 (0)