Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add phq-8 #12

Merged
merged 1 commit into from
Oct 14, 2024
Merged

add phq-8 #12

merged 1 commit into from
Oct 14, 2024

Conversation

sharlotta93
Copy link
Contributor

@sharlotta93 sharlotta93 commented Oct 14, 2024

User description

add phq-8


PR Type

enhancement, tests, documentation


Description

  • Integrated PHQ-8 into the calculation library, allowing it to be used alongside other calculations.
  • Defined the input questions, output structure, and interpretation table for PHQ-8.
  • Implemented the calculation logic for PHQ-8, including score computation and interpretation.
  • Added comprehensive unit tests for PHQ-8, covering various response scenarios and validation checks.
  • Corrected a test in PHQ-9 to ensure accurate interpretation of severe depression.
  • Provided documentation for PHQ-8, detailing its purpose, calculation method, and interpretation guidelines.

Changes walkthrough 📝

Relevant files
Enhancement
6 files
calculation_library.ts
Integrate PHQ-8 into calculation library                                 

src/calculation_suite/calculations/calculation_library.ts

  • Added import for phq_8.
  • Included phq_8 in the CALCULATIONS export.
  • +2/-0     
    index.ts
    Export PHQ-8 definitions                                                                 

    src/calculation_suite/calculations/phq_8/definition/index.ts

    • Exported PHQ-8 inputs, output, and interpretation table.
    +3/-0     
    phq8_interpretation.ts
    Define PHQ-8 interpretation table                                               

    src/calculation_suite/calculations/phq_8/definition/phq8_interpretation.ts

    • Defined interpretation table for PHQ-8 scores.
    +36/-0   
    phq_8_inputs.ts
    Define PHQ-8 input questions and answers                                 

    src/calculation_suite/calculations/phq_8/definition/phq_8_inputs.ts

    • Defined input questions and allowed answers for PHQ-8.
    +252/-0 
    phq_8_output.ts
    Define PHQ-8 output structure                                                       

    src/calculation_suite/calculations/phq_8/definition/phq_8_output.ts

    • Defined output structure for PHQ-8 calculation results.
    +14/-0   
    phq_8.ts
    Implement PHQ-8 calculation logic                                               

    src/calculation_suite/calculations/phq_8/phq_8.ts

  • Implemented PHQ-8 calculation logic.
  • Included score calculation and interpretation.
  • +62/-0   
    Tests
    2 files
    phq_8_test_responses.ts
    Add test data for PHQ-8 responses                                               

    src/calculation_suite/calculations/phq_8/testdata/phq_8_test_responses.ts

    • Added test data for best, worst, and random responses for PHQ-8.
    +35/-0   
    phq_8.test.ts
    Add unit tests for PHQ-8 calculation                                         

    src/calculation_suite/calculations/phq_8/phq_8.test.ts

  • Added unit tests for PHQ-8 calculation.
  • Tested various response scenarios and validation.
  • +148/-0 
    Bug fix
    1 files
    phq_9.test.ts
    Fix PHQ-9 test for severe depression interpretation           

    src/calculation_suite/calculations/phq_9/phq_9.test.ts

  • Corrected test expectation for PHQ-9 severe depression interpretation.

  • +1/-1     
    Documentation
    1 files
    README.md
    Add documentation for PHQ-8                                                           

    src/calculation_suite/calculations/phq_8/README.md

  • Added documentation for PHQ-8 including introduction, calculation, and
    interpretation.
  • +24/-0   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request tests Review effort [1-5]: 3 labels Oct 14, 2024
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    Ensure that the calculation handles cases where input values are not strictly numeric or are out of the expected range, as this could lead to incorrect scoring or application crashes.

    Typo in Variable Name
    The variable 'PHQ8_INTERPRATION_TABLE' should be renamed to 'PHQ8_INTERPRETATION_TABLE' to correct the typo and maintain consistency.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a fallback for missing entries in PHQ8_INTERPRATION_TABLE to handle unexpected scores gracefully

    Ensure that the calculate_score function handles cases where PHQ8_INTERPRATION_TABLE
    does not have an entry for the calculated score, to avoid potential runtime errors.

    src/calculation_suite/calculations/phq_8/phq_8.ts [35-45]

     const total_score = R.sum(valid_inputs);
    +const interpretation = PHQ8_INTERPRATION_TABLE[total_score.toString()] || 'Unknown';
     return [
       {
         id: 'PHQ8_SCORE',
         score: total_score,
       },
       {
         id: 'PHQ8_INTERPRETATION',
    -    score: PHQ8_INTERPRATION_TABLE[total_score.toString()],
    +    score: interpretation,
       },
     ];
    Suggestion importance[1-10]: 8

    Why: Adding a fallback for missing entries in PHQ8_INTERPRATION_TABLE is crucial to prevent runtime errors, ensuring the application handles unexpected scores gracefully and maintains robustness.

    8
    Enhancement
    Change the key type in PHQ8_INTERPRATION_TABLE from string to number for direct numeric access

    Consider using a numeric type for the keys in the PHQ8_INTERPRATION_TABLE to avoid
    the need to convert scores to strings when looking up interpretations.

    src/calculation_suite/calculations/phq_8/definition/phq8_interpretation.ts [8-36]

     export const PHQ8_INTERPRATION_TABLE: {
    -  [key in string]: DepressionSeverityType
    +  [key: number]: DepressionSeverityType
     } = {
    -  '0': 'None/minimal depression',
    +  0: 'None/minimal depression',
       ...
     }
    Suggestion importance[1-10]: 7

    Why: Changing the key type from string to number in PHQ8_INTERPRATION_TABLE improves code clarity and avoids unnecessary string conversion, enhancing performance and maintainability.

    7
    Best practice
    Add validation for allowed_answers values to ensure they are within the expected range

    Consider adding validation to ensure that the value fields in allowed_answers are
    within the expected range (0-3) to prevent configuration errors.

    src/calculation_suite/calculations/phq_8/definition/phq_8_inputs.ts [12-32]

     allowed_answers: [
       {
         label: { en: 'Not at all', nl: 'Helemaal niet' },
         value: 0,
       },
       ...
    -],
    +].map(answer => {
    +  if (answer.value < 0 || answer.value > 3) throw new Error('Invalid answer value');
    +  return answer;
    +}),
    Suggestion importance[1-10]: 7

    Why: Adding validation for allowed_answers values ensures data integrity and prevents configuration errors, enhancing the reliability of the input data handling.

    7
    Maintainability
    Refactor repeated input_type structures into a shared constant or function to enhance code maintainability

    Refactor the repeated structure of input_type across different inputs to a function
    or constant to reduce code duplication and improve maintainability.

    src/calculation_suite/calculations/phq_8/definition/phq_8_inputs.ts [10-32]

    -input_type: {
    +const defaultInputType = {
       type: 'number',
       allowed_answers: [
         {
           label: { en: 'Not at all', nl: 'Helemaal niet' },
           value: 0,
         },
         ...
       ],
    -},
    +};
    +input_type: defaultInputType,
    Suggestion importance[1-10]: 6

    Why: Refactoring repeated input_type structures into a shared constant reduces code duplication, improving maintainability and readability, though it does not address any critical issues.

    6

    @bejoinka bejoinka merged commit 5b2cf05 into main Oct 14, 2024
    2 checks passed
    @bejoinka bejoinka deleted the TP-2534-add-phq-8 branch October 14, 2024 13:47
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3 tests
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants