Skip to content

Commit 8f2c423

Browse files
committed
PPHA-528: Age when started smoking page
1 parent 80b8d2e commit 8f2c423

21 files changed

Lines changed: 454 additions & 10 deletions

features/questionnaire.feature

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@AgeWhenStartedSmoking
12
Feature: Questionnaire
23
Scenario: Cannot change responses once submitted
34
Given I am logged in
@@ -40,7 +41,6 @@ Feature: Questionnaire
4041
Then I am on "/education"
4142
When I fill in and submit my education with "A-levels"
4243

43-
4444
Then I am on "/respiratory-conditions"
4545
When I fill in and submit my respiratory conditions with "Pneumonia" and "Emphysema"
4646

@@ -56,8 +56,11 @@ Feature: Questionnaire
5656
Then I am on "/relatives-age-when-diagnosed"
5757
When I fill in and submit my relatives age when diagnosed with "Yes, they were younger than 60"
5858

59+
Then I am on "/age-when-started-smoking"
60+
When I fill in "How old were you when you started smoking?" as "18" and submit
61+
5962
Then I am on "/check-your-answers"
60-
And I see a back link to "/relatives-age-when-diagnosed"
63+
And I see a back link to "/age-when-started-smoking"
6164

6265
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
6366
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"

features/relatives_age_when_diagnosed.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ Feature: Relatives age when diagnosed page
1717
And I see a form error "Select if your relatives were younger than 60 when they were diagnosed with lung cancer"
1818
And there are no accessibility violations
1919

20+
@AgeWhenStartedSmoking
2021
Scenario: Navigating backwards and forwards
2122
Given I am logged in
2223
When I go to "/family-history-lung-cancer"
2324
And I fill in and submit my family history lung cancer with "Yes"
2425
Then I am on "/relatives-age-when-diagnosed"
2526
And I see a back link to "/family-history-lung-cancer"
2627
When I fill in and submit my relatives age when diagnosed with "Yes, they were younger than 60"
27-
Then I am on "/check-your-answers"
28+
Then I am on "/age-when-started-smoking"
2829

2930
Scenario: Redirecting if they have no family history of lung cancer
3031
Given I am logged in

features/steps/form_steps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ def when_i_check_value_and_submit(context, value):
99
context.page.get_by_label(value, exact=True).check()
1010
when_i_submit_the_form(context)
1111

12+
@when("I fill in \"{field}\" as \"{value}\" and submit")
13+
def when_i_enter_value_and_submit(context, field, value):
14+
context.page.get_by_label(field).fill(value)
15+
when_i_submit_the_form(context)
16+
1217
@when("I take a screenshot")
1318
@when("I take a screenshot {value}")
1419
def screenshot(context, value=""):

lung_cancer_screening/nhsuk_forms/integer_field.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ def __init__(
77
*args,
88
hint=None,
99
label_classes=None,
10+
label_is_page_heading=False,
1011
classes=None,
1112
**kwargs,
1213
):
1314
kwargs["template_name"] = "input.jinja"
1415

1516
self.suffix = kwargs.pop("suffix", None)
17+
self.prefix = kwargs.pop("prefix", None)
1618
self.hint = hint
1719
self.classes = classes
1820
self.label_classes = label_classes
21+
self.label_is_page_heading = label_is_page_heading
1922

2023
super().__init__(*args, **kwargs)
2124

lung_cancer_screening/nhsuk_forms/jinja2/input.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
"label": {
1111
"text": field.label,
1212
"html": label_html if label_html,
13-
"classes": unbound_field.label_classes if unbound_field.label_classes
13+
"classes": unbound_field.label_classes if unbound_field.label_classes,
14+
"isPageHeading": unbound_field.label_is_page_heading if unbound_field.label_is_page_heading
1415
},
1516
"hint": {
1617
"text": unbound_field.hint
1718
} if unbound_field.hint,
1819
"suffix": unbound_field.suffix if unbound_field.suffix,
20+
"prefix": unbound_field.prefix if unbound_field.prefix,
1921
"id": field.auto_id,
2022
"name": field.html_name,
2123
"value": field.value() or "",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django import forms
2+
from ...nhsuk_forms.integer_field import IntegerField
3+
from ..models.age_when_started_smoking_response import AgeWhenStartedSmokingResponse
4+
5+
6+
class AgeWhenStartedSmokingForm(forms.ModelForm):
7+
def __init__(self, *args, **kwargs):
8+
super().__init__(*args, **kwargs)
9+
10+
self.fields["value"] = IntegerField(
11+
label="How old were you when you started smoking?",
12+
label_classes="nhsuk-fieldset__legend--l",
13+
label_is_page_heading=True,
14+
classes="nhsuk-input--width-2",
15+
hint="Give an estimate if you are not sure",
16+
prefix="Age",
17+
error_messages={
18+
'required': 'Enter your age when you started smoking',
19+
'invalid': 'Enter your age when you started smoking',
20+
'zero_entered':'The age you started smoking must be between 1 and your current age',
21+
'old_current_age':'The age you started smoking must be the same as, or younger than your current age'
22+
}
23+
)
24+
25+
class Meta:
26+
model = AgeWhenStartedSmokingResponse
27+
fields = ['value']

lung_cancer_screening/questions/forms/metric_height_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, *args, **kwargs):
1616
self.fields["metric"] = DecimalField(
1717
decimal_places=1,
1818
label="Centimetres",
19-
classes="nhsuk-input--width-4",
19+
classes="nhsuk-input--width-2",
2020
error_messages={
2121
'required': 'Enter your height',
2222
"max_decimal_places": (
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 5.2.10 on 2026-01-15 08:59
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('questions', '0042_alter_educationresponse_value'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='AgeWhenStartedSmokingResponse',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('created_at', models.DateTimeField(auto_now_add=True)),
19+
('updated_at', models.DateTimeField(auto_now=True)),
20+
('value', models.PositiveIntegerField()),
21+
('response_set', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='age_when_started_smoking_response', to='questions.responseset')),
22+
],
23+
options={
24+
'abstract': False,
25+
},
26+
),
27+
]

lung_cancer_screening/questions/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .response_set import ResponseSet # noqa: F401
33
from .user import User # noqa: F401
44

5+
from .age_when_started_smoking_response import AgeWhenStartedSmokingResponse # noqa: F401
56
from .asbestos_exposure_response import AsbestosExposureResponse # noqa: F401
67
from .cancer_diagnosis_response import CancerDiagnosisResponse # noqa: F401
78
from .check_need_appointment_response import CheckNeedAppointmentResponse # noqa: F401
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
3+
from django.db import models
4+
from django.forms import ValidationError
5+
from django.utils import timezone
6+
7+
from .base import BaseModel
8+
from .response_set import ResponseSet
9+
10+
from django.core.validators import MaxValueValidator, MinValueValidator
11+
12+
13+
14+
# def validate_less_than_age(self, value):
15+
# print(f"self : {self}")
16+
# print(f"value : {self.value}")
17+
# print("what")
18+
# print(f"dob : {self.response_set.date_of_birth}")
19+
# print(hasattr(self.response_set, "date_of_birth"))
20+
# if hasattr(self.response_set, "date_of_birth") :
21+
# if value < self.get_age :
22+
# raise ValidationError(
23+
# "Must be less than your age",
24+
# code="less_than_age",
25+
# )
26+
27+
class AgeWhenStartedSmokingResponse(BaseModel):
28+
response_set = models.OneToOneField(ResponseSet, on_delete=models.CASCADE, related_name='age_when_started_smoking_response')
29+
value = models.PositiveIntegerField(validators=[
30+
MinValueValidator(1, message="The age you started smoking must be between 1 and your current age"),
31+
# validate_less_than_age
32+
]
33+
)
34+
35+
# def clean(self):
36+
# super().clean()
37+
# print(f"clean 1:{self.response_set}")
38+
# if hasattr(self.response_set, "date_of_birth_response") :
39+
# print(f"clean 2:{self.response_set.date_of_birth_response.value}")
40+
# today = timezone.now()
41+
# born = self.response_set.date_of_birth_response.value
42+
# age = today.year - born.year - ((today.month, today.day) < (born.month, born.day))
43+
# print(f"value : {self.value}")
44+
# print(f"Age {age}")
45+
# if (self.value and self.value < age):
46+
# raise ValidationError(
47+
# "The age you started smoking must be the same as, or younger than your current age"
48+
# )
49+
#if submitted_response_sets_in_last_year:
50+
# raise ValidationError(
51+
# "Responses have already been submitted for this user"
52+
# )
53+

0 commit comments

Comments
 (0)