diff --git a/opal/core/patient_lists.py b/opal/core/patient_lists.py index a265e60fd..dee42f126 100644 --- a/opal/core/patient_lists.py +++ b/opal/core/patient_lists.py @@ -259,6 +259,14 @@ def visible_to(klass, user): return False +class CardListPatientList(PatientList, utils.AbstractBase): + card_header_template = "patient_lists/partials/card_header.html" + card_body_template = "patient_lists/partials/card_body.html" + card_footer_template = "patient_lists/partials/card_footer.html" + card_link = "[[ '/#/patient/' + row.demographics[0].patient_id ]]" + template_name = "patient_lists/card_list.html" + + """ Begin Definitions of Patient List App Metadata entries """ diff --git a/opal/templates/patient_lists/card_list.html b/opal/templates/patient_lists/card_list.html new file mode 100644 index 000000000..4158028b4 --- /dev/null +++ b/opal/templates/patient_lists/card_list.html @@ -0,0 +1,46 @@ +{% load forms %} +
+
+
+

+ + [[ tag_display[currentTag] ]] +

+
+
+
+
+
+ {% include "patient_lists/partials/list_dropdown_menu.html" %} +
+ + +
+
+
+
+ + +
+

+ There are no patients on this list. +

+

+ + Would you like to add one? + +

+
+
+
+
diff --git a/opal/templates/patient_lists/partials/card_body.html b/opal/templates/patient_lists/partials/card_body.html new file mode 100644 index 000000000..a03525407 --- /dev/null +++ b/opal/templates/patient_lists/partials/card_body.html @@ -0,0 +1,35 @@ +{% load forms %} +
+
+
+ {% for column in columns %} + {% if not forloop.counter0|divisibleby:2 %} +

+ {% if column.icon %} + {% icon column.icon %} + {% endif %} + {{ column.title }} +

+

+ {% include column.detail_template_path %} +

+ {% endif %} + {% endfor %} +
+
+ {% for column in columns %} + {% if forloop.counter0|divisibleby:2 %} +

+ {% if column.icon %} + {% icon column.icon %} + {% endif %} + {{ column.title }} +

+

+ {% include column.detail_template_path %} +

+ {% endif %} + {% endfor %} +
+
+
diff --git a/opal/templates/patient_lists/partials/card_footer.html b/opal/templates/patient_lists/partials/card_footer.html new file mode 100644 index 000000000..f948822fd --- /dev/null +++ b/opal/templates/patient_lists/partials/card_footer.html @@ -0,0 +1,4 @@ + diff --git a/opal/templates/patient_lists/partials/card_header.html b/opal/templates/patient_lists/partials/card_header.html new file mode 100644 index 000000000..966ee078d --- /dev/null +++ b/opal/templates/patient_lists/partials/card_header.html @@ -0,0 +1,16 @@ +
+
+
+

+ [[ row.demographics[0].first_name ]] [[ row.demographics[0].surname ]] [[ row.demographics[0].hospital_number ]] + + [[ row.demographics[0].date_of_birth|shortDate ]] + + ([[ row.demographics[0].date_of_birth | age ]]) + + +

+
+ +
+
diff --git a/opal/templates/patient_lists/partials/list_dropdown_menu.html b/opal/templates/patient_lists/partials/list_dropdown_menu.html new file mode 100644 index 000000000..a68ba65af --- /dev/null +++ b/opal/templates/patient_lists/partials/list_dropdown_menu.html @@ -0,0 +1,21 @@ +{% load forms %} +

+
+ + +
+

diff --git a/opal/tests/test_patient_lists.py b/opal/tests/test_patient_lists.py index 2667d333c..d18d4a9b4 100644 --- a/opal/tests/test_patient_lists.py +++ b/opal/tests/test_patient_lists.py @@ -1,18 +1,19 @@ """ Unittests for opal.core.patient_lists """ +from django.core.urlresolvers import reverse from django.contrib.auth.models import User from mock import MagicMock, PropertyMock, patch from opal.core import exceptions from opal.tests import models -from opal.models import Episode, Patient, UserProfile +from opal.models import Episode, Patient, UserProfile, Demographics from opal.core.test import OpalTestCase from opal.core import patient_lists from opal.core.patient_lists import ( PatientList, TaggedPatientList, TabbedPatientListGroup, - PatientListComparatorMetadata + PatientListComparatorMetadata, CardListPatientList ) """ @@ -80,10 +81,34 @@ class TestTabbedPatientListGroup(TabbedPatientListGroup): class TestEmptyTabbedPatientListGroup(TabbedPatientListGroup): member_lists = [InvisibleList] + +class TestCardList(CardListPatientList): + slug = "some_card_list" + order = 105 + schema = [ + models.Demographics, + ] + + @property + def card_header_template(self): + return CardListPatientList.card_header_template + + @property + def card_body_template(self): + return CardListPatientList.card_body_template + + @property + def card_footer_template(self): + return CardListPatientList.card_footer_template + + @property + def card_link(self): + return CardListPatientList.card_link + + """ Begin Tests """ - class ColumnTestCase(OpalTestCase): def test_set_non_inferred_attributes(self): @@ -240,6 +265,7 @@ def test_order_respected_by_list(self): TaggingTestPatientList, TaggingTestSameTagPatientList, InvisibleList, + TestCardList ] self.assertEqual(expected, list(PatientList.list())) @@ -362,7 +388,6 @@ def test_for_list_raises_if_non_list_passed(self): with self.assertRaises(ValueError): TabbedPatientListGroup.for_list(OpalTestCase) - def test_visible_to(self): self.assertTrue(TestTabbedPatientListGroup.visible_to(self.user)) @@ -370,6 +395,57 @@ def test_invisible_to_if_member_lists_for_user_empty(self): self.assertFalse(TestEmptyTabbedPatientListGroup.visible_to(self.user)) +class CardListGroupTestCase(OpalTestCase): + + def setUp(self): + self.assertTrue( + self.client.login( + username=self.user.username, password=self.PASSWORD + ) + ) + self.url = reverse( + "patient_list_template_view", kwargs=dict(slug="some_card_list") + ) + + def test_vanilla_get(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + + @patch( + "opal.tests.test_patient_lists.TestCardList.card_footer_template", + new_callable=PropertyMock + ) + @patch( + "opal.tests.test_patient_lists.TestCardList.card_body_template", + new_callable=PropertyMock + ) + @patch( + "opal.tests.test_patient_lists.TestCardList.card_header_template", + new_callable=PropertyMock + ) + @patch( + "opal.tests.test_patient_lists.TestCardList.card_link", + new_callable=PropertyMock + ) + def test_get_template_columns(self, card_link, header, body, footer): + # make sure we include all the constituents of the patient list + self.client.get(self.url) + header.return_value = CardListPatientList.card_header_template + body.return_value = CardListPatientList.card_body_template + card_link.return_value = CardListPatientList.card_link + header.assert_called_once() + body.assert_called_once() + footer.assert_called_once() + card_link.assert_called_once() + + @patch("opal.tests.models.Demographics.get_display_template") + def test_get_card_body(self, display_template): + # make sure that the schema is called + display_template.return_value = Demographics.get_display_template() + self.client.get(self.url) + display_template.assert_called_once() + + class FirstListMetadataTestCase(OpalTestCase): def test_first_list_slug(self):