@@ -124,6 +124,7 @@ class Source:
124
124
VIOSCREEN_ID = 10001
125
125
MYFOODREPO_ID = 10002
126
126
POLYPHENOL_FFQ_ID = 10003
127
+ SKIN_SCORING_APP_ID = 10005
127
128
SPAIN_FFQ_ID = 10004
128
129
129
130
SYSTEM_MSG_DICTIONARY = {
@@ -398,6 +399,21 @@ class Source:
398
399
'est_minutes' : '30' ,
399
400
'icon' : 'survey_external.svg'
400
401
},
402
+ SKIN_SCORING_APP_ID : {
403
+ 'description' : 'This will direct you to the ModiFace skin-scoring web'
404
+ ' app. This app allows you to upload a selfie photo, '
405
+ 'which will be used to generate anonymized data about '
406
+ 'your skin for researchers and provide you with what '
407
+ 'the algorithm assesses to be your top two skin '
408
+ 'concerns. You will be provided a username and study'
409
+ ' code on the next screen to access the app, which '
410
+ 'will link your ModiFace results to your skin sample. '
411
+ 'This app is hosted by a third-party provider; we are '
412
+ 'unable to provide any assistance if you encounter '
413
+ 'errors or issues while using the app.' ,
414
+ 'est_minutes' : '5' ,
415
+ 'icon' : 'survey_external.svg'
416
+ },
401
417
}
402
418
LOCAL_SURVEY_SEQUENCE = [
403
419
BASIC_INFO_ID ,
@@ -466,7 +482,8 @@ def _get_req_survey_templates_by_source_type(source_type):
466
482
467
483
def _get_opt_survey_templates_by_source_type (source_type ):
468
484
if source_type == Source .SOURCE_TYPE_HUMAN :
469
- return [3 , 4 , 5 , 7 , MYFOODREPO_ID , POLYPHENOL_FFQ_ID , SPAIN_FFQ_ID ]
485
+ return [3 , 4 , 5 , 7 , MYFOODREPO_ID , POLYPHENOL_FFQ_ID ,
486
+ SPAIN_FFQ_ID , SKIN_SCORING_APP_ID ]
470
487
elif source_type == Source .SOURCE_TYPE_ANIMAL :
471
488
return []
472
489
elif source_type == Source .SOURCE_TYPE_ENVIRONMENT :
@@ -1398,6 +1415,14 @@ def get_fill_source_survey(*,
1398
1415
account_id , source_id , "data" , reconsent = True
1399
1416
)
1400
1417
1418
+ # this is remote, so go to an external url, not our jinja2 template
1419
+ return redirect (survey_output ['survey_template_text' ]['url' ])
1420
+ elif survey_template_id == SKIN_SCORING_APP_ID :
1421
+ if need_reconsent :
1422
+ return render_consent_page (
1423
+ account_id , source_id , "data" , reconsent = True
1424
+ )
1425
+
1401
1426
# this is remote, so go to an external url, not our jinja2 template
1402
1427
return redirect (survey_output ['survey_template_text' ]['url' ])
1403
1428
else :
@@ -1542,6 +1567,25 @@ def get_myfoodrepo_no_slots(*, account_id=None, source_id=None):
1542
1567
source_id = source_id )
1543
1568
1544
1569
1570
+ @prerequisite ([SOURCE_PREREQS_MET , BIOSPECIMEN_PREREQS_MET ])
1571
+ def post_ajax_skin_scoring_app_credentials (* , account_id , source_id ):
1572
+ need_reconsent = check_current_consent (account_id , source_id , "data" )
1573
+
1574
+ if need_reconsent :
1575
+ return render_consent_page (
1576
+ account_id , source_id , "data" , reconsent = True
1577
+ )
1578
+
1579
+ has_error , credentials , _ = ApiRequest .post (
1580
+ "/accounts/%s/sources/%s/surveys/skin_scoring_app_credentials"
1581
+ % (account_id , source_id )
1582
+ )
1583
+ if has_error == 404 :
1584
+ return flask .jsonify ({"app_username" : "" , "app_studycode" : "" })
1585
+ else :
1586
+ return flask .jsonify (credentials )
1587
+
1588
+
1545
1589
@prerequisite ([SOURCE_PREREQS_MET , BIOSPECIMEN_PREREQS_MET ])
1546
1590
def get_fill_vioscreen_remote_sample_survey (* ,
1547
1591
account_id = None ,
@@ -1850,7 +1894,10 @@ def get_source(*, account_id=None, source_id=None):
1850
1894
for answer in survey_answers :
1851
1895
template_id = answer ['survey_template_id' ]
1852
1896
for template in local_surveys + remote_surveys :
1853
- if template ['survey_template_id' ] == template_id :
1897
+ if template ['survey_template_id' ] == SKIN_SCORING_APP_ID :
1898
+ template ['survey_id' ] = answer ['survey_id' ]
1899
+ template ['answered' ] = True
1900
+ else :
1854
1901
template ['answered' ] = True
1855
1902
1856
1903
for template in local_surveys :
@@ -1879,11 +1926,24 @@ def get_source(*, account_id=None, source_id=None):
1879
1926
template ['est_minutes' ] = SURVEY_INFO [template_id ]['est_minutes' ]
1880
1927
template ['icon' ] = SURVEY_INFO [template_id ]['icon' ]
1881
1928
1882
- # TODO: MyFoodRepo logic needs to be refactored when we reactivate it
1883
- """
1884
1929
# any survey specific stuff like opening a tab
1885
1930
# or slot checking
1886
- for idx, template in enumerate(remote_surveys[:]):
1931
+ # NB: change "_" back to "idx" when MyFoodRepo is reactivated or if
1932
+ # another external survey requires similar functionality
1933
+ for _ , template in enumerate (remote_surveys [:]):
1934
+ if template ['survey_template_id' ] == SKIN_SCORING_APP_ID :
1935
+ has_error , credentials , _ = ApiRequest .get (
1936
+ '/accounts/%s/sources/%s/surveys/skin_scoring_app_credentials'
1937
+ % (account_id , source_id )
1938
+ )
1939
+
1940
+ if has_error :
1941
+ return has_error
1942
+
1943
+ template ['credentials' ] = credentials
1944
+
1945
+ # TODO: MyFoodRepo logic needs to be refactored when we reactivate it
1946
+ """
1887
1947
if template['survey_template_id'] == MYFOODREPO_ID:
1888
1948
has_error, slots, _ = ApiRequest.get('/slots/myfoodrepo')
1889
1949
if has_error:
@@ -1896,7 +1956,7 @@ def get_source(*, account_id=None, source_id=None):
1896
1956
per_source_not_taken.pop(idx)
1897
1957
else:
1898
1958
template['new_tab'] = False
1899
- """
1959
+ """
1900
1960
1901
1961
local_surveys = [translate_survey_template (s ) for s in local_surveys ]
1902
1962
remote_surveys = [translate_survey_template (s ) for s in remote_surveys ]
@@ -1911,7 +1971,8 @@ def get_source(*, account_id=None, source_id=None):
1911
1971
source_name = source_output ['source_name' ],
1912
1972
profile_has_samples = profile_has_samples ,
1913
1973
need_reconsent = need_reconsent ,
1914
- show_update_age = show_update_age
1974
+ show_update_age = show_update_age ,
1975
+ SKIN_SCORING_APP_ID = SKIN_SCORING_APP_ID
1915
1976
)
1916
1977
1917
1978
0 commit comments