generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
PPHA-529: Add smoked total years for cigarettes smoking type #250
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
2 commits
Select commit
Hold shift + click to select a range
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
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,50 @@ | ||
| @SmokedTotalYears | ||
| Feature: Smoked total years page | ||
| Scenario: The page is accessible | ||
| Given I am logged in | ||
| And I have answered questions showing I am eligible | ||
| And I have answered questions showing I have smoked for "10" years | ||
| And I have answered questions showing I have smoked "Cigarettes" | ||
| When I go to "/cigarettes-smoked-total-years" | ||
| Then there are no accessibility violations | ||
|
|
||
| Scenario: Form errors | ||
| Given I am logged in | ||
| And I have answered questions showing I am eligible | ||
| And I have answered questions showing I have smoked for "10" years | ||
| And I have answered questions showing I have smoked "Cigarettes" | ||
| When I go to "/cigarettes-smoked-total-years" | ||
| And I click "Continue" | ||
| Then I am on "/cigarettes-smoked-total-years" | ||
| And I see a form error "Enter the number of years you have smoked cigarettes" | ||
| And there are no accessibility violations | ||
|
|
||
| Scenario: Navigating backwards and forwards | ||
| Given I am logged in | ||
| And I have answered questions showing I am eligible | ||
| And I have answered questions showing I have smoked for "10" years | ||
| And I have answered questions showing I have smoked "Cigarettes" | ||
| When I go to "/cigarettes-smoked-total-years" | ||
| Then I see a back link to "/types-tobacco-smoking" | ||
| When I fill in "Roughly how many years have you smoked cigarettes?" with "9" | ||
| And I submit the form | ||
| Then I am on "/check-your-answers" | ||
|
|
||
| Scenario: Checking responses and changing them | ||
| Given I am logged in | ||
| And I have answered questions showing I am eligible | ||
| And I have answered questions showing I have smoked for "10" years | ||
| And I have answered questions showing I have smoked "Cigarettes" | ||
| When I go to "/cigarettes-smoked-total-years" | ||
| When I fill in "Roughly how many years have you smoked cigarettes?" with "9" | ||
| And I submit the form | ||
| When I go to "/check-your-answers" | ||
| Then I see "9" as a response to "Total number of years you have smoked cigarettes" under "Smoking history" | ||
| And I see "/cigarettes-smoked-total-years?change=True" as a link to change "Total number of years you have smoked cigarettes" under "Smoking history" | ||
| When I click the link to change "Total number of years you have smoked cigarettes" under "Smoking history" | ||
| Then I am on "/cigarettes-smoked-total-years?change=True" | ||
| And I see "9" filled in for "Roughly how many years have you smoked cigarettes?" | ||
| When I fill in "Roughly how many years have you smoked cigarettes?" with "8" | ||
| And I click "Continue" | ||
| Then I am on "/check-your-answers" | ||
| And I see "8" as a response to "Total number of years you have smoked cigarettes" under "Smoking history" |
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
28 changes: 28 additions & 0 deletions
28
lung_cancer_screening/questions/forms/smoked_total_years_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,28 @@ | ||
| from django import forms | ||
|
|
||
| from ...nhsuk_forms.integer_field import IntegerField | ||
| from ..models.smoked_total_years_response import SmokedTotalYearsResponse | ||
|
|
||
|
|
||
| class SmokedTotalYearsForm(forms.ModelForm): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| self.fields["value"] = IntegerField( | ||
| label="Roughly how many years have you smoked cigarettes?", | ||
| label_is_page_heading=True, | ||
| label_classes="nhsuk-label--l", | ||
| classes="nhsuk-input--width-4", | ||
| hint="Give an estimate if you are not sure", | ||
| required=True, | ||
| suffix="years", | ||
| error_messages={ | ||
| "required": "Enter the number of years you have smoked cigarettes", | ||
| "invalid": "Years must be in whole numbers" | ||
| }, | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = SmokedTotalYearsResponse | ||
| fields = ['value'] | ||
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
40 changes: 40 additions & 0 deletions
40
lung_cancer_screening/questions/migrations/0049_smokedtotalyearsresponse_and_more.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,40 @@ | ||
| # Generated by Django 5.2.10 on 2026-01-28 15:38 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('questions', '0048_tobaccosmokinghistory_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='SmokedTotalYearsResponse', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('updated_at', models.DateTimeField(auto_now=True)), | ||
| ('value', models.IntegerField()), | ||
| ], | ||
| options={ | ||
| 'abstract': False, | ||
| }, | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='tobaccosmokinghistory', | ||
| name='response_set', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tobacco_smoking_history', to='questions.responseset'), | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name='tobaccosmokinghistory', | ||
| constraint=models.UniqueConstraint(fields=('response_set', 'type'), name='unique_tobacco_smoking_history_per_response_set', violation_error_message='A tobacco smoking history already exists for this response set and type'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='smokedtotalyearsresponse', | ||
| name='tobacco_smoking_history', | ||
| field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='smoked_total_years_response', to='questions.tobaccosmokinghistory'), | ||
| ), | ||
| ] |
48 changes: 48 additions & 0 deletions
48
lung_cancer_screening/questions/models/smoked_total_years_response.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,48 @@ | ||
| from django.db import models | ||
| from django.core.exceptions import ValidationError | ||
| from django.core.validators import MinValueValidator | ||
|
|
||
| from .base import BaseModel | ||
| from .tobacco_smoking_history import TobaccoSmokingHistory | ||
|
|
||
|
|
||
| class SmokedTotalYearsResponse(BaseModel): | ||
| tobacco_smoking_history = models.OneToOneField( | ||
| TobaccoSmokingHistory, | ||
| on_delete=models.CASCADE, | ||
| related_name='smoked_total_years_response' | ||
| ) | ||
|
|
||
| value = models.IntegerField( | ||
| validators=[ | ||
| MinValueValidator(1, message="The number of years you smoked cigarettes must be at least 1") | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| def clean(self): | ||
| super().clean() | ||
| self._validate_age_when_started_smoking_response_exists() | ||
| self._validate_value_fewer_than_total_number_of_years_smoked() | ||
|
|
||
|
|
||
| def _validate_age_when_started_smoking_response_exists(self): | ||
| if not hasattr(self.tobacco_smoking_history.response_set, 'age_when_started_smoking_response'): | ||
| raise ValidationError({ | ||
| "value": ValidationError( | ||
| "You must answer age when started smoking before answering how many years you have smoked cigarettes", | ||
| code="age_when_started_smoking_response_not_found" | ||
| ) | ||
| }) | ||
|
|
||
| def _validate_value_fewer_than_total_number_of_years_smoked(self): | ||
| if not self.value: | ||
| return None | ||
|
|
||
| if self.value > self.tobacco_smoking_history.response_set.age_when_started_smoking_response.years_smoked_including_stopped(): | ||
| raise ValidationError({ | ||
| "value": ValidationError( | ||
| "The number of years you smoked cigarettes must be fewer than the total number of years you have been smoking", | ||
| code="value_greater_than_total_number_of_years_smoked" | ||
| ) | ||
| }) |
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
12 changes: 12 additions & 0 deletions
12
lung_cancer_screening/questions/tests/factories/smoked_total_years_response_factory.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,12 @@ | ||
| import factory | ||
|
|
||
| from .tobacco_smoking_history_factory import TobaccoSmokingHistoryFactory | ||
| from ...models.smoked_total_years_response import SmokedTotalYearsResponse | ||
|
|
||
|
|
||
| class SmokedTotalYearsResponseFactory(factory.django.DjangoModelFactory): | ||
| class Meta: | ||
| model = SmokedTotalYearsResponse | ||
|
|
||
| tobacco_smoking_history = factory.SubFactory(TobaccoSmokingHistoryFactory) | ||
| value = 1 |
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.