Skip to content

Commit 9655600

Browse files
committed
Add copd_enphysema_or_bronchitis to PLCO calculator
1 parent 600a95f commit 9655600

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lung_cancer_screening/calculators/plco.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@ class Plco:
77
AGE_CENTRED_OR_REFERENT_REF_GROUP = Decimal('62')
88
BMI_COEFFICIENT = Decimal('-0.0274194')
99
BMI_CENTRED_OR_REFERENT_REF_GROUP = Decimal('27')
10+
COPD_ENPHYSEMA_OR_CHRONIC_BRONCHITIS_COEFFICIENT = Decimal('0.3553063')
1011

11-
def __init__(self, age=None, bmi=None):
12+
def __init__(self, age=None, bmi=None, copd_enphysema_or_chronic_bronchitis=None):
1213
self.age = Decimal(str(age or 0))
1314
self.bmi = Decimal(str(bmi or 0))
15+
self.copd_enphysema_or_chronic_bronchitis = copd_enphysema_or_chronic_bronchitis
1416

1517
def age_in_years_contribution_to_estimate(self):
1618
return (self.age - self.AGE_CENTRED_OR_REFERENT_REF_GROUP) * self.AGE_COEFFICIENT
1719

1820
def bmi_contribution_to_estimate(self):
1921
return (self.bmi - self.BMI_CENTRED_OR_REFERENT_REF_GROUP) * self.BMI_COEFFICIENT
22+
23+
def copd_enphysema_or_chronic_bronchitis_contribution_to_estimate(self):
24+
if self.copd_enphysema_or_chronic_bronchitis is None:
25+
raise self.InvalidValueError(
26+
"copd_enphysema_or_chronic_bronchitis must be true or false")
27+
28+
return self.copd_enphysema_or_chronic_bronchitis * self.COPD_ENPHYSEMA_OR_CHRONIC_BRONCHITIS_COEFFICIENT
29+
30+
class InvalidValueError(Exception):
31+
pass

lung_cancer_screening/calculators/tests/test_plco.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,25 @@ def test_bmi_contribution_to_estimate_when_bmi_is_a_long_decimal(self):
3939
result = calculator.bmi_contribution_to_estimate()
4040

4141
self.assertEqual(result, Decimal('0.01439734564872'))
42+
43+
def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_none(self):
44+
calculator = Plco(copd_enphysema_or_chronic_bronchitis=None)
45+
46+
self.assertRaises(
47+
Plco.InvalidValueError,
48+
calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate
49+
)
50+
51+
def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_true(self):
52+
calculator = Plco(copd_enphysema_or_chronic_bronchitis=True)
53+
54+
result = calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate()
55+
56+
self.assertEqual(result, Decimal('0.3553063'))
57+
58+
def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_false(self):
59+
calculator = Plco(copd_enphysema_or_chronic_bronchitis=False)
60+
61+
result = calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate()
62+
63+
self.assertEqual(result, Decimal('0'))

0 commit comments

Comments
 (0)