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

feat: Configure Report To Select Scores or Raw Scores (CAMHI) (M2-7738) #1935

Merged
merged 34 commits into from
Oct 25, 2024

Conversation

sultanofcardio
Copy link
Contributor

@sultanofcardio sultanofcardio commented Oct 4, 2024

  • Tests for the changes have been added

📝 Description

Note

It may be helpful to look at TL;DR on Subscales, T Scores, and Lookup Tables before reviewing this PR if you're unfamiliar with subscales

🔗 Jira Ticket M2-7738

This PR adds support for linking subscales to report scores, allowing them to use T-Scores from a subscale's lookup table for their calculations.

Note

Only subscales that contain both a lookup table and at least one non-subscale item can be linked to a report score. It is valid for subscales to contain only nested subscales, but those are not valid for linking

To link a subscale to a report score, the admin must first define an eligible subscale, and then indicate the type of score to be used on the report

image

This subscale has non-subscale items and a lookup table

image

Note that the Score Calculation Type and the Items used to calculate score are fixed to match those of the selected subscale and cannot be edited

📸 Screenshots

In addition to the screenshots above, here are some other cases to consider

No eligible subscales

When there are no eligible subscales, the radio group does not appear and the score type is fixed to raw score

image

Raw score by default

When there are eligible subscales, raw score is selected by default and the Score Calculation Type and the Items used to calculate score remain editable

image

Tooltips

Tooltips are included to tell the user about each score type

image image

🪤 Peer Testing

Note

Some scenarios may require the API modifications from ChildMindInstitute/mindlogger-backend-refactor#1616 to be tested

Create an activity and use it to test the following conditions

Hidden by default

  1. Ensure the activity does not contain any eligible subscales
  2. Create a report score
  3. Confirm that the radio group is not visible

Tooltip copy

  1. Create an eligible subscale
  2. Create a report score and set the score type to "Score"
  3. Confirm the copy of each tooltip on the info icons match the acceptance criteria

Default score type

  1. Ensure the activity does not contain any eligible subscales
  2. Create a report score and fill in the required fields
  3. Save the applet
  4. Confirm that the scoringType field in the request body is raw_score
  5. Create an eligible subscale
  6. Confirm that the radio group is now visible on the report score and raw score is selected

Only eligible subscales

  1. Create at least one of each of the following subscales
    • One with a lookup table and non-subscale items (eligible)
    • One with a lookup table and only subscale items (ineligible)
    • One without a lookup table (ineligible)
  2. Create a report score and set the score type to "Score"
  3. Confirm that the subscale dropdown list only contains the eligible subscale

Link to subscales page

  1. Create an eligible subscale
  2. Create a report score and set the score type to "Score"
  3. Select the eligible subscale from the dropdown list
  4. Click the "View Subscale Configuration" button
  5. Confirm navigation to the "Subscales Configuration" screen

Note

The selected subscale can't be directly navigated to, so the one that appears after navigation may be a different one

Score range and items

  1. Create an eligible subscale
  2. Create a report score and set the score type to "Score"
  3. Select the eligible subscale from the dropdown list
  4. Confirm that the Possible Range of Scores is updated to match the min and max scores between the scores on each item and those in the subscale lookup table
  5. Confirm that the Items used to calculate score are no longer editable and match the items in the selected subscale

Linked subscale is saved

  1. Create an eligible subscale
  2. Create a report score and set the score type to "Score"
  3. Select the eligible subscale from the dropdown list
  4. Fill in the rest of the required fields
  5. Save the applet
  6. Confirm that the subscaleName field in the request body contains the name of the selected subscale

Warning

If ChildMindInstitute/mindlogger-backend-refactor#1616 is not yet complete, then the data may not be persisted

Only eligible items

  1. Create an eligible subscale that also contains another subscale
  2. Create a report score and set the score type to "Score"
  3. Select the eligible subscale from the dropdown list
  4. Fill in the rest of the required fields
  5. Save the applet
  6. Confirm that the success banner is shown and the itemsScore field in the request body contains only the name of the non-subscale item(s)

Warning

If ChildMindInstitute/mindlogger-backend-refactor#1616 is not yet complete, then the data may not be persisted

Change propagation

Name change
  1. Create an eligible subscale
  2. Create a report score and set the score type to "Score"
  3. Select the eligible subscale from the dropdown list
  4. Fill in the rest of the required fields
  5. Change the name of the selected subscale
  6. Without navigating away from the subscales configuration screen, Save the applet
  7. Confirm that the subscaleName field in the request body contains the name of the selected subscale

Warning

If ChildMindInstitute/mindlogger-backend-refactor#1616 is not yet complete, then the data may not be persisted

Remove lookup table
  1. Repeat steps 1-4 from the name change scenario
  2. Remove the lookup table from the selected subscale
  3. Without navigating away from the subscales configuration screen, Save the applet
  4. Confirm that an error is shown and the applet fails to be saved
Delete selected subscale
  1. Repeat steps 1-4 from the name change scenario
  2. Delete the selected subscale
  3. Without navigating away from the subscales configuration screen, Save the applet
  4. Confirm that an error is shown and the applet fails to be saved

✏️ Notes

  1. Automated tests have not yet been added to account for the updated page UI
  2. I've updated the onChange prop on the RadioGroupController and the onCustomChange prop in the InputController to accept the original onChange function from react-hook-form as a parameter, so that it may optionally be called by the provider

@sultanofcardio sultanofcardio self-assigned this Oct 4, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-1935.d19gtpld8yi51u.amplifyapp.com

I wrapped this component and forgot to move the key up a level
Apparently MUI doesn't like a default value of `undefined` on the select, so the empty string works while still showing the placeholder
@sultanofcardio sultanofcardio marked this pull request as ready for review October 4, 2024 14:56
Copy link
Contributor

@farmerpaul farmerpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sultanofcardio, I've run through the peer testing so far. All tests pass according to the expectations you've outlined in each of the scenarios, however I did discover a client-side error happening after each of two of these scenarios:

  • Remove lookup table
  • Delete selected subscale

In each of these cases, although I'm correctly led to fix the validation error on the Scores & Reports tab, once I fix it (by selecting a different eligible subscale, for instance), I'm unable to save changes. Clicking Save & Publish after I've addressed this validation error results in this client-side error, and trying to save from then on doesn't seem work until I reload the browser:

CleanShot 2024-10-07 at 14 41 30@2x

@farmerpaul farmerpaul self-requested a review October 7, 2024 17:50
If there are other activities in the applet with existing report scores that don't have a scoringType, they will prevent any updates to the applet. So we must make this field nullable
Subscales can contain other subscales, but we shouldn't include them in the report
@sultanofcardio
Copy link
Contributor Author

Thanks for finding this @farmerpaul 🙏 It should be fixed with c30a70c

Copy link
Contributor

@farmerpaul farmerpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That error is happening less now! However, I can still cause it to happen, but thankfully, it's not related to your work – it's a pre-existing bug reproducible in develop. It seems that when you have a subscale that references another subscale, and you delete the referenced subscale (but not the one that was referencing it) and try to Save & Publish, you get that same TypeError: Cannot read properties of undefined (reading 'name') and you can no longer save your changes. If you think it's too much effort to come up with a fix for this, I'll just log this as a bug in Jira. But if it's a quick fix, would be nice to take care of it.

I had a look through the code and nothing seems off to me, so happy to approve!

Copy link
Contributor

@mbanting mbanting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peer tested this alongside peer testing M2-8097.
Code LGTM. Great job @sultanofcardio

@mbanting mbanting merged commit 2741402 into develop Oct 25, 2024
5 checks passed
mbanting pushed a commit that referenced this pull request Oct 25, 2024
… (#1935)

* Add support for a tooltip icon with a tooltip in the RadioGroupController

* Add radio buttons with hardcoded text

* Update ScoreReport type to include scoreType and linkedSubscaleName

* WIP update to score type selection logic

* Set selected items based on subscale

* Update score range calculation to account for linked subscale

* Exclude subscales with no activity items

* Pass the `onChange` to the `onCustomChange` in the InputController

This allows callers who pass a custom onChange function to this component to receive and optionally invoke the original react-hook-form onChange. This removes the need to invoke `setValue` (or equivalent) manually, which the docs say you should avoid

* Update report score linked subscale name when it is edited on the subscales configuration screen

* Fix type name

* Require linked subscale when report score type is score

* Update the logic that accounts for updates on the subscales configuration screen

This block of code now also manually removes the linked subscale name if it can't be used to find a valid subscale

* Remove the link to a report score if a subscale or its lookup table is deleted

* Translate strings

* Fix broken tests

* Move key prop to parent

I wrapped this component and forgot to move the key up a level

* Fix MUI select warning

Apparently MUI doesn't like a default value of `undefined` on the select, so the empty string works while still showing the placeholder

* Set score type back to raw score if there are no eligible subscales

* Hide the radio group if there are no eligible subscales

* Fix broken test

* Abstract field names

* Rename scoreType to scoringType

* Rename linkedSubscaleName to subscaleName

* Change `rawScore` to `raw_score`

* Make the `scoringType` field nullable

If there are other activities in the applet with existing report scores that don't have a scoringType, they will prevent any updates to the applet. So we must make this field nullable

* Remove the noisy MUI controlled field warning

* Handle the case where the score is undefined

🤷

* Filter out ineligible subscale items

Subscales can contain other subscales, but we shouldn't include them in the report

* Account for existing applets with reports but no subscales

* Account for reports that were saved without an explicit scoring type

* Reset report scores to raw_score if there are no more eligible subscales

* Remove linked subscales from reports when they no longer contain non-subscale items

* Fix score range calculation

* Ignore score ranges

The lookup table parsing allows ranges in the score column, but this is invalid as scores can only be numbers. So I'm updating this code to ignore those until we can update the parsing code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants