From 07a663218b63908864f43af17b2e1bd7d9c37cd5 Mon Sep 17 00:00:00 2001 From: Paul Bugni Date: Tue, 19 Nov 2024 17:37:32 -0800 Subject: [PATCH] sort visits for select --- portal/views/patients.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/portal/views/patients.py b/portal/views/patients.py index 75b78e939..5a83f29ed 100644 --- a/portal/views/patients.py +++ b/portal/views/patients.py @@ -184,7 +184,11 @@ def requested_orgs(user, research_study_id): options.append({"action_state": [(state[0], _(state[0])) for state in distinct_action]}) distinct_visits = PatientList.query.distinct(PatientList.empro_visit).with_entities( PatientList.empro_visit) - options.append({"empro_visit": [(visit[0], translate_visit_name(visit[0])) for visit in distinct_visits]}) + sorted_visits = sorted( + [v[0] for v in distinct_visits if v[0]], + key=lambda x: (0 if not x.split()[-1].isdigit() else int(x.split()[-1])) + ) + options.append({"empro_visit": [(visit, translate_visit_name(visit)) for visit in sorted_visits]}) else: distinct_status = PatientList.query.distinct( PatientList.questionnaire_status).with_entities(PatientList.questionnaire_status) @@ -192,7 +196,11 @@ def requested_orgs(user, research_study_id): {"questionnaire_status": [(status[0], _(status[0])) for status in distinct_status]}) distinct_visits = PatientList.query.distinct(PatientList.visit).with_entities( PatientList.visit) - options.append({"visit": [(visit[0], translate_visit_name(visit[0])) for visit in distinct_visits]}) + sorted_visits = sorted( + [v[0] for v in distinct_visits if v[0]], + key=lambda x: (0 if not x.split()[-1].isdigit() else int(x.split()[-1])) + ) + options.append({"visit": [(visit, translate_visit_name(visit)) for visit in sorted_visits]}) viewable_orgs = requested_orgs(user, research_study_id) query = PatientList.query.filter(PatientList.org_id.in_(viewable_orgs))