diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py index 36f2363b68fdfc73f7a7aef9e20fa62e2770873c..fb81d9624b40750c5f24315112d873516b2ff3ab 100644 --- a/smash/web/api_views/subject.py +++ b/smash/web/api_views/subject.py @@ -51,6 +51,7 @@ def get_subject_columns(request, subject_list_type): add_column(result, "Screening", "screening_number", study_subject_columns, "string_filter", study.columns) add_column(result, "First name", "first_name", subject_columns, "string_filter") add_column(result, "Last name", "last_name", subject_columns, "string_filter") + add_column(result, "Address", "address", subject_columns, "string_filter") add_column(result, "Social Security Number", "social_security_number", subject_columns, "string_filter") add_column(result, "Date of birth", "date_born", subject_columns, None) add_column(result, "Contact on", "datetime_contact_reminder", study_subject_columns, None, study.columns) @@ -110,6 +111,8 @@ def get_subjects_order(subjects_to_be_ordered, order_column, order_direction, co result = subjects_to_be_ordered.order_by(order_direction + 'subject__first_name') elif order_column == "last_name": result = subjects_to_be_ordered.order_by(order_direction + 'subject__last_name') + elif order_column == "address": + result = subjects_to_be_ordered.order_by(order_direction + 'subject__address') elif order_column == "nd_number": result = subjects_to_be_ordered.order_by(order_direction + 'nd_number') elif order_column == "referral": @@ -237,6 +240,8 @@ def get_subjects_filtered(subjects_to_be_filtered, filters): result = result.filter(subject__first_name__icontains=value) elif column == "last_name": result = result.filter(subject__last_name__icontains=value) + elif column == "address": + result = result.filter(subject__address__icontains=value) elif column == "nd_number": result = result.filter(nd_number__icontains=value) elif column == "referral": @@ -396,6 +401,7 @@ def serialize_subject(study_subject): result = { "first_name": study_subject.subject.first_name, "last_name": study_subject.subject.last_name, + "address": study_subject.subject.pretty_address(), "date_born": study_subject.subject.date_born, "datetime_contact_reminder": contact_reminder, "last_contact_attempt": last_contact_attempt_string, diff --git a/smash/web/models/subject.py b/smash/web/models/subject.py index 55afd8ba6b70406e163ee90d64227798ca4a52ee..b762bfe39be8df6f7275401d0498621532bc3d8a 100644 --- a/smash/web/models/subject.py +++ b/smash/web/models/subject.py @@ -102,6 +102,9 @@ class Subject(models.Model): editable=True ) + def pretty_address(self): + return u'{} ({}), {}. {}'.format(self.address, self.postal_code, self.city, self.country) + def mark_as_dead(self): self.dead = True self.finish_all_visits() diff --git a/smash/web/static/js/smash.js b/smash/web/static/js/smash.js index 9ae0968b16a23e70ce3aaf30d866b866c5dc9d58..2f2846523db2447089e98c1c7f08de6accf1aff3 100644 --- a/smash/web/static/js/smash.js +++ b/smash/web/static/js/smash.js @@ -128,7 +128,20 @@ function getColumns(columns, getSubjectEditUrl) { var result = []; for (var i = 0; i < columns.length; i++) { var columnRow = columns[i]; - if (columnRow.type === "edit") { + if (columnRow.type === "address"){ + + var renderFunction = (function () { + return function (data, type, row) { + return data; + }; + })(); + + var columnDef = createColumn(columnRow.type, columnRow.name, columnRow.filter, columnRow.visible, columnRow.sortable, renderFunction); + columnDef.className = 'subject-address'; + columnDef.width = '150px'; + result.push(columnDef); + + } else if (columnRow.type === "edit") { result.push(createColumn("id", columnRow.name, columnRow.filter, columnRow.visible, columnRow.sortable, function (data, type, row) { var url = getSubjectEditUrl(row.id.toString()); @@ -392,7 +405,6 @@ function createTable(params) { }); }); - $(function () { var columns = []; var columnDefs = []; @@ -403,6 +415,8 @@ function createTable(params) { "targets": i, "render": column.render, visible: column.visible, + className: column.className, + width: column.width, orderable: column.sortable }); } @@ -450,7 +464,7 @@ function createTable(params) { }); $('#table_filter').css("display", "null"); }); - $('#visible-column-checkboxes input').on('click', function (e) { + $(params.checkboxesElement).find('input').on('click', function (e) { var visible = $(this).is(":checked"); // Get the column API object diff --git a/smash/web/templates/subjects/index.html b/smash/web/templates/subjects/index.html index 6a1045c0fea313eef7ec81b06f7cbdc978a56750..cfe954bcc1251c81a64dffee7c12a18b62893bda 100644 --- a/smash/web/templates/subjects/index.html +++ b/smash/web/templates/subjects/index.html @@ -37,6 +37,9 @@ margin-top: 10px; text-align: left; } + td.subject-address{ + word-break: break-word; + } </style> {% endblock styles %}