Skip to content

Commit 0fccc18

Browse files
committed
Add personal history of cancer to PLCO calculator
1 parent 9655600 commit 0fccc18

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lung_cancer_screening/calculators/plco.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ class Plco:
88
BMI_COEFFICIENT = Decimal('-0.0274194')
99
BMI_CENTRED_OR_REFERENT_REF_GROUP = Decimal('27')
1010
COPD_ENPHYSEMA_OR_CHRONIC_BRONCHITIS_COEFFICIENT = Decimal('0.3553063')
11+
PERSONAL_HISTORY_OF_CANCER_COEFFICIENT = Decimal('0.4589971')
1112

12-
def __init__(self, age=None, bmi=None, copd_enphysema_or_chronic_bronchitis=None):
13+
def __init__(self, age=None, bmi=None, copd_enphysema_or_chronic_bronchitis=None, personal_history_of_cancer=None):
1314
self.age = Decimal(str(age or 0))
1415
self.bmi = Decimal(str(bmi or 0))
1516
self.copd_enphysema_or_chronic_bronchitis = copd_enphysema_or_chronic_bronchitis
17+
self.personal_history_of_cancer = personal_history_of_cancer
1618

1719
def age_in_years_contribution_to_estimate(self):
1820
return (self.age - self.AGE_CENTRED_OR_REFERENT_REF_GROUP) * self.AGE_COEFFICIENT
@@ -27,5 +29,13 @@ def copd_enphysema_or_chronic_bronchitis_contribution_to_estimate(self):
2729

2830
return self.copd_enphysema_or_chronic_bronchitis * self.COPD_ENPHYSEMA_OR_CHRONIC_BRONCHITIS_COEFFICIENT
2931

32+
33+
def personal_history_of_cancer_contribution_to_estimate(self):
34+
if self.personal_history_of_cancer is None:
35+
raise self.InvalidValueError(
36+
"personal_history_of_cancer must be true or false")
37+
38+
return self.personal_history_of_cancer * self.PERSONAL_HISTORY_OF_CANCER_COEFFICIENT
39+
3040
class InvalidValueError(Exception):
3141
pass

lung_cancer_screening/calculators/tests/test_plco.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,25 @@ def test_copd_enphysema_or_chronic_bronchitiscontribution_to_estimate_when_false
6161
result = calculator.copd_enphysema_or_chronic_bronchitis_contribution_to_estimate()
6262

6363
self.assertEqual(result, Decimal('0'))
64+
65+
def test_personal_history_of_cancer_contribution_to_estimate_when_none(self):
66+
calculator = Plco(personal_history_of_cancer=None)
67+
68+
self.assertRaises(
69+
Plco.InvalidValueError,
70+
calculator.personal_history_of_cancer_contribution_to_estimate
71+
)
72+
73+
def test_personal_history_of_cancer_contribution_to_estimate_when_true(self):
74+
calculator = Plco(personal_history_of_cancer=True)
75+
76+
result = calculator.personal_history_of_cancer_contribution_to_estimate()
77+
78+
self.assertEqual(result, Decimal('0.4589971'))
79+
80+
def test_personal_history_of_cancer_contribution_to_estimate_when_false(self):
81+
calculator = Plco(personal_history_of_cancer=False)
82+
83+
result = calculator.personal_history_of_cancer_contribution_to_estimate()
84+
85+
self.assertEqual(result, Decimal('0'))

0 commit comments

Comments
 (0)