From fc8f17f2fa20e83680b3f241329bef975e800dd0 Mon Sep 17 00:00:00 2001 From: Paul Bugni Date: Tue, 19 Nov 2024 16:01:46 -0800 Subject: [PATCH] IRONN-264 visit_month was being cached in translated form. looking up visit_month now always returns english version, which may be cached. `translate_visit_month()` used by front end where needed. --- portal/models/qb_timeline.py | 4 ++-- portal/models/questionnaire_bank.py | 22 ++++++++++++++++++---- portal/models/questionnaire_response.py | 3 ++- portal/views/patients.py | 5 +++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/portal/models/qb_timeline.py b/portal/models/qb_timeline.py index a35d04635..81c129222 100644 --- a/portal/models/qb_timeline.py +++ b/portal/models/qb_timeline.py @@ -1316,8 +1316,8 @@ def qb_status_visit_name(user_id, research_study_id, as_of_date): :returns: dictionary with key/values for: status: string like 'expired' - visit_name: for the period, i.e. '3 months' - action_state: 'not applicable', or status of follow up action + visit_name: for the period, i.e. '3 months'. ALWAYS in english, clients must translate + action_state: 'not applicable', or status of follow-up action """ from .research_study import EMPRO_RS_ID diff --git a/portal/models/questionnaire_bank.py b/portal/models/questionnaire_bank.py index c964f3c82..6a0e2822b 100644 --- a/portal/models/questionnaire_bank.py +++ b/portal/models/questionnaire_bank.py @@ -592,6 +592,10 @@ def qbs_by_rp(rp_id, classification): def visit_name(qbd): + """returns string repr of visit, i.e. 'Month 3' or 'Baseline' + + NB - only returns english version. See `translate_visit_name()` + """ from .research_study import ( EMPRO_RS_ID, research_study_id_from_questionnaire, @@ -617,12 +621,22 @@ def visit_name(qbd): clm += (clrd.years * 12) if clrd.years else 0 total = clm * qbd.iteration + sm if rs_id == EMPRO_RS_ID: - return _('Month %(month_total)d', month_total=total+1) - return _('Month %(month_total)d', month_total=total) + return f'Month {total+1}' + return f'Month {total}' if rs_id == EMPRO_RS_ID: - return _('Month %(month_total)d', month_total=1) - return _(qbd.questionnaire_bank.classification.title()) + return 'Month 1' + return qbd.questionnaire_bank.classification.title() + + +def translate_visit_name(visit_name): + """parse the english version of visit name for front end translation needs""" + if not visit_name: + return visit_name + if visit_name.startswith('Month '): + number = int(visit_name[6:]) + return _('Month %(month_total)d', month_total=number) + return _(visit_name) def add_static_questionnaire_bank(): diff --git a/portal/models/questionnaire_response.py b/portal/models/questionnaire_response.py index bf52df00b..85bfe34fd 100644 --- a/portal/models/questionnaire_response.py +++ b/portal/models/questionnaire_response.py @@ -28,6 +28,7 @@ QuestionnaireBank, QuestionnaireBankQuestionnaire, trigger_date, + translate_visit_name, visit_name, ) from .research_data import ResearchData @@ -401,7 +402,7 @@ def extensions(self): relative_start=None, iteration=self.qb_iteration, recur_id=recur_id, qb_id=self.questionnaire_bank_id) results.append({ - 'visit_name': visit_name(qbd), + 'visit_name': translate_visit_name(visit_name(qbd)), 'url': TRUENTH_VISIT_NAME_EXTENSION}) expires_at = expires(self.subject_id, qbd) diff --git a/portal/views/patients.py b/portal/views/patients.py index 3d1d97b4e..5d07c72b2 100644 --- a/portal/views/patients.py +++ b/portal/views/patients.py @@ -17,6 +17,7 @@ from ..models.intervention import Intervention from ..models.organization import Organization, OrgTree from ..models.patient_list import PatientList +from ..models.questionnaire_bank import translate_visit_name from ..models.qb_status import patient_research_study_status from ..models.role import ROLE from ..models.research_study import EMPRO_RS_ID, ResearchStudy @@ -222,8 +223,8 @@ def requested_orgs(user, research_study_id): "questionnaire_status": _(row.questionnaire_status), "empro_status": _(row.empro_status), "action_state": _(row.action_state), - "visit": row.visit, - "empro_visit": row.empro_visit, + "visit": translate_visit_name(row.visit), + "empro_visit": translate_visit_name(row.empro_visit), "study_id": row.study_id, "consentdate": row.consentdate, "empro_consentdate": row.empro_consentdate,