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-242 update adherence cache on any patient demographics changes. #4427

Merged
merged 3 commits into from
Dec 12, 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
16 changes: 14 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,12 +29,25 @@
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))
Loading