File size: 25,693 Bytes
8018595
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
"""Tests for the PLCOm2012 Lung Cancer Risk Model.

Ground truth values are calculated from authors' reference implementation in
https://brocku.ca/lung-cancer-screening-and-risk-prediction/risk-calculators/
and the reference implementation in R: https://github.com/resplab/PLCOm2012.
"""

import pytest

from sentinel.risk_models.plcom2012 import PLCOm2012RiskModel
from sentinel.user_input import (
    Anthropometrics,
    CancerType,
    ChronicCondition,
    Demographics,
    Ethnicity,
    FamilyMemberCancer,
    FamilyRelation,
    FamilySide,
    Lifestyle,
    PersonalMedicalHistory,
    RelationshipDegree,
    Sex,
    SmokingHistory,
    SmokingStatus,
    UserInput,
)

# Test cases with calculated ground truth data (inline UserInput like Gail tests)
GROUND_TRUTH_CASES = [
    {
        "name": "low_risk_current_smoker",
        "input": UserInput(
            demographics=Demographics(
                age_years=55,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=25.0 * (1.75**2),
                ),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=10,
                    years_smoked=20,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[],
                previous_cancers=[],
            ),
            family_history=[],
        ),
        "expected": 0.31,
    },
    {
        "name": "moderate_risk_former_smoker",
        "input": UserInput(
            demographics=Demographics(
                age_years=62,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=27.0 * (1.75**2),
                ),
                education_level=3,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.FORMER,
                    cigarettes_per_day=20,
                    years_smoked=30,
                    years_since_quit=5,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[],
                previous_cancers=[],
            ),
            family_history=[],
        ),
        "expected": 1.24,
    },
    {
        "name": "high_risk_multiple_factors",
        "input": UserInput(
            demographics=Demographics(
                age_years=70,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=22.0 * (1.75**2),
                ),
                education_level=2,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=40,
                    years_smoked=45,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[ChronicCondition.COPD],
                previous_cancers=[CancerType.BREAST],
            ),
            family_history=[
                FamilyMemberCancer(
                    relation=FamilyRelation.MOTHER,
                    side=FamilySide.MATERNAL,
                    degree=RelationshipDegree.FIRST,
                    cancer_type=CancerType.LUNG,
                    age_at_diagnosis=65,
                )
            ],
        ),
        "expected": 31.19,
    },
    {
        "name": "black_race_variant",
        "input": UserInput(
            demographics=Demographics(
                age_years=58,
                sex=Sex.MALE,
                ethnicity=Ethnicity.BLACK,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=28.0 * (1.75**2),
                ),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.FORMER,
                    cigarettes_per_day=15,
                    years_smoked=25,
                    years_since_quit=8,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[],
                previous_cancers=[],
            ),
            family_history=[],
        ),
        "expected": 0.696,
    },
    {
        "name": "hispanic_low_education",
        "input": UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.HISPANIC,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=30.0 * (1.75**2),
                ),
                education_level=1,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=25,
                    years_smoked=35,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[],
                previous_cancers=[],
            ),
            family_history=[],
        ),
        "expected": 1.161,
    },
    {
        "name": "asian_former_heavy_smoker",
        "input": UserInput(
            demographics=Demographics(
                age_years=65,
                sex=Sex.MALE,
                ethnicity=Ethnicity.ASIAN,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=24.0 * (1.75**2),
                ),
                education_level=5,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.FORMER,
                    cigarettes_per_day=25,
                    years_smoked=35,
                    years_since_quit=3,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[ChronicCondition.COPD],
                previous_cancers=[],
            ),
            family_history=[
                FamilyMemberCancer(
                    relation=FamilyRelation.MOTHER,
                    side=FamilySide.MATERNAL,
                    degree=RelationshipDegree.FIRST,
                    cancer_type=CancerType.LUNG,
                    age_at_diagnosis=65,
                )
            ],
        ),
        "expected": 3.40,
    },
]


class TestPLCOm2012Model:
    """Test suite for PLCOm2012RiskModel."""

    def setup_method(self):
        """Initialize PLCOm2012RiskModel instance for testing."""
        self.model = PLCOm2012RiskModel()

    @pytest.mark.parametrize("case", GROUND_TRUTH_CASES, ids=lambda x: x["name"])
    def test_ground_truth_validation(self, case):
        """Test against calculated ground truth results.

        Args:
            case: Parameterized ground truth case dict.
        """
        user = case["input"]
        score_str = self.model.compute_score(user)
        calculated = float(score_str.rstrip("%"))
        expected = case["expected"]

        # Using tight tolerance since these are calculated values
        assert calculated == pytest.approx(expected, abs=0.01)

    def test_user_input_integration_current_smoker(self):
        """Test integration with UserInput model for current smoker."""
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(
                    height_cm=175.0,
                    weight_kg=80.0,
                ),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[],
                previous_cancers=[],
            ),
            family_history=[],
        )

        score = self.model.compute_score(user)
        assert score != "N/A: Model is for current or former smokers only."
        assert "%" in score
        assert float(score.replace("%", "")) > 0

    def test_user_input_integration_former_smoker(self):
        """Test integration with UserInput model for former smoker."""
        user = UserInput(
            demographics=Demographics(
                age_years=65,
                sex=Sex.FEMALE,
                ethnicity=Ethnicity.BLACK,
                anthropometrics=Anthropometrics(
                    height_cm=160.0,
                    weight_kg=70.0,
                ),
                education_level=3,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.FORMER,
                    cigarettes_per_day=15,
                    years_smoked=30,
                    years_since_quit=10,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[ChronicCondition.COPD],
                previous_cancers=[CancerType.BREAST],
            ),
            family_history=[
                FamilyMemberCancer(
                    relation=FamilyRelation.FATHER,
                    side=FamilySide.PATERNAL,
                    degree=RelationshipDegree.FIRST,
                    cancer_type=CancerType.LUNG,
                    age_at_diagnosis=68,
                )
            ],
        )

        score = self.model.compute_score(user)
        assert score != "N/A: Model is for current or former smokers only."
        assert "%" in score
        assert float(score.replace("%", "")) > 0

    def test_never_smoker_handling(self):
        """Test that never smokers receive N/A response."""
        never_smoker = UserInput(
            demographics=Demographics(
                age_years=55,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.NEVER,
                    cigarettes_per_day=0,
                    years_smoked=0,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        score = self.model.compute_score(never_smoker)
        assert score == "N/A: Model is for current or former smokers only."

    def test_validation_errors(self):
        """Test validation errors for missing required fields."""
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        # This should pass validation since all required fields are present
        score = self.model.compute_score(user)
        assert "%" in score

    def test_age_out_of_range(self):
        """Test age outside validated range raises ValueError."""
        user = UserInput(
            demographics=Demographics(
                age_years=45,  # Below minimum
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        with pytest.raises(ValueError, match=r"Invalid inputs for PLCOm2012:"):
            self.model.compute_score(user)

    def test_age_validation_legacy(self):
        """Test age validation (50-80 range) - legacy behavior."""
        # This test is now handled by input validation, so we expect ValueError
        young_user = UserInput(
            demographics=Demographics(
                age_years=49,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=75.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )
        with pytest.raises(ValueError, match=r"Invalid inputs for PLCOm2012:"):
            self.model.compute_score(young_user)

        old_user = UserInput(
            demographics=Demographics(
                age_years=81,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=75.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )
        with pytest.raises(ValueError, match=r"Invalid inputs for PLCOm2012:"):
            self.model.compute_score(old_user)

    def test_missing_bmi_data(self):
        """Test handling of missing BMI data."""
        # This test is now handled by input validation since anthropometrics is required
        # We can't create a UserInput without anthropometrics due to Pydantic validation
        pass

    def test_missing_education_level(self):
        """Test handling of missing education level."""
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                # Missing education_level
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        with pytest.raises(ValueError, match=r"Invalid inputs for PLCOm2012:"):
            self.model.compute_score(user)

    def test_missing_smoking_intensity(self):
        """Test handling of missing smoking intensity."""
        # This test is now handled by the model's internal validation
        # since 0 cigarettes per day causes a division by zero in the calculation
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=0,  # This will cause division by zero
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        # The model should handle this gracefully and return an N/A message
        score = self.model.compute_score(user)
        assert "Calculation failed" in score

    def test_missing_smoking_duration(self):
        """Test handling of missing smoking duration."""
        # This test is now handled by input validation since years_smoked >= 0 is required
        # The model will accept 0 years smoked as valid input
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=0,  # This is valid input
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        # This should work fine with 0 years smoked
        score = self.model.compute_score(user)
        assert "%" in score

    def test_missing_quit_years_former_smoker(self):
        """Test handling of missing quit years for former smoker."""
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.FORMER,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,  # This will trigger N/A message
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[],
        )

        score = self.model.compute_score(user)
        assert "Missing years since quitting for former smoker" in score

    def test_copd_detection(self):
        """Test COPD detection from chronic illnesses."""
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(
                chronic_conditions=[ChronicCondition.COPD, ChronicCondition.DIABETES],
            ),
            family_history=[],
        )

        score = self.model.compute_score(user)
        assert "%" in score

    def test_family_history_lung_cancer_detection(self):
        """Test lung cancer family history detection."""
        user = UserInput(
            demographics=Demographics(
                age_years=60,
                sex=Sex.MALE,
                ethnicity=Ethnicity.WHITE,
                anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                education_level=4,
            ),
            lifestyle=Lifestyle(
                smoking=SmokingHistory(
                    status=SmokingStatus.CURRENT,
                    cigarettes_per_day=20,
                    years_smoked=25,
                    years_since_quit=None,
                ),
            ),
            personal_medical_history=PersonalMedicalHistory(),
            family_history=[
                FamilyMemberCancer(
                    relation=FamilyRelation.MOTHER,
                    side=FamilySide.MATERNAL,
                    degree=RelationshipDegree.FIRST,
                    cancer_type=CancerType.LUNG,
                    age_at_diagnosis=65,
                ),
                FamilyMemberCancer(
                    relation=FamilyRelation.MATERNAL_UNCLE,
                    side=FamilySide.MATERNAL,
                    degree=RelationshipDegree.SECOND,
                    cancer_type=CancerType.LUNG,
                    age_at_diagnosis=70,
                ),  # Should not count (not first-degree relative)
            ],
        )

        score = self.model.compute_score(user)
        assert "%" in score

    def test_race_handling(self):
        """Test different race/ethnicity handling."""
        races = [
            Ethnicity.WHITE,
            Ethnicity.BLACK,
            Ethnicity.HISPANIC,
            Ethnicity.ASIAN,
            Ethnicity.PACIFIC_ISLANDER,
        ]

        for race in races:
            user = UserInput(
                demographics=Demographics(
                    age_years=60,
                    sex=Sex.MALE,
                    ethnicity=race,
                    anthropometrics=Anthropometrics(height_cm=175.0, weight_kg=80.0),
                    education_level=4,
                ),
                lifestyle=Lifestyle(
                    smoking=SmokingHistory(
                        status=SmokingStatus.CURRENT,
                        cigarettes_per_day=20,
                        years_smoked=25,
                        years_since_quit=None,
                    ),
                ),
                personal_medical_history=PersonalMedicalHistory(),
                family_history=[],
            )

            score = self.model.compute_score(user)
            assert "%" in score
            assert float(score.replace("%", "")) > 0

    def test_model_metadata(self):
        """Test model metadata methods."""
        assert self.model.name == "plcom2012"
        assert self.model.cancer_type() == "lung"
        assert "PLCOm2012" in self.model.description()
        assert "6-year" in self.model.description()
        assert "percentage chance" in self.model.interpretation()
        assert isinstance(self.model.references(), list)
        assert len(self.model.references()) > 0
        assert "Tammemägi" in self.model.references()[0]

    def test_smoking_status_encoding(self):
        """Test smoking status encoding (current=0, former=1)."""
        # Test current smoker
        current_input = dict(
            age=60,
            race="white",
            education=4,
            bmi=25.0,
            copd=0,
            cancer_hist=0,
            family_hist_lung_cancer=0,
            smoking_status=0,
            smoking_intensity=20,
            duration_smoking=25,
            smoking_quit_time=0,
        )
        current_risk = self.model.calculate_risk(**current_input)

        # Test former smoker (same parameters except status and quit time)
        former_input = dict(
            age=60,
            race="white",
            education=4,
            bmi=25.0,
            copd=0,
            cancer_hist=0,
            family_hist_lung_cancer=0,
            smoking_status=1,
            smoking_intensity=20,
            duration_smoking=25,
            smoking_quit_time=5,
        )
        former_risk = self.model.calculate_risk(**former_input)

        # Both should be positive numbers
        assert current_risk > 0
        assert former_risk > 0

    def test_smoking_intensity_transformation(self):
        """Test smoking intensity transformation ((intensity/10)^-1)."""
        # Test with different intensities
        intensities = [10, 20, 30, 40]
        risks = []

        for intensity in intensities:
            input_data = dict(
                age=60,
                race="white",
                education=4,
                bmi=25.0,
                copd=0,
                cancer_hist=0,
                family_hist_lung_cancer=0,
                smoking_status=0,
                smoking_intensity=intensity,
                duration_smoking=25,
                smoking_quit_time=0,
            )
            risk = self.model.calculate_risk(**input_data)
            risks.append(risk)

        # All risks should be positive
        for risk in risks:
            assert risk > 0