Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cassidysymons committed Dec 11, 2023
1 parent e3366ca commit 79fac20
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
41 changes: 25 additions & 16 deletions microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ class Source:
# Age groups for consent purposes, in order. Order is key as this will be
# used to govern progression. E.g., a child may move to teen, but a teen may
# not move to child.
HUMAN_CONSENT_AGE_GROUPS = ("0-6", "7-12", "13-17", "18-plus")
HUMAN_CONSENT_TODDLER = "0-6"
HUMAN_CONSENT_CHILD = "7-12"
HUMAN_CONSENT_ADOLESCENT = "13-17"
HUMAN_CONSENT_ADULT = "18-plus"
HUMAN_CONSENT_AGE_GROUPS = (
HUMAN_CONSENT_TODDLER,
HUMAN_CONSENT_CHILD,
HUMAN_CONSENT_ADOLESCENT,
HUMAN_CONSENT_ADULT
)

# States
NEEDS_REROUTE = "NeedsReroute"
Expand Down Expand Up @@ -1219,7 +1228,7 @@ def get_consent_page(*, account_id=None):
age_range=None,
source_id=None,
reconsent=reconsent,
cur_age_index=-1,
cur_age="UNKNOWN",
update_age=False
)

Expand Down Expand Up @@ -1664,13 +1673,10 @@ def render_consent_page(account_id, source_id, form_type, sample_ids=None,
# biospecimen consent
skip_dupe_check = True

try:
cur_age_index = HUMAN_CONSENT_AGE_GROUPS.index(
source_output['consent']['age_range']
)
except ValueError:
# In case a source has a blank, legacy or faulty age range
cur_age_index = -1
if source_output['consent']['age_range'] in HUMAN_CONSENT_AGE_GROUPS:
cur_age = source_output['consent']['age_range']
else:
cur_age = "UNKNOWN"

return _render_with_defaults(
'new_participant.jinja2',
Expand All @@ -1687,7 +1693,7 @@ def render_consent_page(account_id, source_id, form_type, sample_ids=None,
account_id=account_id,
source_id=source_id,
skip_dupe_check=skip_dupe_check,
cur_age_index=cur_age_index,
cur_age=cur_age,
update_age=update_age
)

Expand All @@ -1703,6 +1709,7 @@ def decline_reconsent(*, account_id, source_id):
)


@prerequisite([SOURCE_PREREQS_MET, BIOSPECIMEN_PREREQS_MET])
def get_update_age(*, account_id, source_id):
# Retrieve the source
has_error, source_output, _ = ApiRequest.get(
Expand All @@ -1712,7 +1719,7 @@ def get_update_age(*, account_id, source_id):
return source_output

# Adults can't change their age range, redirect them to My Profile
if source_output['consent']['age_range'] == "18-plus":
if source_output['consent']['age_range'] == HUMAN_CONSENT_ADULT:
return redirect(
"/accounts/%s/sources/%s" %
(account_id, source_id)
Expand Down Expand Up @@ -2237,13 +2244,15 @@ def get_consent_view(*, account_id=None, source_id=None, consent_type=None):

consent_type_lifestage = consent_output['consent_type'].split("_")[0]
if consent_type_lifestage == "adult":
age_range = "18-plus"
age_range = HUMAN_CONSENT_ADULT
elif consent_type_lifestage == "adolescent":
age_range = "13-17"
age_range = HUMAN_CONSENT_ADOLESCENT
elif consent_type_lifestage == "child":
age_range = "7-12"
age_range = HUMAN_CONSENT_CHILD
elif consent_type_lifestage == "parent":
age_range = HUMAN_CONSENT_TODDLER
else:
age_range = "0-6"
raise ValueError(f"This shouldn't happen: {consent_type_lifestage}")

if consent_type == "biospecimen":
consent_type_display = "Biospecimen"
Expand Down Expand Up @@ -3650,7 +3659,7 @@ def check_current_consent(account_id, source_id, consent_type):


def check_show_update_age(age_range):
return age_range != "18-plus"
return age_range != HUMAN_CONSENT_ADULT


class BearerAuth(AuthBase):
Expand Down
12 changes: 6 additions & 6 deletions microsetta_interface/templates/new_participant.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,21 @@
</div>
<div class="row mb-4">
{% if language_tag != "ja_JP" %}
{% if cur_age_index <= 0 %}
{% if cur_age in ("UNKNOWN", "0-6") %}
<div class="col-md">
<input type="radio" id="age-range-1" name="age-range" value="0-6" onchange="change_consent_div(this)" {% if cur_age_index == 0 %}checked{% endif %}>
<input type="radio" id="age-range-1" name="age-range" value="0-6" onchange="change_consent_div(this)" {% if cur_age == '0-6' %}checked{% endif %}>
<label for="age-range-1" class="consent-age-label">{{ tl['PARTICIPANT_FORM']['AGE_0_6'] |e}}</label>
</div>
{% endif %}
{% if cur_age_index <= 1 %}
{% if cur_age in ("UNKNOWN", "0-6", "7-12") %}
<div class="col-md">
<input type="radio" id="age-range-2" name="age-range" value="7-12" onchange="change_consent_div(this)" {% if cur_age_index == 1 %}checked{% endif %}>
<input type="radio" id="age-range-2" name="age-range" value="7-12" onchange="change_consent_div(this)" {% if cur_age == '7-12' %}checked{% endif %}>
<label for="age-range-2" class="consent-age-label">{{ tl['PARTICIPANT_FORM']['AGE_7_12'] |e}}</label>
</div>
{% endif %}
{% if cur_age_index <= 2 %}
{% if cur_age in ("UNKNOWN", "0-6", "7-12", "13-17") %}
<div class="col-md">
<input type="radio" id="age-range-3" name="age-range" value="13-17" onchange="change_consent_div(this)" {% if cur_age_index == 2 %}checked{% endif %}>
<input type="radio" id="age-range-3" name="age-range" value="13-17" onchange="change_consent_div(this)" {% if cur_age == '13-17' %}checked{% endif %}>
<label for="age-range-3" class="consent-age-label">{{ tl['PARTICIPANT_FORM']['AGE_13_17'] |e}}</label>
</div>
{% endif %}
Expand Down

0 comments on commit 79fac20

Please sign in to comment.