From 86ec4d3de49f251fca1fb40aaec58893e6905dbe Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 4 Dec 2017 17:29:15 +0100 Subject: [PATCH] possibility to filter and sort by flying team location added --- smash/web/api_views/subject.py | 10 ++++++++++ smash/web/static/js/subject.js | 18 +++++++++++++++++- smash/web/templates/subjects/index.html | 1 + smash/web/tests/api_views/test_subject.py | 11 ++++++++++- smash/web/tests/functions.py | 2 +- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py index 7e043275..94785aef 100644 --- a/smash/web/api_views/subject.py +++ b/smash/web/api_views/subject.py @@ -71,6 +71,8 @@ def get_subject_columns(request, subject_list_type): add_column(result, "Last contact attempt", "last_contact_attempt", study_subject_list, None) add_column(result, "Referred by", "referral", study_subject_columns, "string_filter", study.columns) add_column(result, "Location", "default_location", study_subject_columns, "location_filter", study.columns) + add_column(result, "Flying team location", "flying_team", study_subject_columns, "flying_team_filter", + study.columns) add_column(result, "Deceased", "dead", subject_columns, "yes_no_filter") add_column(result, "Resigned", "resigned", study_subject_columns, "yes_no_filter", study.columns) add_column(result, "Postponed", "postponed", study_subject_columns, "yes_no_filter", study.columns) @@ -125,6 +127,8 @@ def get_subjects_order(subjects_to_be_ordered, order_column, order_direction): result = subjects_to_be_ordered.order_by(order_direction + 'screening_number') elif order_column == "default_location": result = subjects_to_be_ordered.order_by(order_direction + 'default_location') + elif order_column == "flying_team": + result = subjects_to_be_ordered.order_by(order_direction + 'flying_team') elif order_column == "dead": result = subjects_to_be_ordered.order_by(order_direction + 'subject__dead') elif order_column == "resigned": @@ -243,6 +247,8 @@ def get_subjects_filtered(subjects_to_be_filtered, filters): result = result.filter(information_sent=(value == "true")) elif column == "default_location": result = result.filter(default_location=value) + elif column == "flying_team": + result = result.filter(flying_team=value) elif column == "type": result = result.filter(type=value) elif str(column).startswith("visit_"): @@ -328,6 +334,9 @@ def serialize_subject(study_subject): location = "" if study_subject.default_location is not None: location = study_subject.default_location.name + flying_team = "" + if study_subject.flying_team is not None: + flying_team = unicode(study_subject.flying_team) visits = Visit.objects.filter(subject=study_subject).order_by('visit_number') serialized_visits = [] for visit in visits: @@ -377,6 +386,7 @@ def serialize_subject(study_subject): "screening_number": study_subject.screening_number, "referral": study_subject.referral, "default_location": location, + "flying_team": flying_team, "dead": get_yes_no(study_subject.subject.dead), "resigned": get_yes_no(study_subject.resigned), "postponed": get_yes_no(study_subject.postponed), diff --git a/smash/web/static/js/subject.js b/smash/web/static/js/subject.js index d6f5ac20..585d1b9f 100644 --- a/smash/web/static/js/subject.js +++ b/smash/web/static/js/subject.js @@ -128,9 +128,9 @@ function createVisibilityCheckboxes(checkboxesElement, columns) { function createSubjectsTable(params) { var tableElement = params.tableElement; var worker_locations = params.worker_locations; - var getSubjectEditUrl = params.getSubjectEditUrl; var subject_types_url = params.subject_types_url; var locations_url = params.locations_url; + var flying_teams_url = params.flying_teams_url; var subjects_url = params.subjects_url; var columnsDefinition = params.columns; @@ -173,8 +173,24 @@ function createSubjectsTable(params) { select.val(worker_locations[0].id); } }); + }); + $(tableElement).find('tfoot div[name="flying_team_filter"]').each(function () { + var obj = $(this); + obj.html('<select style="width:80px"><option value selected="selected">---</option></select>'); + var select = $('select', obj); + $.get(flying_teams_url, function (data) { + $.each(data.flying_teams, function (index, flying_team) { + select.append('<option value="' + flying_team.id + '">' + flying_team.name + '</option>'); + }); + if (worker_locations.length === 1) { + select.val(worker_locations[0].id); + } + }); }); + + + $(tableElement).find('tfoot div[name="type_filter"]').each(function () { var obj = $(this); obj.html('<select style="width:80px"><option value selected="selected">---</option></select>'); diff --git a/smash/web/templates/subjects/index.html b/smash/web/templates/subjects/index.html index 2c39cc33..b3b4aaa0 100644 --- a/smash/web/templates/subjects/index.html +++ b/smash/web/templates/subjects/index.html @@ -58,6 +58,7 @@ subject_types_url: "{% url 'web.api.subject_types' %}", locations_url: "{% url 'web.api.locations' %}", subjects_url: "{% url 'web.api.subjects' list_type %}", + flying_teams_url: "{% url 'web.api.flying_teams' %}", tableElement: document.getElementById("table"), columns: getColumns(data.columns, getSubjectEditUrl), checkboxesElement: document.getElementById("visible-column-checkboxes") diff --git a/smash/web/tests/api_views/test_subject.py b/smash/web/tests/api_views/test_subject.py index c16d85bb..0cfe69f5 100644 --- a/smash/web/tests/api_views/test_subject.py +++ b/smash/web/tests/api_views/test_subject.py @@ -14,7 +14,7 @@ from web.models.constants import GLOBAL_STUDY_ID from web.models.study_subject_list import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT, \ StudySubjectList from web.tests.functions import create_study_subject, create_worker, create_get_suffix, create_visit, \ - create_appointment, create_empty_study_columns, create_contact_attempt + create_appointment, create_empty_study_columns, create_contact_attempt, create_flying_team from web.views.notifications import get_today_midnight_date logger = logging.getLogger(__name__) @@ -207,6 +207,13 @@ class TestApi(TestCase): self.check_subject_ordered("default_location", [subject]) + def test_subjects_sort_flying_team(self): + subject = self.study_subject + subject.flying_team = create_flying_team() + subject.save() + + self.check_subject_ordered("flying_team", [subject]) + def test_subjects_sort_screening_number(self): subject = self.study_subject subject.screening_number = "PPP" @@ -357,6 +364,8 @@ class TestApi(TestCase): def test_serialize_subject(self): study_subject = self.study_subject study_subject.subject.dead = True + study_subject.flying_team = create_flying_team() + study_subject.datetime_contact_reminder = get_today_midnight_date() create_contact_attempt(subject=study_subject) create_visit(subject=study_subject) diff --git a/smash/web/tests/functions.py b/smash/web/tests/functions.py index b7089c3b..05db98ce 100644 --- a/smash/web/tests/functions.py +++ b/smash/web/tests/functions.py @@ -214,7 +214,7 @@ def create_configuration_item(): def create_flying_team(place=None): if place is None: - place = "CHEM" + place = "CHEM " result = FlyingTeam.objects.create(place=place) return result -- GitLab