Skip to content

Commit

Permalink
Merge pull request #285 from biocore/csymons_overhaul_20230823
Browse files Browse the repository at this point in the history
Reconsent Tweaks & Results Report Content
  • Loading branch information
wasade authored Aug 29, 2023
2 parents 7b9ce0f + 3d3d573 commit 1ed2273
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 69 deletions.
125 changes: 103 additions & 22 deletions microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,19 @@ def get_account(*, account_id=None):
if RECONSENT_DECLINED_KEY in session:
session.pop(RECONSENT_DECLINED_KEY)

# Determine if the source/profile has any action items. This framework
# will evolve over time.
for s in sources:
alerts = 0

need_reconsent_d = check_current_consent(
account_id, s[SOURCE_ID], "data"
)
if need_reconsent_d:
alerts += 1

s['alerts'] = alerts

sources = [translate_source(s) for s in sources]

japan_user = False
Expand Down Expand Up @@ -1162,7 +1175,8 @@ def get_consent_page(*, account_id=None):
return consent_output

form_type = "data"
reconsent = False
skip_dupe_check = False
reconsent = None

return _render_with_defaults(
'new_participant.jinja2',
Expand All @@ -1171,12 +1185,13 @@ def get_consent_page(*, account_id=None):
duplicate_source_check=duplicate_source_check,
home_url=home_url,
form_type=form_type,
reconsent=reconsent,
skip_dupe_check=skip_dupe_check,
language_tag=session_locale(),
account_id=account_id,
participant_name=None,
age_range=None,
source_id=None
source_id=None,
reconsent=reconsent
)


Expand Down Expand Up @@ -1242,11 +1257,19 @@ def post_create_human_source(*, account_id=None, body=None):
return consent_output

session.pop(SOURCE_ID)
return post_claim_samples(
account_id=account_id,
source_id=source_id,
sample_ids=body['sample_ids']
)
# Yes, "None" is coming through as a string in this instance, not as
# an actual None type.
if body["sample_ids"] != "None":
return post_claim_samples(
account_id=account_id,
source_id=source_id,
sample_ids=body['sample_ids']
)
else:
return redirect(
"/accounts/%s/sources/%s/kits" %
(account_id, source_id)
)


@prerequisite([ACCT_PREREQS_MET])
Expand Down Expand Up @@ -1362,6 +1385,11 @@ def get_fill_source_survey(*,
ctr = 0
trig_ctr = 0
for field in group['fields']:
if need_reconsent:
# If the user has not agreed to the current consent, we
# disable all of the fields.
field['disabled'] = True

if "triggered_by" in field:
field['label'] = str(ctr) + ascii_lowercase[trig_ctr]\
+ ". " + field['label']
Expand Down Expand Up @@ -1828,6 +1856,13 @@ def get_kits(*, account_id=None, source_id=None, check_survey_date=False):

prompt_survey_update = prompt_response['prompt']

need_reconsent_data = check_current_consent(
account_id, source_id, "data"
)
need_reconsent_biospecimen = check_current_consent(
account_id, source_id, "biospecimen"
)

return _render_with_defaults(
'kits.jinja2',
account_id=account_id,
Expand All @@ -1842,7 +1877,9 @@ def get_kits(*, account_id=None, source_id=None, check_survey_date=False):
public_endpoint=SERVER_CONFIG['public_api_endpoint'],
profile_has_samples=profile_has_samples,
prompt_survey_update=prompt_survey_update,
prompt_survey_id=BASIC_INFO_ID
prompt_survey_id=BASIC_INFO_ID,
need_reconsent_data=need_reconsent_data,
need_reconsent_biospecimen=need_reconsent_biospecimen
)


Expand Down Expand Up @@ -2037,6 +2074,22 @@ def get_consent_view(*, account_id=None, source_id=None, consent_type=None):
)


def get_reconsent(*, account_id, source_id, consent_type):
# Let's make sure they actually need to reconsent
need_reconsent = check_current_consent(
account_id, source_id, consent_type
)

if need_reconsent is False:
# User shouldn't be here, send them back to their profile
return redirect(
"/accounts/%s/sources/%s" %
(account_id, source_id)
)
else:
return render_consent_page(account_id, source_id, consent_type)


# Note: ideally this would be represented as a DELETE, not as a GET
# However, it is used as a link, and HTML links do not support a DELETE
# action
Expand All @@ -2054,7 +2107,7 @@ def get_remove_source(*,
return _refresh_state_and_route_to_sink(account_id)


@prerequisite([BIOSPECIMEN_PREREQS_MET])
@prerequisite([SOURCE_PREREQS_MET, BIOSPECIMEN_PREREQS_MET])
def get_update_sample(*, account_id=None, source_id=None, sample_id=None):
has_error, source_output, _ = ApiRequest.get(
'/accounts/%s/sources/%s' %
Expand Down Expand Up @@ -2118,27 +2171,56 @@ def get_update_sample(*, account_id=None, source_id=None, sample_id=None):
dt = datetime.fromisoformat(sample_output['sample_datetime'])
# TODO: This might need some flask_babel calls, hmm...
sample_output['date'] = dt.strftime("%m/%d/%Y")
sample_output['time'] = dt.strftime("%I:%M %p")
sample_output['time'] = dt.strftime("%-I:%M %p")
else:
sample_output['date'] = ""
sample_output['time'] = ""

profile_has_samples = _check_if_source_has_samples(account_id, source_id)

return _render_with_defaults('sample.jinja2',
account_id=account_id,
source_id=source_id,
source_name=source_output['source_name'],
sample=sample_output,
sample_sites=sample_sites,
sample_sites_text=sample_site_translations,
is_environmental=is_environmental,
profile_has_samples=profile_has_samples)
need_reconsent_data = check_current_consent(
account_id, source_id, "data"
)
need_reconsent_biospecimen = check_current_consent(
account_id, source_id, "biospecimen"
)
return _render_with_defaults(
'sample.jinja2',
account_id=account_id,
source_id=source_id,
source_name=source_output['source_name'],
sample=sample_output,
sample_sites=sample_sites,
sample_sites_text=sample_site_translations,
is_environmental=is_environmental,
profile_has_samples=profile_has_samples,
need_reconsent_data=need_reconsent_data,
need_reconsent_biospecimen=need_reconsent_biospecimen
)


# TODO: guess we should also rewrite as ajax post for sample vue form?
@prerequisite([BIOSPECIMEN_PREREQS_MET])
def post_update_sample(*, account_id=None, source_id=None, sample_id=None):
# We hid the submit buttons for users who need to reconsent, but let's
# be defensive and make sure someone has current consent for both data
# and biospecimen. Admins are allowed to update samples regardless of
# consent status.
if session.get(ADMIN_MODE_KEY, False) is False:
need_reconsent_d = check_current_consent(
account_id, source_id, "data"
)
need_reconsent_b = check_current_consent(
account_id, source_id, "biospecimen"
)
if need_reconsent_d is True or need_reconsent_b is True:
# They've seen multiple messages telling them to reconsent, we'll
# dump them back at the My Kits page.
return redirect(
"/accounts/%s/sources/%s/kits" %
(account_id, source_id)
)

model = {}
for x in flask.request.form:
model[x] = flask.request.form[x]
Expand Down Expand Up @@ -2441,8 +2523,7 @@ def post_claim_samples(*, account_id=None, source_id=None, body=None,
account_id,
source_id,
"biospecimen",
sample_ids=sample_ids,
reconsent=True
sample_ids=sample_ids
)

has_error, survey_output, _ = ApiRequest.get(
Expand Down
20 changes: 20 additions & 0 deletions microsetta_interface/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,26 @@ paths:
'302':
description: Set session variable for declined reconsent and redirect to profile page

'/accounts/{account_id}/sources/{source_id}/reconsent/{consent_type}':
get:
operationId: microsetta_interface.implementation.get_reconsent
tags:
- Source
parameters:
- $ref: '#/components/parameters/account_id'
- $ref: '#/components/parameters/source_id'
- $ref: '#/components/parameters/consent_type'
responses:
'200':
description: Interface to agree to the current consent document
content:
text/html:
schema:
type: string
'302':
description: Redirect if the user doesn't need to reconsent


'/accounts/{account_id}/sources/{source_id}/consents':
get:
operationId: microsetta_interface.implementation.get_consents
Expand Down
49 changes: 49 additions & 0 deletions microsetta_interface/static/css/minimal_interface.css
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ a.breadcrumb-item-profile {
color: var(--tmi-red);
}

.btn-orange {
background: var(--tmi-orange);
border-radius: 50px;
font-weight: 700;
font-size: 14px;
line-height: 22px;
color: #ffffff;
}

.card-header {
background-color: #ffffff;
color: #222222;
Expand Down Expand Up @@ -380,6 +389,18 @@ p.tmi-content {
border-bottom: 0px;
}

.card-profile-alerts {
height: 270px;
background: linear-gradient(
to bottom,
var(--tmi-orange) 0px,
var(--tmi-orange) 100px,
white 100px,
white 270px
);
border-bottom: 0px;
}

.card-survey {
height: 310px;
background-color: white;
Expand Down Expand Up @@ -798,6 +819,30 @@ li.active-profile {
color: var(--tmi-gray-90);
}

.alert-consent > ul {
margin-bottom: 0px;
}

.alert-consent > ul > li > a {
color: var(--tmi-gray-90) !important;
}

.alert-updates {
background: var(--tmi-orange-bg);
border-left: 8px solid var(--tmi-orange);
border-radius: 12px;
color: var(--tmi-gray-90);
height: 48px;
width: 100%;
max-width: 260px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 14px;
line-height: 22px;
}

.blue-bg-card {
background: var(--tmi-blue-bg);
box-shadow: none;
Expand Down Expand Up @@ -1367,3 +1412,7 @@ input.barcode-checkbox[type=checkbox]:checked+label {
margin-left: 1rem;
margin-right: 1rem;
}

.orange-text {
color: var(--tmi-orange);
}
29 changes: 22 additions & 7 deletions microsetta_interface/templates/account_overview.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,28 @@
<div class="row mb-5">
{% for source in sources %}
<div class="col-md-4 mb-4">
<div class="card card-profile">
<img src="/static/img/profile_card_icon.png" class="mx-auto card-profile-icon">
<h2 class="centered profile-card-h2">{{ source.source_name|e}}</h2>
<a class="btn btn-blue-gradient centered" style="width: fit-content;" href="/accounts/{{account.account_id}}/sources/{{ source.source_id|e }}">
{{ _('Go to My Profile') }}
</a>
</div>
{% if source.alerts > 0 %}
<div class="card card-profile-alerts">
<img src="/static/img/profile_card_icon.png" class="mx-auto card-profile-icon">
<h2 class="profile-card-h2 mx-auto mt-2 mb-3">{{ source.source_name|e}}</h2>
<div class="alert-updates mx-auto mb-3">
{% if source.alerts > 1 %}
{{ _('You have') }}&nbsp;<span class="orange-text">{{ source.alerts }}</span>&nbsp;{{ _('updates') }}
{% else %}
{{ _('You have') }}&nbsp;<span class="orange-text">{{ source.alerts }}</span>&nbsp;{{ _('update') }}
{% endif %}
<a class="btn btn-orange ms-4" style="width: fit-content;" href="/accounts/{{account.account_id}}/sources/{{ source.source_id|e }}">View</a>
</div>
</div>
{% else %}
<div class="card card-profile">
<img src="/static/img/profile_card_icon.png" class="mx-auto card-profile-icon">
<h2 class="profile-card-h2 mx-auto mt-2 mb-4">{{ source.source_name|e}}</h2>
<a class="btn btn-blue-gradient mx-auto" style="width: fit-content;" href="/accounts/{{account.account_id}}/sources/{{ source.source_id|e }}">
{{ _('Go to My Profile') }}
</a>
</div>
{% endif %}
</div>
{% endfor %}
</div>
Expand Down
13 changes: 13 additions & 0 deletions microsetta_interface/templates/kits.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@
{{ _('Thank you for logging your sample information. It looks like you haven\'t updated your profile recently. Please review') }} <a href="/accounts/{{account_id}}/sources/{{source_id}}/take_survey?survey_template_id={{prompt_survey_id}}">{{ _('your survey responses') }}</a> {{ _('to ensure they\'re as current and complete as possible.') }}
</div>
{% endif %}
{% if profile_has_samples and (need_reconsent_data or need_reconsent_biospecimen) %}
<div id="consent_alert" class="alert alert-consent mt-4" role="alert">
{{ _('To update your existing samples or contribute new samples, please review the following:') }}<br />
<ul>
{% if need_reconsent_data %}
<li><a href="/accounts/{{account_id}}/sources/{{source_id}}/reconsent/data">{{ _('Consent to Act as a Research Subject') }}</a></li>
{% endif %}
{% if need_reconsent_biospecimen %}
<li><a href="/accounts/{{account_id}}/sources/{{source_id}}/reconsent/biospecimen">{{ _('Consent to Act as a Research Subject - Biospecimen and Future Use Research') }}</a></li>
{% endif %}
</ul>
</div>
{% endif %}
<div class="alert alert-primary alert-profile mt-4" role="alert">
{{ _('Click on the following link if you would like to contribute to receive a kit') }} - <a href="{{ fundrazr_url }}" target="_blank">{{ _('Get a Kit') }}</a>
</div>
Expand Down
12 changes: 10 additions & 2 deletions microsetta_interface/templates/new_participant.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,21 @@
{{ _('We\'ve made some changes to the project since you last logged in, including an update to our consent agreement. To proceed, please provide your updated consent.') }}
</div>
{% endif %}
{% if age_range != None %}
<input type="hidden" name="age-range" value="{{ age_range }}" />
{% if form_type == "biospecimen" %}
<div class="row mb-4">
<div class="col-12 biospecimen-alert">
{{ _('Signature and agreement of this consent form is required to process your sample(s).') }}
</div>
</div>
{% else %}
<div class="row mb-4">
<div class="col-12 biospecimen-alert">
{{ _('Signature and agreement of this consent form is required to update your information.') }}
</div>
</div>
{% endif %}
{% if age_range != None %}
<input type="hidden" name="age-range" value="{{ age_range }}" />
{% else %}
<div class="row">
<div class="col-12">
Expand Down
Loading

0 comments on commit 1ed2273

Please sign in to comment.