Skip to content

Commit

Permalink
IRONN-242 update adherence cache on any patient demographics changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pbugni committed Dec 11, 2024
1 parent d2c319d commit 7ca0ceb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 13 additions & 2 deletions portal/models/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from flask import current_app
from flask_babel import force_locale
from flask_login import login_manager
from werkzeug.exceptions import Unauthorized

from ..audit import auditable_event
Expand All @@ -30,11 +29,23 @@
qnr_csv_column_headers,
generate_qnr_csv,
)
from .research_study import BASE_RS_ID, EMPRO_RS_ID
from .research_study import BASE_RS_ID, EMPRO_RS_ID, ResearchStudy
from .role import ROLE, Role
from .user import User, UserRoles, patients_query
from .user_consent import consent_withdrawal_dates

def update_patient_adherence_data(patient_id):
"""Cache invalidation and force rebuild for given patient's adherence data
NB - any timeline or questionnaire response data changes are invalidated and
updated as part of `invalidate_users_QBT()`. This function is for edge cases
such as changing a user's study-id.
"""
patient = User.query.get(patient_id)
AdherenceData.query.filter(AdherenceData.patient_id).delete()
for rs_id in ResearchStudy.assigned_to(patient):
single_patient_adherence_data(patient_id=patient_id, research_study_id=rs_id)


def single_patient_adherence_data(patient_id, research_study_id):
"""Update any missing (from cache) adherence data for patient
Expand Down
8 changes: 6 additions & 2 deletions portal/views/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from ..database import db
from ..extensions import oauth
from ..models.reference import MissingReference
from ..models.reporting import update_patient_adherence_data
from ..models.user import current_user, get_user
from ..models.role import ROLE
from .crossdomain import crossdomain

demographics_api = Blueprint('demographics_api', __name__, url_prefix='/api')
Expand Down Expand Up @@ -176,7 +178,9 @@ def demographics_set(patient_id):
patient_id, json.dumps(request.json)), user_id=current_user().id,
subject_id=patient_id, context='user')

# update the patient_table cache with any change from above
patient_list_update_patient(patient_id)
# update the respective cache tables with any change from above
if patient.has_role(ROLE.PATIENT.value):
patient_list_update_patient(patient_id)
update_patient_adherence_data(patient_id)

return jsonify(patient.as_fhir(include_empties=False))

0 comments on commit 7ca0ceb

Please sign in to comment.