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

IRONN-225 EMPRO month 12 expired vs. not available #4354

Merged
merged 12 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
63 changes: 63 additions & 0 deletions portal/migrations/versions/66368e673005_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""IRONN-225 update adherence data for expired EMPRO users

Revision ID: 66368e673005
Revises: d1f3ed8d16ef
Create Date: 2023-12-11 16:56:10.427854

"""
from alembic import op
from datetime import datetime
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker


# revision identifiers, used by Alembic.
revision = '66368e673005'
down_revision = 'd1f3ed8d16ef'

Session = sessionmaker()


def upgrade():
# IRONN-225 noted expired EMPRO users adherence data showed
# `not yet available`. Code corrected, need to force renewal
# for those affected.

bind = op.get_bind()
session = Session(bind=bind)

now = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
patient_ids = []
# get list of non-deleted users with a 12th month expiration
# that has already passed. (12 = baseline + zero-index 10)
for patient_id in session.execute(
"SELECT DISTINCT(user_id) FROM qb_timeline JOIN users"
" ON users.id = user_id WHERE deleted_id IS NULL"
" AND research_study_id = 1 AND qb_iteration = 10"
f" AND status = 'expired' AND at < '{now}'"):
patient_ids.append(patient_id[0])

# purge their respective rows from adherence cache, IFF status
# shows IRONN-225 symptom.
rs_visit = "1:Month 12"
for patient_id in patient_ids:
status = session.execute(
"SELECT data->>'status' FROM adherence_data WHERE"
f" patient_id = {patient_id} AND"
f" rs_id_visit = '{rs_visit}'"
).first()
if status and status[0] != "Not Yet Available":
continue

# purge the user's EMPRO adherence rows to force refresh
session.execute(
"DELETE FROM adherence_data WHERE"
f" patient_id = {patient_id} AND"
f" rs_id_visit like '1:%'"
)


def downgrade():
# No reasonable downgrade
pass

10 changes: 7 additions & 3 deletions portal/models/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ def empro_row_detail(row, ts_reporting):
# build up data until we find valid cache for patient's history
status = str(qb_stats.overall_status)
row = patient_data(patient)
row["status"] = status
if status == "Expired" and research_study_id == EMPRO_RS_ID:
row["status"] = "Not Yet Available"
else:
row["status"] = status
mcjustin marked this conversation as resolved.
Show resolved Hide resolved
# Expired status ambiguous for EMPRO - either not available
# due to complex business rules around start or walked off
# the end. Assume if consent + 1year > now, it's the former.
consent = datetime.strptime(row["consent"], "%d-%b-%Y %H:%M:%S")
if consent + timedelta(days=365) > as_of_date:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://promowiki.movember.com/pages/viewpage.action?pageId=72941826#SequencingofPROMs-EMPROQUESTIONNAIRE , the actual 12 month expiration date can be significantly later than this.

  1. "If the subject consents to the IRONMAN and EMPRO studies on the same day: the EMPRO questionnaire is made available for four weeks from the date the subject completes their baseline IRONMAN questionnaire". So, this cutoff date can be up to 4 weeks too early in this situation.
  2. "If the subject consents to the EMPRO study after consenting to the IRONMAN study... (and) If the subject consents to the EMPRO study more than four weeks after completing an IRONMAN questionnaire: The EMPRO questionnaires are made available for four weeks from the date the subject completes their next IRONMAN questionnaire" - this may be even longer than four weeks later, as I read it.

Am I reading this correctly? Would we report "Expired" to soon in these situations?

If so, can we look to the timeline for a more accurate date here? If not, we'll need to explain to PCCTC how to interpret this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yes, you are correct. i'll need to work that in, thanks for remembering this detail @mcjustin

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also of note, found in testing scenarios where row["consent"] == None need to account for this as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I read it, you've addressed this - thanks

row["status"] = "Not Yet Available"

if last_viable:
general_row_detail(row, patient, last_viable)
Expand Down