Skip to content

Commit

Permalink
Merge 8f72698 into f3e8cd0
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Feb 27, 2019
2 parents f3e8cd0 + 8f72698 commit eef3a50
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .envrc
@@ -0,0 +1,2 @@
layout python python3.4

2 changes: 2 additions & 0 deletions changelog.md
@@ -1,5 +1,7 @@
### 0.14.0 (Major Release)

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

### 0.13.1 (Minor Release)

Upgrades the setup.py Django version from 2.0.9 to 2.0.13. Removes the six library dependency from setup.py.
Expand Down
16 changes: 16 additions & 0 deletions doc/docs/reference/subrecords.md
Expand Up @@ -224,3 +224,19 @@ 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 a patient.

This model maps `first_name`, `middle name` `surname`, `title`, `date_of_birth`, `hospital_number` and `nhs_number` and other similar fields.

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 @@ -1411,8 +1412,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 @@ -819,6 +819,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 eef3a50

Please sign in to comment.