Skip to content

Commit

Permalink
IRONN-264 visit_month was being cached in translated form.
Browse files Browse the repository at this point in the history
looking up visit_month now always returns english version, which may be cached.  `translate_visit_month()` used by front end where needed.
  • Loading branch information
pbugni committed Nov 20, 2024
1 parent f269a29 commit fc8f17f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions portal/models/qb_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions portal/models/questionnaire_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion portal/models/questionnaire_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
QuestionnaireBank,
QuestionnaireBankQuestionnaire,
trigger_date,
translate_visit_name,
visit_name,
)
from .research_data import ResearchData
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions portal/views/patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fc8f17f

Please sign in to comment.