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 eligibility to response model - fixes #1292 #1300
Conversation
…ct creation, add/refactor queries, add helper
Questions about this issue: what should the value of the
BTW, these issues revealed themselves in testing because (a) we don't require the birthday field in the Child account model, and (b) the criteria_expression in the Study model doesn't default to an empty string. So if it so happens that we did want to change those things, that might remove the need for handling these cases (except that maybe the researcher can still enter an invalid criteria expression - I'm not sure if there's any validation on that before it's saved). |
There's an issue on this #1285. If you look through the production database, all children have a birthday. This require for a birthday was enforced at the form level and probably should be at the database level. Assuming, we want to require a child to have a birthday.
It my preference to not have an invalid criteria. Can we do a better job of validating the criteria on form submission? For existing invalid criteria, could we signal the researcher in someway? Maybe on the preview child selection view? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a draft, but it seems to make sense. I'll do another review when you're ready.
|
||
class ResponseEligibility(models.TextChoices): | ||
"""Participant eligibility categories for Response model""" | ||
|
||
# This must be determined at the point of the study participation/response, because child eligibility can change over time for a given study | ||
ELIGIBLE = "Eligible" | ||
INELIGIBLE_YOUNG = "Ineligible_TooYoung" | ||
INELIGIBLE_OLD = "Ineligible_TooOld" | ||
INELIGIBLE_CRITERIA = "Ineligible_CriteriaExpression" | ||
INELIGIBLE_PARTICIPATION = "Ineligible_Participation" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextChoices! I should've known about this, very nice.
…nse eligibility migration to include change to Study model
…the necessary validation is handled by the modeland forms. This reverts commit bb4fb0e.
It turns out that we do require a birthday on the Child create form, and we validate the criteria expression on the study create/edit form. I've updated the Child model so that Similarly, I've added a default blank ( |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Couple of comments from Ian on typos, but I think they are in the PR text rather than the codebase: I found a few quick typos:
|
Thanks Melissa and Ian! I checked the codebase and these errors are just in the PR text. Fixed! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! That was a lot of work.
* add eligibility field to Response model/serializer, set value on object creation, add/refactor queries, add helper * add eligibility to the Response fields displayed in admin pages * add eligibility to response columns available for researcher download/display * display eligibility value in details table on individual responses page * alter child birthday field to not allow blank or null * add a default blank value for Study criteria expression, modify response eligibility migration to include change to Study model * fix failing tests: add required birthday to Child instances * add tests for child_in_age_range_for_study_days_difference * add tests for eligibility field, get_eligibility_for_response returns sorted list of eligibility strings
This PR adds a new 'eligibility' field to the Response model. The value is determined when the Response object is first created, and it is a list of one or more strings:
The eligibility value will only be set for newly-created Response objects. Existing responses will have an eligibility field that contains an empty list.
The 'eligibility' field value roughly corresponds to the 'red text' warnings displayed under the "Participate/Preview Now" button, which let the participant know that the selected child is too young/old or does not meet the study criteria. However, there are some minor differences between these:
Examples
Eligible
Participation page:
Data:
Study Responses -> Individual Responses -> Response details:
Ineligible: too young
Participation page:
Data:
Study Responses -> Individual Responses -> Response details:
Ineligible: too old
Ineligible: criteria
Participation page:
Data:
Study Responses -> Individual Responses -> Response details:
Ineligible: multiple reasons
Participation page:
Data:
Study Responses -> Individual Responses -> Response details:
Existing responses
The 'eligibility' column will be present but will contain an empty list.