Skip to content

Commit 9969572

Browse files
committed
Add family history of cancer to PLCO calculator
1 parent 0fccc18 commit 9969572

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lung_cancer_screening/calculators/plco.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ class Plco:
99
BMI_CENTRED_OR_REFERENT_REF_GROUP = Decimal('27')
1010
COPD_ENPHYSEMA_OR_CHRONIC_BRONCHITIS_COEFFICIENT = Decimal('0.3553063')
1111
PERSONAL_HISTORY_OF_CANCER_COEFFICIENT = Decimal('0.4589971')
12+
FAMILY_HISTORY_OF_CANCER_COEFFICIENT = Decimal('0.587185')
1213

13-
def __init__(self, age=None, bmi=None, copd_enphysema_or_chronic_bronchitis=None, personal_history_of_cancer=None):
14+
def __init__(self,
15+
age=None,
16+
bmi=None,
17+
copd_enphysema_or_chronic_bronchitis=None,
18+
personal_history_of_cancer=None, family_history_of_cancer=None):
1419
self.age = Decimal(str(age or 0))
1520
self.bmi = Decimal(str(bmi or 0))
1621
self.copd_enphysema_or_chronic_bronchitis = copd_enphysema_or_chronic_bronchitis
1722
self.personal_history_of_cancer = personal_history_of_cancer
23+
self.family_history_of_cancer = family_history_of_cancer
1824

1925
def age_in_years_contribution_to_estimate(self):
2026
return (self.age - self.AGE_CENTRED_OR_REFERENT_REF_GROUP) * self.AGE_COEFFICIENT
@@ -37,5 +43,12 @@ def personal_history_of_cancer_contribution_to_estimate(self):
3743

3844
return self.personal_history_of_cancer * self.PERSONAL_HISTORY_OF_CANCER_COEFFICIENT
3945

46+
def family_history_of_cancer_contribution_to_estimate(self):
47+
if self.family_history_of_cancer is None:
48+
raise self.InvalidValueError(
49+
"family_history_of_cancer must be true or false")
50+
51+
return self.family_history_of_cancer * self.FAMILY_HISTORY_OF_CANCER_COEFFICIENT
52+
4053
class InvalidValueError(Exception):
4154
pass

lung_cancer_screening/calculators/tests/test_plco.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,26 @@ def test_personal_history_of_cancer_contribution_to_estimate_when_false(self):
8383
result = calculator.personal_history_of_cancer_contribution_to_estimate()
8484

8585
self.assertEqual(result, Decimal('0'))
86+
87+
def test_family_history_of_cancer_contribution_to_estimate_when_none(self):
88+
calculator = Plco(family_history_of_cancer=None)
89+
90+
self.assertRaises(
91+
Plco.InvalidValueError,
92+
calculator.family_history_of_cancer_contribution_to_estimate
93+
)
94+
95+
def test_family_history_of_cancer_contribution_to_estimate_when_true(self):
96+
calculator = Plco(family_history_of_cancer=True)
97+
98+
result = calculator.family_history_of_cancer_contribution_to_estimate()
99+
100+
self.assertEqual(result, Decimal('0.587185'))
101+
102+
def test_family_history_of_cancer_contribution_to_estimate_when_false(self):
103+
calculator = Plco(family_history_of_cancer=False)
104+
105+
result = calculator.family_history_of_cancer_contribution_to_estimate()
106+
107+
self.assertEqual(result, Decimal('0'))
108+

0 commit comments

Comments
 (0)