Skip to content

Commit 600a95f

Browse files
committed
Initial BMI and Age calculations for PLCO
1 parent ead190c commit 600a95f

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13.1

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
- ./lung_cancer_screening:/app/lung_cancer_screening
1818
restart: unless-stopped
1919

20+
2021
asset_builder:
2122
build:
2223
context: .

tests/.gitkeep renamed to lung_cancer_screening/calculators/__init__.py

File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from decimal import Decimal, getcontext
2+
3+
getcontext().prec = 999999
4+
5+
class Plco:
6+
AGE_COEFFICIENT = Decimal('0.0778868')
7+
AGE_CENTRED_OR_REFERENT_REF_GROUP = Decimal('62')
8+
BMI_COEFFICIENT = Decimal('-0.0274194')
9+
BMI_CENTRED_OR_REFERENT_REF_GROUP = Decimal('27')
10+
11+
def __init__(self, age=None, bmi=None):
12+
self.age = Decimal(str(age or 0))
13+
self.bmi = Decimal(str(bmi or 0))
14+
15+
def age_in_years_contribution_to_estimate(self):
16+
return (self.age - self.AGE_CENTRED_OR_REFERENT_REF_GROUP) * self.AGE_COEFFICIENT
17+
18+
def bmi_contribution_to_estimate(self):
19+
return (self.bmi - self.BMI_CENTRED_OR_REFERENT_REF_GROUP) * self.BMI_COEFFICIENT

lung_cancer_screening/calculators/tests/__init__.py

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from django.test import TestCase
2+
from decimal import Decimal
3+
4+
from lung_cancer_screening.calculators.plco import Plco
5+
6+
class TestPlco(TestCase):
7+
def test_age_in_years_contribution_to_estimate_when_age_is_none(self):
8+
calculator = Plco(age=None)
9+
result = calculator.age_in_years_contribution_to_estimate()
10+
11+
self.assertEqual(result, Decimal('-4.8289816'))
12+
13+
def test_age_in_years_contribution_to_estimate_at_74(self):
14+
calculator = Plco(age=74)
15+
result = calculator.age_in_years_contribution_to_estimate()
16+
17+
self.assertEqual(result, Decimal('0.9346416'))
18+
19+
def test_age_in_years_contribution_to_estimate_at_62(self):
20+
calculator = Plco(age=58)
21+
result = calculator.age_in_years_contribution_to_estimate()
22+
23+
self.assertEqual(result, Decimal('-0.3115472'))
24+
25+
def test_bmi_contribution_to_estimate_when_bmi_is_none(self):
26+
calculator = Plco(bmi=None)
27+
result = calculator.bmi_contribution_to_estimate()
28+
29+
self.assertEqual(result, Decimal('0.7403238'))
30+
31+
def test_bmi_contribution_to_estimate_when_bmi_is_23_point_5(self):
32+
calculator = Plco(bmi=23.5)
33+
result = calculator.bmi_contribution_to_estimate()
34+
35+
self.assertEqual(result, Decimal('0.0959679'))
36+
37+
def test_bmi_contribution_to_estimate_when_bmi_is_a_long_decimal(self):
38+
calculator = Plco(bmi="26.4749212")
39+
result = calculator.bmi_contribution_to_estimate()
40+
41+
self.assertEqual(result, Decimal('0.01439734564872'))

lung_cancer_screening/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def boolean_env(key, default=None):
4848
'django.contrib.staticfiles',
4949
'lung_cancer_screening.core',
5050
'lung_cancer_screening.questions'
51+
'lung_cancer_screening.calculators',
5152
]
5253

5354
MIDDLEWARE = [

0 commit comments

Comments
 (0)