diff --git a/opal/models.py b/opal/models.py index 291de2b2b..42ec96911 100644 --- a/opal/models.py +++ b/opal/models.py @@ -160,6 +160,21 @@ def _get_field_default(cls, name): return default + @classmethod + def get_field_description(cls, name): + field = cls._get_field(name) + description = getattr(field, 'help_text', "") + if description: + return description + + @classmethod + def get_field_enum(cls, name): + field = cls._get_field(name) + choices = getattr(field, "choices", []) + + if choices: + return [i[1] for i in choices] + @classmethod def build_field_schema(cls): field_schema = [] @@ -184,14 +199,18 @@ def build_field_schema(cls): ) title = cls._get_field_title(fieldname) default = cls._get_field_default(fieldname) - - field_schema.append({'name': fieldname, - 'title': title, - 'type': field_type, - 'lookup_list': lookup_list, - 'default': default, - 'model': cls.__name__ - }) + field = { + 'name': fieldname, + 'title': title, + 'type': field_type, + 'lookup_list': lookup_list, + 'default': default, + 'model': cls.__name__, + 'description': cls.get_field_description(fieldname), + 'enum': cls.get_field_enum(fieldname) + } + + field_schema.append(field) return field_schema @@ -1011,8 +1030,15 @@ def get_form_template(team=None, subteam=None): @staticmethod def build_field_schema(): - return [{'name': t, 'type': 'boolean'} for t in - patient_lists.TaggedPatientList.get_tag_names()] + # t.title is wrong, but its the better than nothing + result = [] + for tag in patient_lists.TaggedPatientList.get_tag_names(): + result.append({ + 'name': tag, + 'type': 'boolean', + 'title': tag.replace("_", " ").title() + }) + return result """ @@ -1280,23 +1306,27 @@ class Demographics(PatientSubrecord): hospital_number = models.CharField(max_length=255, blank=True) nhs_number = models.CharField( - max_length=255, blank=True, null=True, verbose_name="NHS Number" + max_length=255, blank=True, null=True, verbose_name="NHS Number", ) surname = models.CharField(max_length=255, blank=True) first_name = models.CharField(max_length=255, blank=True) middle_name = models.CharField(max_length=255, blank=True, null=True) title = ForeignKeyOrFreeText(Title) - date_of_birth = models.DateField(null=True, blank=True) + date_of_birth = models.DateField( + null=True, blank=True, verbose_name="Date of Birth" + ) marital_status = ForeignKeyOrFreeText(MaritalStatus) religion = models.CharField(max_length=255, blank=True, null=True) - date_of_death = models.DateField(null=True, blank=True) + date_of_death = models.DateField( + null=True, blank=True, verbose_name="Date of Death" + ) post_code = models.CharField(max_length=20, blank=True, null=True) gp_practice_code = models.CharField( max_length=20, blank=True, null=True, verbose_name="GP Practice Code" ) birth_place = ForeignKeyOrFreeText(Destination, - verbose_name="Country Of Birth") + verbose_name="Country of Birth") ethnicity = ForeignKeyOrFreeText(Ethnicity) death_indicator = models.BooleanField(default=False) @@ -1540,6 +1570,7 @@ class InpatientAdmission(PatientSubrecord, ExternallySourcedModel): _title = "Inpatient Admissions" _icon = 'fa fa-map-marker' _sort = "-admitted" + _advanced_searchable = False datetime_of_admission = models.DateTimeField(blank=True, null=True) datetime_of_discharge = models.DateTimeField(blank=True, null=True) diff --git a/opal/tests/test_core_schemas.py b/opal/tests/test_core_schemas.py index 43d74152f..1b07e7f6e 100644 --- a/opal/tests/test_core_schemas.py +++ b/opal/tests/test_core_schemas.py @@ -21,34 +21,46 @@ 'type': 'date_time', 'name': 'created', 'default': None, + 'enum': None, + 'description': None, 'title': 'Created'}, {'model': 'Colour', 'lookup_list': None, 'type': 'date_time', 'name': 'updated', 'default': None, + 'enum': None, + 'description': None, 'title': 'Updated'}, {'model': 'Colour', 'lookup_list': None, 'default': None, 'name': 'created_by_id', 'title': 'Created By', + 'enum': None, + 'description': None, 'type': 'forei'}, {'model': 'Colour', 'lookup_list': None, 'default': None, + 'enum': None, + 'description': None, 'name': 'updated_by_id', 'title': 'Updated By', 'type': 'forei'}, {'model': 'Colour', 'lookup_list': None, 'default': None, + 'enum': None, + 'description': None, 'name': 'consistency_token', 'title': 'Consistency Token', 'type': 'token'}, {'model': 'Colour', 'lookup_list': None, 'default': None, + 'enum': None, + 'description': None, 'name': 'name', 'title': 'Name', 'type': 'string'}, diff --git a/opal/tests/test_models.py b/opal/tests/test_models.py index e052b8d25..ac34d12a1 100644 --- a/opal/tests/test_models.py +++ b/opal/tests/test_models.py @@ -5,23 +5,23 @@ from mock import patch, MagicMock from django.conf import settings -from django.contrib.auth.models import User from django.utils import timezone from opal import models from opal.core import exceptions from opal.models import ( Subrecord, Tagging, Patient, InpatientAdmission, Symptom, - SymptomComplex, UserProfile ) from opal.core.test import OpalTestCase -import opal.tests.test_patient_lists # To make sure test tagged lists are pulled in +from opal.core import patient_lists +from opal.tests import test_patient_lists from opal.tests.models import ( FamousLastWords, PatientColour, ExternalSubRecord, SymptomComplex, PatientConsultation, Birthday, DogOwner, HatWearer, HouseOwner, HoundOwner, Colour ) + class PatientRecordAccessTestCase(OpalTestCase): def test_to_dict(self): @@ -746,13 +746,15 @@ def test_display_template(self): def test_form_template(self): self.assertEqual('tagging_modal.html', Tagging.get_form_template()) - def test_field_schema(self): - names = ['eater', 'herbivore', 'carnivore'] - fields = [{'name': tagname, 'type': 'boolean'} for tagname in names] + @patch.object(patient_lists.TaggedPatientList, "list") + def test_field_schema(self, patient_list): + patient_list.return_value = [test_patient_lists.TaggingTestPatientList] + expected = [ + {'name': 'eater', 'title': 'Eater', 'type': 'boolean'}, + {'type': 'boolean', 'name': 'herbivore', 'title': 'Herbivore'} + ] schema = Tagging.build_field_schema() - for field in fields: - self.assertIn(field, schema) - + self.assertEqual(expected, schema) class AbstractDemographicsTestCase(OpalTestCase): diff --git a/opal/tests/test_models_mixins.py b/opal/tests/test_models_mixins.py index f88fe3bff..f2b515750 100644 --- a/opal/tests/test_models_mixins.py +++ b/opal/tests/test_models_mixins.py @@ -61,6 +61,8 @@ def test_build_field_schema(self): expected = [ { 'model': 'SerialisableModel', + 'description': None, + 'enum': None, 'lookup_list': None, 'type': 'string', 'name': 'pid', @@ -69,6 +71,8 @@ def test_build_field_schema(self): }, { 'model': 'SerialisableModel', + 'description': None, + 'enum': None, 'lookup_list': 'hat', 'type': 'string', 'name': 'hatty', @@ -89,6 +93,7 @@ def test_getter_is_used(self): dict(foo="gotten", id=None) ) + class UpdatesFromDictMixinTestCase(OpalTestCase): def setUp(self): self.model = UpdatableModelInstance