generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
PPHA-268: Add respiratory conditions #143
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d4b28cc
WIP
miriam-z 89d00de
Add validation to prevent selecting 'None' with other respiratory con…
miriam-z d1ba21e
Fix isinstance() syntax error in test_helpers
miriam-z 4238f0b
Update assertion error text
miriam-z 23ee5b5
Fix broken tests
miriam-z d16ec63
Added test_can_select_multiple_respiratory_conditions() method
miriam-z f5ffc99
Added support for rendering hints on individual radio button choices,…
miriam-z 00b4e70
Remove redundant comment
miriam-z b5dae6a
Remove print statement
miriam-z File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
lung_cancer_screening/core/tests/acceptance/helpers/test_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| def check_labels(page, answers): | ||
| if answers is None: | ||
| return | ||
|
|
||
| if isinstance(answers, str): | ||
| page.get_by_label(answers, exact=True).check() | ||
| return | ||
|
|
||
| if isinstance(answers, (list, tuple)): | ||
| for answer in answers: | ||
| page.get_by_label(answer, exact=True).check() | ||
| return | ||
|
|
||
| raise TypeError("answers must be a string, list, or tuple") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| {% from 'nhsuk/components/checkboxes/macro.jinja' import checkboxes %} | ||
| {% set unbound_field = field.field %} | ||
| {% if field.errors %} | ||
| {% set error_message = {"text": field.errors | first} %} | ||
| {% endif %} | ||
| {% set ns = namespace(items=[]) %} | ||
| {% for value, text in unbound_field.choices %} | ||
| {% set hint_text = field.get_hint_for_choice(value) %} | ||
| {% set ns.items = ns.items + [{ | ||
| "id": field.auto_id ~ '_' ~ loop.index0, | ||
| "value": value, | ||
| "text": text, | ||
| "checked": value in (field.value() or []), | ||
| "hint": { | ||
| "text": hint_text | ||
| } if hint_text else undefined | ||
| }] %} | ||
| {% set divider = field.get_divider_after(value) %} | ||
| {% if divider %} | ||
| {% set ns.items = ns.items + [{"divider": divider}] %} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {{ checkboxes({ | ||
| "name": field.html_name, | ||
| "idPrefix": field.auto_id, | ||
| "fieldset": { | ||
| "legend": { | ||
| "text": field.label, | ||
| "classes": unbound_field.label_classes | ||
| } | ||
| } if field.use_fieldset else none, | ||
| "errorMessage": error_message, | ||
| "classes": unbound_field.classes if unbound_field.classes, | ||
| "hint": { | ||
| "html": unbound_field.hint|e | ||
| } if unbound_field.hint, | ||
| "items": ns.items | ||
| }) }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
lung_cancer_screening/questions/forms/respiratory_conditions_form.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from django import forms | ||
|
|
||
| from ...nhsuk_forms.choice_field import MultipleChoiceField | ||
| from ..models.response_set import ResponseSet, RespiratoryConditionValues | ||
|
|
||
|
|
||
| class RespiratoryConditionsForm(forms.ModelForm): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| self.participant = kwargs.pop('participant') | ||
| super().__init__(*args, **kwargs) | ||
| self.instance.participant = self.participant | ||
|
|
||
| self.fields["respiratory_conditions"] = MultipleChoiceField( | ||
| choices=RespiratoryConditionValues.choices, | ||
| widget=forms.CheckboxSelectMultiple, | ||
| label="Have you ever been diagnosed with any of the following respiratory conditions?", | ||
| label_classes="nhsuk-fieldset__legend--l", | ||
| hint="Select all that apply", | ||
| error_messages={ | ||
| 'required': 'Select if you have had any respiratory conditions', | ||
| 'singleton_option': 'Select if you have had any respiratory conditions, or select \'No, I have not had any of these respiratory conditions\'' | ||
| } | ||
| ) | ||
|
|
||
| # Add hints for each choice | ||
| respiratory_conditions_field = self["respiratory_conditions"] | ||
| respiratory_conditions_field.add_hint_for_choice( | ||
| RespiratoryConditionValues.PNEUMONIA, | ||
| "An infection of the lungs, usually diagnosed by a chest x-ray" | ||
| ) | ||
| respiratory_conditions_field.add_hint_for_choice( | ||
| RespiratoryConditionValues.EMPHYSEMA, | ||
| "Damage to the air sacs in the lungs" | ||
| ) | ||
| respiratory_conditions_field.add_hint_for_choice( | ||
| RespiratoryConditionValues.BRONCHITIS, | ||
| "An ongoing inflammation of the airways in the lungs that is usually caused by an infection" | ||
| ) | ||
| respiratory_conditions_field.add_hint_for_choice( | ||
| RespiratoryConditionValues.TUBERCULOSIS, | ||
| "An infection that usually affects the lungs, but can affect any part of the body" | ||
| ) | ||
| respiratory_conditions_field.add_hint_for_choice( | ||
| RespiratoryConditionValues.COPD, | ||
| "A group of lung conditions that cause breathing difficulties" | ||
| ) | ||
|
|
||
| # Add divider before "None of the above" | ||
| respiratory_conditions_field.add_divider_after( | ||
| RespiratoryConditionValues.COPD, | ||
| "or" | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = ResponseSet | ||
| fields = ['respiratory_conditions'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.