diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index 5bf8ce5..2c3a718 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -17,14 +17,14 @@ jobs: # github.event.pull_request.user.login == 'external-contributor' || # github.event.pull_request.user.login == 'new-developer' || # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' - + runs-on: ubuntu-latest permissions: contents: read pull-requests: read issues: read id-token: write - + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -39,7 +39,7 @@ jobs: # Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4) # model: "claude-opus-4-20250514" - + # Direct prompt for automated review (no @claude mention needed) direct_prompt: | Please review this pull request and provide feedback on: @@ -48,12 +48,12 @@ jobs: - Performance considerations - Security concerns - Test coverage - + Be constructive and helpful in your feedback. # Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR # use_sticky_comment: true - + # Optional: Customize review based on file types # direct_prompt: | # Review this PR focusing on: @@ -61,18 +61,17 @@ jobs: # - For API endpoints: Security, input validation, and error handling # - For React components: Performance, accessibility, and best practices # - For tests: Coverage, edge cases, and test quality - + # Optional: Different prompts for different authors # direct_prompt: | - # ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' && + # ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' && # 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' || # 'Please provide a thorough code review focusing on our coding standards and best practices.' }} - + # Optional: Add specific tools for running tests or linting # allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)" - + # Optional: Skip review for certain conditions # if: | # !contains(github.event.pull_request.title, '[skip-review]') && # !contains(github.event.pull_request.title, '[WIP]') - diff --git a/specs/coding_style.md b/specs/coding_style.md index 8f32533..70dec02 100644 --- a/specs/coding_style.md +++ b/specs/coding_style.md @@ -109,4 +109,4 @@ When faced with coding choices, ask: 5. **Does this follow our established conventions?** 6. **Is this optimized for readability?** -The answer to all these questions should be "yes" for beautiful Python code. \ No newline at end of file +The answer to all these questions should be "yes" for beautiful Python code. diff --git a/tests/inputs/score2/test__input__patient_25.json b/tests/inputs/score2/test__input__patient_25.json index 83f68ad..c14c61d 100755 --- a/tests/inputs/score2/test__input__patient_25.json +++ b/tests/inputs/score2/test__input__patient_25.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P024-2024-024", - "sex": "female", - "timestamp": "2024-07-04T13:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 50, - "unit": "years" + "metadata": { + "patient_id": "P024-2024-024", + "sex": "female", + "timestamp": "2024-07-04T13:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 140, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 6.3, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.4, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 50, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 140, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 6.3, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.4, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": false, + "unit": "yes/no" + } } - } } diff --git a/tests/inputs/score2/test__input__patient_26.json b/tests/inputs/score2/test__input__patient_26.json index ba11b32..47ca4c5 100755 --- a/tests/inputs/score2/test__input__patient_26.json +++ b/tests/inputs/score2/test__input__patient_26.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P024-2024-024", - "sex": "male", - "timestamp": "2024-07-04T13:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 50, - "unit": "years" + "metadata": { + "patient_id": "P024-2024-024", + "sex": "male", + "timestamp": "2024-07-04T13:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 140, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 6.3, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.4, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 50, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 140, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 6.3, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.4, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": true, + "unit": "yes/no" + } } - } } diff --git a/tests/inputs/score2/test__input__patient_27.json b/tests/inputs/score2/test__input__patient_27.json index 96b5a37..23b76ea 100644 --- a/tests/inputs/score2/test__input__patient_27.json +++ b/tests/inputs/score2/test__input__patient_27.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P027-2024-027", - "sex": "female", - "timestamp": "2024-07-04T14:00:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 55, - "unit": "years" + "metadata": { + "patient_id": "P027-2024-027", + "sex": "female", + "timestamp": "2024-07-04T14:00:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 125, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 5.2, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.6, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 55, + "unit": "years" + }, + "smoking_yes_no": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 125, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 5.2, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.6, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_28.json b/tests/inputs/score2/test__input__patient_28.json index 62b9906..ef74275 100644 --- a/tests/inputs/score2/test__input__patient_28.json +++ b/tests/inputs/score2/test__input__patient_28.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P028-2024-028", - "sex": "male", - "timestamp": "2024-07-04T14:15:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 45, - "unit": "years" + "metadata": { + "patient_id": "P028-2024-028", + "sex": "male", + "timestamp": "2024-07-04T14:15:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 130, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 5.8, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.3, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 45, + "unit": "years" + }, + "smoking_yes_no": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 130, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 5.8, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.3, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_29.json b/tests/inputs/score2/test__input__patient_29.json index d439a63..3b072bc 100644 --- a/tests/inputs/score2/test__input__patient_29.json +++ b/tests/inputs/score2/test__input__patient_29.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P029-2024-029", - "sex": "male", - "timestamp": "2024-07-04T14:30:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 40, - "unit": "years" + "metadata": { + "patient_id": "P029-2024-029", + "sex": "male", + "timestamp": "2024-07-04T14:30:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 135, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 6.0, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.2, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 40, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 135, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 6.0, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.2, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_30.json b/tests/inputs/score2/test__input__patient_30.json index 77bfb0b..d0d551a 100644 --- a/tests/inputs/score2/test__input__patient_30.json +++ b/tests/inputs/score2/test__input__patient_30.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P030-2024-030", - "sex": "female", - "timestamp": "2024-07-04T14:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 60, - "unit": "years" + "metadata": { + "patient_id": "P030-2024-030", + "sex": "female", + "timestamp": "2024-07-04T14:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 145, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 6.5, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.5, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 60, + "unit": "years" + }, + "smoking_yes_no": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 145, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 6.5, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.5, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_31.json b/tests/inputs/score2/test__input__patient_31.json index 66d115b..cce3e57 100644 --- a/tests/inputs/score2/test__input__patient_31.json +++ b/tests/inputs/score2/test__input__patient_31.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P031-2024-031", - "sex": "male", - "timestamp": "2024-07-04T15:00:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 65, - "unit": "years" + "metadata": { + "patient_id": "P031-2024-031", + "sex": "male", + "timestamp": "2024-07-04T15:00:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 150, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 7.0, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.1, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 65, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 150, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 7.0, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.1, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_32.json b/tests/inputs/score2/test__input__patient_32.json index 83cc013..14ea302 100644 --- a/tests/inputs/score2/test__input__patient_32.json +++ b/tests/inputs/score2/test__input__patient_32.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P032-2024-032", - "sex": "female", - "timestamp": "2024-07-04T15:15:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 69, - "unit": "years" + "metadata": { + "patient_id": "P032-2024-032", + "sex": "female", + "timestamp": "2024-07-04T15:15:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 155, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 7.2, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.3, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 69, + "unit": "years" + }, + "smoking_yes_no": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 155, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 7.2, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.3, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_33.json b/tests/inputs/score2/test__input__patient_33.json index 4220ee1..f71c377 100644 --- a/tests/inputs/score2/test__input__patient_33.json +++ b/tests/inputs/score2/test__input__patient_33.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P033-2024-033", - "sex": "male", - "timestamp": "2024-07-04T15:30:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 49, - "unit": "years" + "metadata": { + "patient_id": "P033-2024-033", + "sex": "male", + "timestamp": "2024-07-04T15:30:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 138, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 6.1, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.4, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 49, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 138, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 6.1, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.4, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_34.json b/tests/inputs/score2/test__input__patient_34.json index f2bdf7e..41ebd11 100644 --- a/tests/inputs/score2/test__input__patient_34.json +++ b/tests/inputs/score2/test__input__patient_34.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P034-2024-034", - "sex": "female", - "timestamp": "2024-07-04T15:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 50, - "unit": "years" + "metadata": { + "patient_id": "P034-2024-034", + "sex": "female", + "timestamp": "2024-07-04T15:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 120, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 4.8, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.8, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 50, + "unit": "years" + }, + "smoking_yes_no": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 120, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 4.8, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.8, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_35.json b/tests/inputs/score2/test__input__patient_35.json index 5fc3658..6f111b0 100644 --- a/tests/inputs/score2/test__input__patient_35.json +++ b/tests/inputs/score2/test__input__patient_35.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P035-2024-035", - "sex": "male", - "timestamp": "2024-07-04T16:00:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 55, - "unit": "years" + "metadata": { + "patient_id": "P035-2024-035", + "sex": "male", + "timestamp": "2024-07-04T16:00:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 142, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 6.4, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.2, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 55, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 142, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 6.4, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.2, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/inputs/score2/test__input__patient_36.json b/tests/inputs/score2/test__input__patient_36.json index b71ddb2..4d2e48e 100644 --- a/tests/inputs/score2/test__input__patient_36.json +++ b/tests/inputs/score2/test__input__patient_36.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P036-2024-036", - "sex": "female", - "timestamp": "2024-07-04T16:15:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age_years": { - "value": 45, - "unit": "years" + "metadata": { + "patient_id": "P036-2024-036", + "sex": "female", + "timestamp": "2024-07-04T16:15:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking_yes_no": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure_mmhg": { - "value": 132, - "unit": "mmHg" - }, - "total_cholesterol_mmol_l": { - "value": 5.5, - "unit": "mmol/L" - }, - "hdl_cholesterol_mmol_l": { - "value": 1.5, - "unit": "mmol/L" - }, - "is_male_yes_no": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age_years": { + "value": 45, + "unit": "years" + }, + "smoking_yes_no": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure_mmhg": { + "value": 132, + "unit": "mmHg" + }, + "total_cholesterol_mmol_l": { + "value": 5.5, + "unit": "mmol/L" + }, + "hdl_cholesterol_mmol_l": { + "value": 1.5, + "unit": "mmol/L" + }, + "is_male_yes_no": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_25.json b/tests/raw/score2/test__raw__patient_25.json index df7575a..45cdeee 100755 --- a/tests/raw/score2/test__raw__patient_25.json +++ b/tests/raw/score2/test__raw__patient_25.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P024-2024-024", - "sex": "female", - "timestamp": "2024-07-04T13:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 50, - "unit": "years" + "metadata": { + "patient_id": "P024-2024-024", + "sex": "female", + "timestamp": "2024-07-04T13:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 140, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 6.3, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.4, - "unit": "mmol/L" - }, - "is_male": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 50, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 140, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 6.3, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.4, + "unit": "mmol/L" + }, + "is_male": { + "value": false, + "unit": "yes/no" + } } - } } diff --git a/tests/raw/score2/test__raw__patient_26.json b/tests/raw/score2/test__raw__patient_26.json index 6eb6449..2872e8f 100755 --- a/tests/raw/score2/test__raw__patient_26.json +++ b/tests/raw/score2/test__raw__patient_26.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P024-2024-024", - "sex": "male", - "timestamp": "2024-07-04T13:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 50, - "unit": "years" + "metadata": { + "patient_id": "P024-2024-024", + "sex": "male", + "timestamp": "2024-07-04T13:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 140, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 6.3, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.4, - "unit": "mmol/L" - }, - "is_male": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 50, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 140, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 6.3, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.4, + "unit": "mmol/L" + }, + "is_male": { + "value": true, + "unit": "yes/no" + } } - } } diff --git a/tests/raw/score2/test__raw__patient_27.json b/tests/raw/score2/test__raw__patient_27.json index 8c2f500..c5ea1a0 100644 --- a/tests/raw/score2/test__raw__patient_27.json +++ b/tests/raw/score2/test__raw__patient_27.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P027-2024-027", - "sex": "female", - "timestamp": "2024-07-04T14:00:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 55, - "unit": "years" + "metadata": { + "patient_id": "P027-2024-027", + "sex": "female", + "timestamp": "2024-07-04T14:00:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 125, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 5.2, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.6, - "unit": "mmol/L" - }, - "is_male": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 55, + "unit": "years" + }, + "smoking": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 125, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 5.2, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.6, + "unit": "mmol/L" + }, + "is_male": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_28.json b/tests/raw/score2/test__raw__patient_28.json index 837f9c3..2acaa03 100644 --- a/tests/raw/score2/test__raw__patient_28.json +++ b/tests/raw/score2/test__raw__patient_28.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P028-2024-028", - "sex": "male", - "timestamp": "2024-07-04T14:15:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 45, - "unit": "years" + "metadata": { + "patient_id": "P028-2024-028", + "sex": "male", + "timestamp": "2024-07-04T14:15:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 130, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 5.8, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.3, - "unit": "mmol/L" - }, - "is_male": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 45, + "unit": "years" + }, + "smoking": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 130, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 5.8, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.3, + "unit": "mmol/L" + }, + "is_male": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_29.json b/tests/raw/score2/test__raw__patient_29.json index c9ded57..f6fcf3f 100644 --- a/tests/raw/score2/test__raw__patient_29.json +++ b/tests/raw/score2/test__raw__patient_29.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P029-2024-029", - "sex": "male", - "timestamp": "2024-07-04T14:30:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 40, - "unit": "years" + "metadata": { + "patient_id": "P029-2024-029", + "sex": "male", + "timestamp": "2024-07-04T14:30:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 135, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 6.0, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.2, - "unit": "mmol/L" - }, - "is_male": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 40, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 135, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 6.0, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.2, + "unit": "mmol/L" + }, + "is_male": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_30.json b/tests/raw/score2/test__raw__patient_30.json index b43b9a0..ca90af4 100644 --- a/tests/raw/score2/test__raw__patient_30.json +++ b/tests/raw/score2/test__raw__patient_30.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P030-2024-030", - "sex": "female", - "timestamp": "2024-07-04T14:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 60, - "unit": "years" + "metadata": { + "patient_id": "P030-2024-030", + "sex": "female", + "timestamp": "2024-07-04T14:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 145, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 6.5, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.5, - "unit": "mmol/L" - }, - "is_male": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 60, + "unit": "years" + }, + "smoking": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 145, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 6.5, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.5, + "unit": "mmol/L" + }, + "is_male": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_31.json b/tests/raw/score2/test__raw__patient_31.json index 0910c92..95fa65a 100644 --- a/tests/raw/score2/test__raw__patient_31.json +++ b/tests/raw/score2/test__raw__patient_31.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P031-2024-031", - "sex": "male", - "timestamp": "2024-07-04T15:00:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 65, - "unit": "years" + "metadata": { + "patient_id": "P031-2024-031", + "sex": "male", + "timestamp": "2024-07-04T15:00:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 150, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 7.0, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.1, - "unit": "mmol/L" - }, - "is_male": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 65, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 150, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 7.0, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.1, + "unit": "mmol/L" + }, + "is_male": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_32.json b/tests/raw/score2/test__raw__patient_32.json index 255d858..9a90055 100644 --- a/tests/raw/score2/test__raw__patient_32.json +++ b/tests/raw/score2/test__raw__patient_32.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P032-2024-032", - "sex": "female", - "timestamp": "2024-07-04T15:15:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 69, - "unit": "years" + "metadata": { + "patient_id": "P032-2024-032", + "sex": "female", + "timestamp": "2024-07-04T15:15:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 155, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 7.2, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.3, - "unit": "mmol/L" - }, - "is_male": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 69, + "unit": "years" + }, + "smoking": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 155, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 7.2, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.3, + "unit": "mmol/L" + }, + "is_male": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_33.json b/tests/raw/score2/test__raw__patient_33.json index 26cc61d..9a19590 100644 --- a/tests/raw/score2/test__raw__patient_33.json +++ b/tests/raw/score2/test__raw__patient_33.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P033-2024-033", - "sex": "male", - "timestamp": "2024-07-04T15:30:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 49, - "unit": "years" + "metadata": { + "patient_id": "P033-2024-033", + "sex": "male", + "timestamp": "2024-07-04T15:30:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 138, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 6.1, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.4, - "unit": "mmol/L" - }, - "is_male": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 49, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 138, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 6.1, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.4, + "unit": "mmol/L" + }, + "is_male": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_34.json b/tests/raw/score2/test__raw__patient_34.json index f471469..3f0153c 100644 --- a/tests/raw/score2/test__raw__patient_34.json +++ b/tests/raw/score2/test__raw__patient_34.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P034-2024-034", - "sex": "female", - "timestamp": "2024-07-04T15:45:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 50, - "unit": "years" + "metadata": { + "patient_id": "P034-2024-034", + "sex": "female", + "timestamp": "2024-07-04T15:45:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": false, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 120, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 4.8, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.8, - "unit": "mmol/L" - }, - "is_male": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 50, + "unit": "years" + }, + "smoking": { + "value": false, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 120, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 4.8, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.8, + "unit": "mmol/L" + }, + "is_male": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_35.json b/tests/raw/score2/test__raw__patient_35.json index 3c06bf3..d176cae 100644 --- a/tests/raw/score2/test__raw__patient_35.json +++ b/tests/raw/score2/test__raw__patient_35.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P035-2024-035", - "sex": "male", - "timestamp": "2024-07-04T16:00:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 55, - "unit": "years" + "metadata": { + "patient_id": "P035-2024-035", + "sex": "male", + "timestamp": "2024-07-04T16:00:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 142, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 6.4, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.2, - "unit": "mmol/L" - }, - "is_male": { - "value": true, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 55, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 142, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 6.4, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.2, + "unit": "mmol/L" + }, + "is_male": { + "value": true, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/raw/score2/test__raw__patient_36.json b/tests/raw/score2/test__raw__patient_36.json index d432a84..f618344 100644 --- a/tests/raw/score2/test__raw__patient_36.json +++ b/tests/raw/score2/test__raw__patient_36.json @@ -1,35 +1,35 @@ { - "metadata": { - "patient_id": "P036-2024-036", - "sex": "female", - "timestamp": "2024-07-04T16:15:00Z", - "test_date": "2024-07-04", - "laboratory": "NHANES Reference Labs" - }, - "raw_biomarkers": { - "age": { - "value": 45, - "unit": "years" + "metadata": { + "patient_id": "P036-2024-036", + "sex": "female", + "timestamp": "2024-07-04T16:15:00Z", + "test_date": "2024-07-04", + "laboratory": "NHANES Reference Labs" }, - "smoking": { - "value": true, - "unit": "yes/no" - }, - "systolic_blood_pressure": { - "value": 132, - "unit": "mmHg" - }, - "total_cholesterol": { - "value": 5.5, - "unit": "mmol/L" - }, - "hdl_cholesterol": { - "value": 1.5, - "unit": "mmol/L" - }, - "is_male": { - "value": false, - "unit": "yes/no" + "raw_biomarkers": { + "age": { + "value": 45, + "unit": "years" + }, + "smoking": { + "value": true, + "unit": "yes/no" + }, + "systolic_blood_pressure": { + "value": 132, + "unit": "mmHg" + }, + "total_cholesterol": { + "value": 5.5, + "unit": "mmol/L" + }, + "hdl_cholesterol": { + "value": 1.5, + "unit": "mmol/L" + }, + "is_male": { + "value": false, + "unit": "yes/no" + } } - } -} \ No newline at end of file +} diff --git a/tests/test_score2.py b/tests/test_score2.py index 1f651c1..98e76ff 100644 --- a/tests/test_score2.py +++ b/tests/test_score2.py @@ -26,7 +26,9 @@ ) def test_score2(filename, expected): # Get the actual fixture value using request.getfixturevalue - age, pred_risk, pred_risk_category = compute.cardiovascular_risk(OUT_FILEPATH / filename) + age, pred_risk, pred_risk_category = compute.cardiovascular_risk( + OUT_FILEPATH / filename + ) expected_age, expected_risk, expected_category = expected assert age == expected_age diff --git a/vitals/biomarkers/helpers.py b/vitals/biomarkers/helpers.py index 3580e07..a112320 100755 --- a/vitals/biomarkers/helpers.py +++ b/vitals/biomarkers/helpers.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from pathlib import Path -from typing import Any, Callable, TypeVar +from typing import Any, TypedDict, TypeVar from pydantic import BaseModel @@ -9,6 +10,14 @@ Units = schemas.PhenoageUnits | schemas.Score2Units +class ConversionInfo(TypedDict): + """Type definition for biomarker conversion information.""" + + target_name: str + target_unit: str + conversion: Callable[[float], float] + + def format_unit_suffix(unit: str) -> str: """Convert unit string to a valid suffix format. @@ -85,7 +94,7 @@ def add_converted_biomarkers(biomarkers: dict[str, Any]) -> dict[str, Any]: result = biomarkers.copy() # Conversion mappings - conversions: dict[str, dict[str, str | Callable[[float], float]]] = { + conversions: dict[str, ConversionInfo] = { "glucose_mg_dl": { "target_name": "glucose_mmol_l", "target_unit": "mmol/L", @@ -136,8 +145,8 @@ def add_converted_biomarkers(biomarkers: dict[str, Any]) -> dict[str, Any]: # Skip if target already exists if target_name not in result: - converted_value = conversion_info["conversion"](source_value) # type: ignore - result[target_name] = { # type: ignore + converted_value = conversion_info["conversion"](source_value) + result[target_name] = { "value": round(converted_value, 4), "unit": conversion_info["target_unit"], } diff --git a/vitals/score2/compute.py b/vitals/score2/compute.py index b78d8e0..dc794af 100644 --- a/vitals/score2/compute.py +++ b/vitals/score2/compute.py @@ -131,55 +131,65 @@ def cardiovascular_risk(filepath: str | Path) -> tuple[float, float, RiskCategor coef: ModelCoefficients = ModelCoefficients() # Calculate linear predictor (x) based on sex + + linear_pred: float + baseline_survival: float + scale1: float + scale2: float + if is_male: - x: float = ( - coef.male_age * cage + - coef.male_smoking * smoking + - coef.male_sbp * csbp + - coef.male_total_cholesterol * ctchol + - coef.male_hdl_cholesterol * chdl + - coef.male_smoking_age * smoking_age + - coef.male_sbp_age * sbp_age + - coef.male_tchol_age * tchol_age + - coef.male_hdl_age * hdl_age + linear_pred = ( + coef.male_age * cage + + coef.male_smoking * smoking + + coef.male_sbp * csbp + + coef.male_total_cholesterol * ctchol + + coef.male_hdl_cholesterol * chdl + + coef.male_smoking_age * smoking_age + + coef.male_sbp_age * sbp_age + + coef.male_tchol_age * tchol_age + + coef.male_hdl_age * hdl_age ) - baseline_survival: float = BaselineSurvival().male - scale1: float = CalibrationScales().male_scale1 - scale2: float = CalibrationScales().male_scale2 + baseline_survival = BaselineSurvival().male + scale1 = CalibrationScales().male_scale1 + scale2 = CalibrationScales().male_scale2 else: - x: float = ( - coef.female_age * cage + - coef.female_smoking * smoking + - coef.female_sbp * csbp + - coef.female_total_cholesterol * ctchol + - coef.female_hdl_cholesterol * chdl + - coef.female_smoking_age * smoking_age + - coef.female_sbp_age * sbp_age + - coef.female_tchol_age * tchol_age + - coef.female_hdl_age * hdl_age + linear_pred = ( + coef.female_age * cage + + coef.female_smoking * smoking + + coef.female_sbp * csbp + + coef.female_total_cholesterol * ctchol + + coef.female_hdl_cholesterol * chdl + + coef.female_smoking_age * smoking_age + + coef.female_sbp_age * sbp_age + + coef.female_tchol_age * tchol_age + + coef.female_hdl_age * hdl_age ) - baseline_survival: float = BaselineSurvival().female - scale1: float = CalibrationScales().female_scale1 - scale2: float = CalibrationScales().female_scale2 + baseline_survival = BaselineSurvival().female + scale1 = CalibrationScales().female_scale1 + scale2 = CalibrationScales().female_scale2 # Calculate uncalibrated risk - uncalibrated_risk: float = 1 - np.power(baseline_survival, np.exp(x)) + uncalibrated_risk: float = 1 - np.power(baseline_survival, np.exp(linear_pred)) # Apply calibration for Belgium (Low Risk region) # Calibrated 10-year risk, % = [1 - exp(-exp(scale1 + scale2*ln(-ln(1 - 10-year risk))))] * 100 - calibrated_risk: float = float((1 - np.exp(-np.exp(scale1 + scale2 * np.log(-np.log(1 - uncalibrated_risk))))) * 100) + calibrated_risk: float = float( + (1 - np.exp(-np.exp(scale1 + scale2 * np.log(-np.log(1 - uncalibrated_risk))))) + * 100 + ) # Determine risk category based on age + risk_category: RiskCategory if age < 50: if calibrated_risk < 2.5: - risk_category: RiskCategory = "Low to moderate" + risk_category = "Low to moderate" elif calibrated_risk < 7.5: risk_category = "High" else: risk_category = "Very high" else: # age 50-69 if calibrated_risk < 5: - risk_category: RiskCategory = "Low to moderate" + risk_category = "Low to moderate" elif calibrated_risk < 10: risk_category = "High" else: