Skip to content

Commit

Permalink
card list template and unit tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed May 15, 2017
1 parent 5bf47a4 commit 6c10bab
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 4 deletions.
8 changes: 8 additions & 0 deletions opal/core/patient_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
46 changes: 46 additions & 0 deletions opal/templates/patient_lists/card_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% load forms %}
<div class="container content-offset">
<div class="panel panel-primary panel-container">
<div class="panel-heading">
<h2>
<i class="fa fa-user-md"></i>
[[ tag_display[currentTag] ]]
</h2>
</div>
<div class="panel-body">
<div class="row screen-only">
<form class="form-inline">
<div class="col-md-12">
{% include "patient_lists/partials/list_dropdown_menu.html" %}
<div class="form-group pull-right">
<label class="offset-right-5" for="listfilter">{% icon "fa-filter" %} Filter </label>
<input ui-event="{focus: 'focusOnQuery()', blur: 'blurOnQuery()'}" ng-model="query.hospital_number" type="text" class="form-control" id="listfilter" placeholder="Name or Hospital Num">
</div>
</div>
</form>
</div>

<div class="row">
<div class="col-md-8 col-md-push-2">
<div ng-repeat="row in rows" class="panel panel-default content-offset patient-row">
<a class="panel-link" href="{{ patient_list.card_link }}">
{% include patient_list.card_header_template %}
{% include patient_list.card_body_template %}
</a>
{% include patient_list.card_footer_template %}
</div>
</div>
</div>
<div class="empty-list" ng-hide="num_episodes > 0">
<p class="lead text-center">
There are no patients on this list.
</p>
<p class="lead text-center">
<span class="screen-only">
Would you like to <a href="/pathway/#/add_patient">add one</a>?
</span>
</p>
</div>
</div>
</div>
</div>
35 changes: 35 additions & 0 deletions opal/templates/patient_lists/partials/card_body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% load forms %}
<div class="panel-body">
<div class="row">
<div class="col-md-6">
{% for column in columns %}
{% if not forloop.counter0|divisibleby:2 %}
<h4><strong>
{% if column.icon %}
{% icon column.icon %}
{% endif %}
{{ column.title }}
</strong></h4>
<p ng-repeat="item in row.diagnosis">
{% include column.detail_template_path %}
</p>
{% endif %}
{% endfor %}
</div>
<div class="col-md-6">
{% for column in columns %}
{% if forloop.counter0|divisibleby:2 %}
<h4><strong>
{% if column.icon %}
{% icon column.icon %}
{% endif %}
{{ column.title }}
</strong></h4>
<p ng-repeat="item in row.diagnosis">
{% include column.detail_template_path %}
</p>
{% endif %}
{% endfor %}
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions opal/templates/patient_lists/partials/card_footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="panel-footer">
<div class="row">
</div>
</div>
16 changes: 16 additions & 0 deletions opal/templates/patient_lists/partials/card_header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="panel-heading">
<div class="row">
<div class="col-sm-12">
<h3><i class="fa fa-user"></i>
[[ row.demographics[0].first_name ]] [[ row.demographics[0].surname ]] [[ row.demographics[0].hospital_number ]]
<small>
[[ row.demographics[0].date_of_birth|shortDate ]]
<span ng-show="row.demographics[0].date_of_birth">
([[ row.demographics[0].date_of_birth | age ]])
</span>
</small>
</h3>
</div>

</div>
</div>
21 changes: 21 additions & 0 deletions opal/templates/patient_lists/partials/list_dropdown_menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% load forms %}
<h1 >
<div class="btn-group pull-left" uib-dropdown is-open="status.isopen">
<button type="button" class="btn btn-secondary" uib-dropdown-toggle ng-disabled="disabled" id="list-dropdown">
<i class="fa fa-user-md"></i>
{{ patient_list.display_name }}
<i class="fa fa-angle-down"></i>
</button>
<ul class="uib-dropdown-menu slides" role="menu" aria-labelledby="list-dropdown">
{% for list in lists %}
{% if list.get_slug != list_slug %}
<li>
<a href="#/list/{{ list.get_slug }}">
{{ list.display_name }}
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</h1>
84 changes: 80 additions & 4 deletions opal/tests/test_patient_lists.py
Original file line number Diff line number Diff line change
@@ -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
)

"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -240,6 +265,7 @@ def test_order_respected_by_list(self):
TaggingTestPatientList,
TaggingTestSameTagPatientList,
InvisibleList,
TestCardList
]
self.assertEqual(expected, list(PatientList.list()))

Expand Down Expand Up @@ -362,14 +388,64 @@ 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))

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):
Expand Down

0 comments on commit 6c10bab

Please sign in to comment.