Skip to content

Commit

Permalink
Merge e01f1fc into f3e8cd0
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Feb 27, 2019
2 parents f3e8cd0 + e01f1fc commit c9512b6
Show file tree
Hide file tree
Showing 4 changed files with 32 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
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 c9512b6

Please sign in to comment.