Skip to content

Commit

Permalink
Merge pull request #661 from openhealthcare/660-labs-module-move
Browse files Browse the repository at this point in the history
moves the lab module accross from a plugin to part of the application…
  • Loading branch information
davidmiller committed Jan 27, 2019
2 parents a627818 + 00bb8e5 commit 93fe1c2
Show file tree
Hide file tree
Showing 42 changed files with 2,144 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source =
elcid
intrahospital_api
lab

omit =
*/migrations/*
Expand All @@ -11,6 +12,7 @@ omit =
elcid/settings.py
elcid/local_settings.py
elcid/templates/acceptance/*
lab/tests/*


[report]
Expand Down
2 changes: 1 addition & 1 deletion elcid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@


if 'test' in sys.argv:
INSTALLED_APPS += ('opal.tests',)
INSTALLED_APPS += ('lab.tests',)
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
)
Expand Down
2 changes: 1 addition & 1 deletion intrahospital_api/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_contains_empty_patient_subrecords(self):
patient, episode = self.new_patient_and_episode_please()
result = api.patient_to_dict(patient, self.user)
self.assertEqual(
result["house_owner"], []
result["lab_test"], []
)

@mock.patch("intrahospital_api.api.patient_to_dict")
Expand Down
70 changes: 34 additions & 36 deletions intrahospital_api/test/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,42 +179,6 @@ def test_log_errors(self, err):
err.assert_called_once_with("blah")


class AnyLoadsRunningTestCase(ApiTestCase):
def setUp(self):
super(AnyLoadsRunningTestCase, self).setUp()
self.patient, _ = self.new_patient_and_episode_please()

def test_any_loads_running_initial_patient_load(self):
imodels.InitialPatientLoad.objects.create(
state=imodels.InitialPatientLoad.RUNNING,
patient=self.patient,
started=timezone.now()
)
self.assertTrue(loader.any_loads_running())

def test_any_loads_running_batch_patient_load(self):
imodels.BatchPatientLoad.objects.create(
state=imodels.BatchPatientLoad.RUNNING,
started=timezone.now()
)
self.assertTrue(loader.any_loads_running())

def test_any_loads_running_none(self):
self.assertFalse(loader.any_loads_running())

def test_any_loads_running_false(self):
imodels.InitialPatientLoad.objects.create(
state=imodels.InitialPatientLoad.SUCCESS,
patient=self.patient,
started=timezone.now()
)
imodels.BatchPatientLoad.objects.create(
state=imodels.BatchPatientLoad.SUCCESS,
started=timezone.now()
)
self.assertFalse(loader.any_loads_running())


class LoadDemographicsTestCase(ApiTestCase):

@mock.patch.object(loader.api, 'demographics')
Expand Down Expand Up @@ -614,3 +578,37 @@ def test_update_patient_from_batch_integration(self):
self.assertEqual(
observation["result"], "Positive"
)


class AnyLoadsRunningTestCase(ApiTestCase):
def test_any_loads_running_initial_patient_load(self):
patient, _ = self.new_patient_and_episode_please()
imodels.InitialPatientLoad.objects.create(
state=imodels.InitialPatientLoad.RUNNING,
patient=patient,
started=timezone.now()
)
self.assertTrue(loader.any_loads_running())

def test_any_loads_running_batch_patient_load(self):
imodels.BatchPatientLoad.objects.create(
state=imodels.BatchPatientLoad.RUNNING,
started=timezone.now()
)
self.assertTrue(loader.any_loads_running())

def test_any_loads_running_none(self):
self.assertFalse(loader.any_loads_running())

def test_any_loads_running_false(self):
patient, _ = self.new_patient_and_episode_please()
imodels.InitialPatientLoad.objects.create(
state=imodels.InitialPatientLoad.SUCCESS,
patient=patient,
started=timezone.now()
)
imodels.BatchPatientLoad.objects.create(
state=imodels.BatchPatientLoad.SUCCESS,
started=timezone.now()
)
self.assertFalse(loader.any_loads_running())
3 changes: 3 additions & 0 deletions lab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Package definition
"""
22 changes: 22 additions & 0 deletions lab/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from reversion.admin import VersionAdmin
from reversion import revisions as reversion
from lab.models import LabTest, Observation
from opal.utils import _itersubclasses
from django.contrib import admin


class LabTestAdmin(VersionAdmin):
pass


def register_lab_tests():
for lab_test in LabTest.list():
if not getattr(lab_test, "_no_admin", False):
admin.site.register(lab_test, LabTestAdmin)

for obs in _itersubclasses(Observation):
if not reversion.is_registered(obs):
admin.site.register(obs, LabTestAdmin)


register_lab_tests()
14 changes: 14 additions & 0 deletions lab/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.utils.functional import SimpleLazyObject
from lab.models import LabTest


class LabTestContextProcessor(object):
def __init__(self):
for i in LabTest.list():
setattr(self, i.__name__, i)


def lab_tests(request):
return {
"lab_tests": SimpleLazyObject(LabTestContextProcessor)
}
20 changes: 20 additions & 0 deletions lab/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from opal.core import metadata
from lab.models import LabTest


class LabTestMetadata(metadata.Metadata):
slug = "lab_tests"

@classmethod
def to_dict(klass, **kw):
result = dict(lab_tests=dict(all_tests=[]))
for lab_test in LabTest.list():
for synonym in lab_test.get_synonyms():
result["lab_tests"][synonym] = dict(
result_form_url=lab_test.get_result_form_url(),
record_url=lab_test.get_record_url(),
display_name=lab_test.get_display_name()
)
if lab_test.HAS_FORM:
result["lab_tests"]["all_tests"].append(synonym)
return result
142 changes: 142 additions & 0 deletions lab/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import jsonfield.fields
import opal.models
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('opal', '0025_merge'),
]

operations = [
migrations.CreateModel(
name='LabTest',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(null=True, blank=True)),
('updated', models.DateTimeField(null=True, blank=True)),
('consistency_token', models.CharField(max_length=8)),
('status', models.CharField(blank=True, max_length=256, null=True, choices=[(b'pending', b'pending'), (b'complete', b'complete')])),
('lab_test_type', models.CharField(max_length=256, null=True, blank=True)),
('date_ordered', models.DateField(null=True, blank=True)),
('date_received', models.DateField(null=True, blank=True)),
('extras', jsonfield.fields.JSONField(null=True, blank=True)),
('created_by', models.ForeignKey(related_name='created_lab_labtest_subrecords', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('patient', models.ForeignKey(to='opal.Patient')),
('resistant_antibiotics', models.ManyToManyField(related_name='test_resistant', to='opal.Antimicrobial')),
('sensitive_antibiotics', models.ManyToManyField(related_name='test_sensitive', to='opal.Antimicrobial')),
('updated_by', models.ForeignKey(related_name='updated_lab_labtest_subrecords', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
bases=(opal.models.UpdatesFromDictMixin, opal.models.ToDictMixin, models.Model),
),
migrations.CreateModel(
name='Observation',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(null=True, blank=True)),
('updated', models.DateTimeField(null=True, blank=True)),
('consistency_token', models.CharField(max_length=8)),
('observation_type', models.CharField(max_length=256)),
('extras', jsonfield.fields.JSONField(null=True, blank=True)),
('result', models.CharField(max_length=256, null=True, blank=True)),
('name', models.CharField(max_length=255)),
('created_by', models.ForeignKey(related_name='created_lab_observation_subrecords', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('lab_test', models.ForeignKey(related_name='observations', to='lab.LabTest')),
('updated_by', models.ForeignKey(related_name='updated_lab_observation_subrecords', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
bases=(opal.models.UpdatesFromDictMixin, opal.models.ToDictMixin, models.Model),
),
migrations.CreateModel(
name='Antimicrobial',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='DynamicLookupList',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='DynamicResultChoices',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='GenericInput',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='Organism',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='PendingPosNeg',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='PosNeg',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='PosNegEquivicalNotDone',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
migrations.CreateModel(
name='PosNegUnknown',
fields=[
],
options={
'proxy': True,
},
bases=('lab.observation',),
),
]
24 changes: 24 additions & 0 deletions lab/migrations/0002_auto_20161127_1849.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lab', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='labtest',
old_name='extras',
new_name='details',
),
migrations.RenameField(
model_name='observation',
old_name='extras',
new_name='details',
),
]
24 changes: 24 additions & 0 deletions lab/migrations/0003_auto_20161127_1952.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lab', '0002_auto_20161127_1849'),
]

operations = [
migrations.RenameField(
model_name='labtest',
old_name='details',
new_name='extras',
),
migrations.RenameField(
model_name='observation',
old_name='details',
new_name='extras',
),
]
19 changes: 19 additions & 0 deletions lab/migrations/0004_auto_20161206_1255.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lab', '0003_auto_20161127_1952'),
]

operations = [
migrations.AlterField(
model_name='observation',
name='result',
field=models.CharField(default=None, max_length=256, null=True, blank=True),
),
]
Loading

0 comments on commit 93fe1c2

Please sign in to comment.