Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external survey - skin scoring app #322

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Source:
VIOSCREEN_ID = 10001
MYFOODREPO_ID = 10002
POLYPHENOL_FFQ_ID = 10003
SKIN_SCORING_APP_ID = 10005
SPAIN_FFQ_ID = 10004

SYSTEM_MSG_DICTIONARY = {
Expand Down Expand Up @@ -398,6 +399,11 @@ class Source:
'est_minutes': '30',
'icon': 'survey_external.svg'
},
SKIN_SCORING_APP_ID: {
'description': 'TBD',
'est_minutes': 'TBD',
'icon': 'survey_external.svg'
},
}
LOCAL_SURVEY_SEQUENCE = [
BASIC_INFO_ID,
Expand Down Expand Up @@ -466,7 +472,8 @@ def _get_req_survey_templates_by_source_type(source_type):

def _get_opt_survey_templates_by_source_type(source_type):
if source_type == Source.SOURCE_TYPE_HUMAN:
return [3, 4, 5, 7, MYFOODREPO_ID, POLYPHENOL_FFQ_ID, SPAIN_FFQ_ID]
return [3, 4, 5, 7, MYFOODREPO_ID, POLYPHENOL_FFQ_ID,
SPAIN_FFQ_ID, SKIN_SCORING_APP_ID]
elif source_type == Source.SOURCE_TYPE_ANIMAL:
return []
elif source_type == Source.SOURCE_TYPE_ENVIRONMENT:
Expand Down Expand Up @@ -1397,6 +1404,14 @@ def get_fill_source_survey(*,
account_id, source_id, "data", reconsent=True
)

# this is remote, so go to an external url, not our jinja2 template
return redirect(survey_output['survey_template_text']['url'])
elif survey_template_id == SKIN_SCORING_APP_ID:
if need_reconsent:
return render_consent_page(
account_id, source_id, "data", reconsent=True
)

# this is remote, so go to an external url, not our jinja2 template
return redirect(survey_output['survey_template_text']['url'])
else:
Expand Down Expand Up @@ -1849,7 +1864,10 @@ def get_source(*, account_id=None, source_id=None):
for answer in survey_answers:
template_id = answer['survey_template_id']
for template in local_surveys + remote_surveys:
if template['survey_template_id'] == template_id:
if template['survey_template_id'] == 10005:
ayobi marked this conversation as resolved.
Show resolved Hide resolved
template['survey_id'] = answer['survey_id']
template['answered'] = True
else:
template['answered'] = True

for template in local_surveys:
Expand Down
10 changes: 6 additions & 4 deletions microsetta_interface/templates/source.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,22 @@
<div class="row mt-4">
{% for detail in remote_surveys %}
<div class="col-12 col-sm-6 col-md-4 p-2">
{% if not detail.answered %}
{% if detail.survey_template_id == 10005 or not detail.answered %}
ayobi marked this conversation as resolved.
Show resolved Hide resolved
<a style="text-decoration: none" onClick="return takeExternalSurvey('/accounts/{{ account_id }}/sources/{{ source_id }}/take_survey?survey_template_id={{ detail.survey_template_id }}', '{{ detail.survey_template_title }}', '{{ detail.description }}');" href="/accounts/{{ account_id }}/sources/{{ source_id }}/take_survey?survey_template_id={{ detail.survey_template_id }}" target="_blank">
{% endif %}
<div class="card card-survey-external">
<div class="row m-2 survey-info-row">
{% if detail.answered %}
{% if detail.survey_template_id == 10005 and detail.answered %}
<div class="col-8 card-survey-new">{{ _('COMPLETED') }} <br> {{ _('Unique ID') }}: {{ detail.survey_id }}</div>
{% elif detail.answered %}
<div class="col-8 card-survey-completed">{{ _('COMPLETED') }}</div>
{% else %}
<div class="col-8 card-survey-new">{{ _('NEW') }}</div>
{% endif %}
<div class="col-4 small-text survey-info text-end">{{ detail.est_minutes }} {{ _('min') }}</div>
</div>
<div class="row m-3 text-center survey-title">
{% if not detail.answered %}
{% if not detail.answered or detail.survey_template_id == 10005 %}
<img src="/static/img/survey_external.svg" class="card-survey-icon-external">
{% else %}
<img src="/static/img/survey_external_taken.svg" class="card-survey-icon-external">
Expand All @@ -150,7 +152,7 @@
{% endif %}
</div>
</div>
{% if not detail.answered %}
{% if not detail.answered or detail.survey_template_id == 10005 %}
</a>
{% endif %}
</div>
Expand Down
6 changes: 6 additions & 0 deletions microsetta_interface/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _fake_jwt(email, verified, uniqify=False):
MYFOODREPO_ID = 10002
POLYPHENOL_FFQ_ID = 10003
SPAIN_FFQ_ID = 10004
SKIN_SCORING_ID = 10005
ayobi marked this conversation as resolved.
Show resolved Hide resolved

BASIC_INFO_SIMPLE = {"112": "1970"}
BASIC_INFO_SIMPLE_ALT = {"112": "1983"}
Expand Down Expand Up @@ -573,6 +574,11 @@ def _complete_spain_ffq_survey(self, account_id, source_id):
f'take_survey?survey_template_id=10004')
return self.app.get(url), url

def _complete_skin_scoring_app_survey(self, account_id, source_id):
url = (f'/accounts/{account_id}/sources/{source_id}/'
f'take_survey?survey_template_id=10005')
return self.app.get(url), url

def test_new_user_to_source_listing(self):
resp, url, user_jwt = self._new_to_create()
account_id, _, _ = self._ids_from_url(url)
Expand Down
Loading