Skip to content

Commit

Permalink
Merge cadbd40 into 27e26f9
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmiller committed May 17, 2019
2 parents 27e26f9 + cadbd40 commit 3ebf6cb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .envrc
@@ -0,0 +1,2 @@
layout python python3.4

3 changes: 3 additions & 0 deletions changelog.md
Expand Up @@ -9,6 +9,9 @@ This change makes it so that it does.

### 0.14.0 (Major Release)


Adds the `age` property to demographics that returns the patient's age.

A User's UserProfile is now automatically created when you create a user in a post save signal.

RecordEditor.editItem, RecordEditor.editItem and RecordEditor.openEditItemModal to take a url argument.
Expand Down
32 changes: 32 additions & 0 deletions doc/docs/reference/subrecords.md
Expand Up @@ -224,3 +224,35 @@ fields external_system and external_identifier to allow us to track where
they come from and how they are referenced by that system.

These fields are then often used in forms to make the data read only


### Specific subrecords

#### Demographics
Opal ships with a demographics model that models personally identifying information for a patient.

This model maps

- `hospital_number`
- `nhs_number`
- `surname`
- `first_name`
- `middle name`
- `title`
- `date_of_birth`
- `marital_status`
- `religion`
- `date_of_death`
- `post_code`
- `birth_place`
- `ethnicity`
- `death_indicator`
- `sex`

It also has the properties:

- `name` - The first name and the surname combined.
- `age` - The current age of the patient (today - their date of birth)



18 changes: 18 additions & 0 deletions opal/models.py
Expand Up @@ -9,6 +9,7 @@
import logging
import random
import os
from dateutil.relativedelta import relativedelta

from django.utils import timezone
from django.db import models, transaction
Expand Down Expand Up @@ -1412,8 +1413,25 @@ class Demographics(PatientSubrecord):

@property
def name(self):
"""
Property that returns the name of the patient constructed from
`first_name` and `surname`
"""
return '{0} {1}'.format(self.first_name, self.surname)

@property
def age(self):
"""
Property that returns the age of the patient in years
or None if `date_of_birth` is not set.
"""
if self.date_of_birth:
today = datetime.date.today()
return relativedelta(
today,
self.date_of_birth
).years

class Meta:
abstract = True
verbose_name_plural = "Demographics"
Expand Down
10 changes: 10 additions & 0 deletions opal/tests/test_models.py
Expand Up @@ -820,6 +820,16 @@ def test_name(self):
middle_name='Obsidian')
self.assertEqual('Jane Doe', d.name)

def test_age_no_date_of_birth(self):
d = models.Demographics(date_of_birth=None)
self.assertIsNone(d.age)

@patch("opal.models.datetime")
def test_age(self, dt):
dt.date.today.return_value = datetime.date(2017, 3, 1)
d = models.Demographics(date_of_birth=datetime.date(2016, 1, 28))
self.assertEqual(d.age, 1)


class ExternalSystemTestCase(OpalTestCase):
def test_get_footer(self):
Expand Down

0 comments on commit 3ebf6cb

Please sign in to comment.