Skip to content

Commit

Permalink
Merge cfdbed6 into f9c2f43
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Oct 1, 2018
2 parents f9c2f43 + cfdbed6 commit 13932b4
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 27 deletions.
32 changes: 32 additions & 0 deletions apps/tb/data/lookuplists/tbstageoptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"tbstageoptions": [
{
"synonyms": [],
"name": "New Referral"
},
{
"synonyms": [],
"name": "Assessed"
},
{
"synonyms": [],
"name": "Active TB Treatment"
},
{
"synonyms": [],
"name": "Latent TB Treatment"
},
{
"synonyms": [],
"name": "NTM Treatment"
},
{
"synonyms": [],
"name": "Under Investigation"
},
{
"synonyms": [],
"name": "Discharged"
}
]
}
57 changes: 57 additions & 0 deletions apps/tb/migrations/0035_auto_20181001_1544.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-10-01 15:44
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import opal.models


class Migration(migrations.Migration):

dependencies = [
('opal', '0035_auto_20180806_1150'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('tb', '0034_auto_20180824_1925'),
]

operations = [
migrations.CreateModel(
name='TBStage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(blank=True, null=True)),
('updated', models.DateTimeField(blank=True, null=True)),
('consistency_token', models.CharField(max_length=8)),
('stage_ft', models.CharField(blank=True, default=b'', max_length=255, null=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_tb_tbstage_subrecords', to=settings.AUTH_USER_MODEL)),
('episode', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='opal.Episode')),
],
options={
'abstract': False,
},
bases=(opal.models.UpdatesFromDictMixin, opal.models.ToDictMixin, models.Model),
),
migrations.CreateModel(
name='TBStageOptions',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
],
options={
'ordering': ['name'],
'abstract': False,
},
),
migrations.AddField(
model_name='tbstage',
name='stage_fk',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='tb.TBStageOptions'),
),
migrations.AddField(
model_name='tbstage',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_tb_tbstage_subrecords', to=settings.AUTH_USER_MODEL),
),
]
19 changes: 19 additions & 0 deletions apps/tb/migrations/0036_auto_20181001_1559.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-10-01 15:59
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('tb', '0035_auto_20181001_1544'),
]

operations = [
migrations.AlterModelOptions(
name='tbstage',
options={'verbose_name': 'Current Status'},
),
]
15 changes: 15 additions & 0 deletions apps/tb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,18 @@ def update_from_dict(self, *args, **kwargs):
class Meta:
verbose_name = "Appointments"
ordering = ["-start"]


class TBStageOptions(lookuplists.LookupList):
pass


class TBStage(models.EpisodeSubrecord):
_is_singleton = True
_icon = "fa fa-tasks"
FIRST_STAGE = "New Referral"

class Meta:
verbose_name = "Current Status"

stage = ForeignKeyOrFreeText(TBStageOptions)
10 changes: 7 additions & 3 deletions apps/tb/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

from apps.tb.patient_lists import TbPatientList
from apps.tb import models as tb_models
from intrahospital_api import constants


class AddTbPatientPathway(AddPatientPathway):
display_name = "Add TB Patient"
display_name = "Add Patient"
slug = 'add_tb_patient'

steps = (
Expand All @@ -30,14 +31,17 @@ class AddTbPatientPathway(AddPatientPathway):

@transaction.atomic
def save(self, data, user, patient=None, episode=None):
patient, episode = super(AddTbPatientPathway, self).save(
saved_patient, episode = super(AddTbPatientPathway, self).save(
data, user=user, patient=patient, episode=episode
)

episode.set_tag_names([TbPatientList.tag], user)
episode.category_name = "TB"
episode.stage = "New Referral"
episode.save()
tb_stage = episode.tbstage_set.first()
tb_stage.stage=tb_models.TBStage.FIRST_STAGE
tb_stage.save()

# if the patient its a new patient and we have
# got their demographics from the upstream api service
Expand All @@ -47,7 +51,7 @@ def save(self, data, user, patient=None, episode=None):
if demo_system == constants.EXTERNAL_SYSTEM:
loader.load_patient(saved_patient)

return patient, episode
return saved_patient, episode


class NewSubrecordStep(HelpTextStep):
Expand Down
4 changes: 2 additions & 2 deletions apps/tb/templates/detail/tb.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ <h3>
</div>
</div>
{% endif %}
{% record_panel models.TBStage %}
<div class="panel panel-default">
<div class="panel-heading">
<h3>
Imaging
<i class="fa fa-file-image-o"></i> Imaging
</h3>
</div>
<div class="panel-body">
<a target="_blank" href="http://freenet/carestream/?pid=[[ episode.demographics[0].hospital_number ]]">PACS</a>
</div>
</div>
{% include 'tb/obs_panel.html' %}
{% record_panel models.TBAppointment editable=0 %}
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions apps/tb/templates/forms/tb_stage_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load forms %}
{% select label="Current State" field="TBStage.stage" %}
4 changes: 4 additions & 0 deletions apps/tb/templates/records/tb_stage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span ng-show="item.stage">
[[ item.stage ]]
<br />
</span>
15 changes: 9 additions & 6 deletions elcid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apps.tb import constants as tb_constants


class NotTbMenuItem(menus.MenuItem):
class StandardAddPatientMenuItem(menus.MenuItem):
def for_user(self, user):
from opal.models import UserProfile
if user.is_superuser:
Expand All @@ -18,7 +18,8 @@ def for_user(self, user):
).exists()


not_tb_menu_item = NotTbMenuItem(
# ie, not the TB one
standard_add_patient_menu_item = StandardAddPatientMenuItem(
href='/pathway/#/add_patient',
display='Add Patient',
icon='fa fa-plus',
Expand Down Expand Up @@ -72,9 +73,11 @@ class Application(application.OpalApplication):
}

@classmethod
def get_menu_items(self, user):
menu_items = super(Application, self).get_menu_items(user)
if not_tb_menu_item.for_user(user):
menu_items.append(not_tb_menu_item)
def get_menu_items(cls, user):
menu_items = super(Application, cls).get_menu_items(user)
if standard_add_patient_menu_item.for_user(user):
menu_items.append(standard_add_patient_menu_item)
else:
menu_items = [i for i in menu_items if not i.href == "/#/list/"]

return menu_items
6 changes: 5 additions & 1 deletion elcid/templates/partials/_no_search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
We couldn't find any results for your search.
</p>
<center>
<a href="/pathway/#/add_patient" class="btn btn-primary btn-lg">{% icon 'fa-plus' %} Add a patient</a>
{% if permissions.tb_professional %}
<a href="/pathway/#/add_tb_patient" class="btn btn-primary btn-lg">{% icon 'fa-plus' %} Add a patient</a>
{% else %}
<a href="/pathway/#/add_patient" class="btn btn-primary btn-lg">{% icon 'fa-plus' %} Add a patient</a>
{% endif %}
</center>
</div>
</div>
47 changes: 32 additions & 15 deletions elcid/test/test_application.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
from django.contrib.auth.models import User
from opal.core.test import OpalTestCase
from opal import models as opal_models
from elcid import Application
from apps.tb import constants as tb_constants


class ApplicationTestCase(OpalTestCase):
PASSWORD = "password"

def setUp(self):
super(ApplicationTestCase, self).setUp()
self.user.is_superuser = False
self.user.save()
normal_user = User.objects.create(username="normal")
normal_user.set_password(self.PASSWORD)
normal_user.save()
self.normal_user = normal_user

tb_user = User.objects.create(username="tb")
tb_user.set_password(self.PASSWORD)
tb_user.save()
opal_models.UserProfile.objects.create(user=tb_user)
tb_user.profile.roles.create(
name=tb_constants.TB_ROLE
)
self.tb_user = tb_user

super_user = User.objects.create(username="super")
super_user.set_password(self.PASSWORD)
super_user.is_superuser = True
super_user.save()

self.super_user = super_user

def test_get_menu_items_superuser(self):
self.user.is_superuser = True
self.user.save()
menu_items = Application.get_menu_items(self.user)
menu_items = Application.get_menu_items(self.super_user)
expected_hrefs = [menu_item.href for menu_item in menu_items]
self.assertIn("/pathway/#/add_patient", expected_hrefs)
self.assertIn("/#/list/", expected_hrefs)

def test_get_menu_items_tb(self):
self.user.profile.roles.create(
name=tb_constants.TB_ROLE
)
menu_items = Application.get_menu_items(self.user)
def test_get_menu_items_for_tb_user(self):
menu_items = Application.get_menu_items(self.tb_user)
expected_hrefs = [menu_item.href for menu_item in menu_items]
self.assertNotIn("/pathway/#/add_patient", expected_hrefs)
self.assertNotIn("/#/list/", expected_hrefs)

def test_get_menu_items_not_tb(self):
self.user.profile.roles.create(
name=tb_constants.TB_ROLE
).delete()
menu_items = Application.get_menu_items(self.user)
def test_get_menu_items_for_normal_user(self):
menu_items = Application.get_menu_items(self.normal_user)
expected_hrefs = [menu_item.href for menu_item in menu_items]
self.assertIn("/pathway/#/add_patient", expected_hrefs)
self.assertIn("/#/list/", expected_hrefs)

def test_make_sure_we_dont_change_a_global_object(self):
# make sure we don't change the list as it appears on
Expand Down

0 comments on commit 13932b4

Please sign in to comment.