Skip to content

Commit d3a34c2

Browse files
authored
Merge pull request #241 from NHSDigital/PPHA-525-periods-when-you-stopped-smoking
PPHA-525: Add Periods when you stopped smoking page
2 parents 503e30d + 2756bae commit d3a34c2

37 files changed

Lines changed: 830 additions & 59 deletions

.gitleaksignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ infrastructure/bootstrap/main.bicep:generic-api-key:32
2929
infrastructure/bootstrap/modules/storage.bicep:generic-api-key:59
3030
infrastructure/bootstrap/modules/keyVault.bicep:generic-api-key:10
3131
infrastructure/bootstrap/modules/storage.bicep:generic-api-key:59
32-
infrastructure/terraform/hub/data.tf:generic-api-key:18
33-
infrastructure/terraform/hub/data.tf:generic-api-key:22
32+
infrastructure/terraform/hub/data.tf:generic-api-key:19
33+
infrastructure/terraform/hub/data.tf:generic-api-key:23
3434
infrastructure/terraform/resource_group_init/core.bicep:generic-api-key:11
3535
infrastructure/terraform/resource_group_init/keyVault.bicep:generic-api-key:10
3636
infrastructure/terraform/resource_group_init/main.bicep:generic-api-key:30
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@startuml
2+
3+
actor "Participant" as Participant
4+
entity "LCS App" as LCS_App
5+
entity "NHS Login" as NHS_Login
6+
entity "In Health" as InHealth
7+
entity "NHS Incentivisation system" as NHS_Incentivisation_System
8+
9+
' Date flow into LCS App
10+
Participant -> LCS_App
11+
LCS_App -> NHS_Login
12+
NHS_Login -> LCS_App: Participant logs in and shares profile, email address and NHS Number (scopes "openid profile email") with LCS app
13+
Participant -> LCS_App: Completes questionnaire
14+
15+
' Data flow from LCS App to In Health
16+
LCS_App -> InHealth: Completed digital participant NHS Numbers shared with InHealth
17+
InHealth -> LCS_App: InHealth share completed telephone responses corresponding to digital NHS number responses
18+
19+
' Data flow from LCS App to NHS Incentivisation system
20+
LCS_App -> NHS_Incentivisation_System: Eligible participant's email addresses shared with NHS Incentivisation system
21+
NHS_Incentivisation_System -> Participant: Participant is incentivised
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@startuml
2+
3+
entity "In Health" as InHealth
4+
actor "Participant" as Participant
5+
entity "LCS App" as LCS_App
6+
entity "NHS Login" as NHS_Login
7+
entity "NHS Incentivisation system" as NHS_Incentivisation_System
8+
9+
' Participant flow
10+
InHealth -> Participant: Initial contact via letter or SMS
11+
Participant -> LCS_App
12+
LCS_App -> NHS_Login: Participant clicks start and is redirected to NHS Login
13+
NHS_Login -> LCS_App: NHS Login shares profile, email address and NHS Number (scopes "openid profile email")
14+
Participant -> LCS_App: Completes questionnaire and submits
15+
16+
' In Health flow
17+
LCS_App -> InHealth: Completed digital participant NHS Numbers shared with InHealth
18+
InHealth -> LCS_App: In Health shared completed telephone responses corresponding to digital NHS number responses
19+
LCS_App -> NHS_Incentivisation_System: Eligible participant's email addresses shared with NHS Incentivisation system
20+
NHS_Incentivisation_System -> Participant: Participant is incentivised

features/age_when_started_smoking.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Feature: Age when started smoking
2626
When I go to "/age-when-started-smoking"
2727
Then I see a back link to "/relatives-age-when-diagnosed"
2828
When I fill in "How old were you when you started smoking?" as "18" and submit
29-
Then I am on "/check-your-answers"
29+
Then I am on "/periods-when-you-stopped-smoking"
3030

3131
Scenario: Checking responses and changing them
3232
Given I am logged in
@@ -40,5 +40,4 @@ Feature: Age when started smoking
4040
Then I am on "/age-when-started-smoking?change=True"
4141
And I see "18" filled in for "How old were you when you started smoking?"
4242
When I fill in "How old were you when you started smoking?" as "22" and submit
43-
Then I am on "/check-your-answers"
44-
And I see "22" as a response to "Age you started smoking" under "Smoking history"
43+
Then I am on "/periods-when-you-stopped-smoking?change=True"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@PeriodsWhenYouStoppedSmoking
2+
Feature: Periods when you stopped smoking page
3+
Scenario: The page is accessible
4+
Given I am logged in
5+
And I have answered questions showing I am eligible
6+
When I go to "/periods-when-you-stopped-smoking"
7+
# TODO: problem with aria expanded from nhsuk frontend
8+
# Then there are no accessibility violations
9+
10+
Scenario: Form errors
11+
Given I am logged in
12+
And I have answered questions showing I am eligible
13+
When I go to "/periods-when-you-stopped-smoking"
14+
When I submit the form
15+
Then I am on "/periods-when-you-stopped-smoking"
16+
And I see a form error "Select if you ever stopped smoking for periods of 1 year or longer"
17+
# TODO: problem with aria expanded from nhsuk frontend
18+
# And there are no accessibility violations
19+
20+
Scenario: Navigating backwards and forwards
21+
Given I am logged in
22+
And I have answered questions showing I am eligible
23+
And I have answered questions showing I have smoked for "10" years
24+
When I go to "/periods-when-you-stopped-smoking"
25+
Then I see a back link to "/age-when-started-smoking"
26+
When I check "Yes"
27+
And I fill in "Enter the total number of years you stopped smoking for" with "1"
28+
And I submit the form
29+
Then I am on "/check-your-answers"
30+
31+
Scenario: Checking responses and changing them
32+
Given I am logged in
33+
And I have answered questions showing I am eligible
34+
And I have answered questions showing I have smoked for "10" years
35+
When I go to "/periods-when-you-stopped-smoking"
36+
And I check "Yes"
37+
And I fill in "Enter the total number of years you stopped smoking for" with "1"
38+
And I submit the form
39+
When I go to "/check-your-answers"
40+
Then I see "Yes (1 years)" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
41+
And I see "/periods-when-you-stopped-smoking?change=True" as a link to change "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
42+
When I click the link to change "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
43+
Then I am on "/periods-when-you-stopped-smoking?change=True"
44+
And I see "Yes" selected
45+
When I check "No"
46+
And I submit the form
47+
Then I am on "/check-your-answers"
48+
And I see "No" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"

features/questionnaire.feature

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ Feature: Questionnaire
5959
Then I am on "/age-when-started-smoking"
6060
When I fill in "How old were you when you started smoking?" as "18" and submit
6161

62+
63+
Then I am on "/periods-when-you-stopped-smoking"
64+
When I check "Yes"
65+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
66+
And I submit the form
67+
6268
Then I am on "/check-your-answers"
63-
And I see a back link to "/age-when-started-smoking"
69+
And I see a back link to "/periods-when-you-stopped-smoking"
6470

6571
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
6672
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"
@@ -78,5 +84,8 @@ Feature: Questionnaire
7884
And I see "Yes" as a response to "Have any of your parents, siblings or children ever been diagnosed with lung cancer?" under "Family history"
7985
And I see "Yes, they were younger than 60" as a response to "Were any of your relatives younger than 60 years old when they were diagnosed with lung cancer?" under "Family history"
8086

87+
And I see "18" as a response to "Age you started smoking" under "Smoking history"
88+
And I see "Yes (10 years)" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
89+
8190
When I click "Submit"
8291
Then I am on "/confirmation"

features/steps/form_steps.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def when_i_fill_in_and_submit_my_cancer_diagnosis(context, relatives_age_when_di
110110
context.page.get_by_label(relatives_age_when_diagnosed, exact=True).check()
111111
when_i_submit_the_form(context)
112112

113+
@when(u'I fill in and submit my periods when you stopped smoking with "{periods_when_you_stopped_smoking}"')
114+
def when_i_fill_in_and_submit_my_periods_when_you_stopped_smoking(context, periods_when_you_stopped_smoking):
115+
context.page.get_by_label(periods_when_you_stopped_smoking, exact=True).check()
116+
when_i_submit_the_form(context)
117+
113118
@when('I submit the form')
114119
def when_i_submit_the_form(context):
115120
when_i_click(context, "Continue")
@@ -134,3 +139,8 @@ def then_i_see_value_filled_in_for_label(context, value, label):
134139
@when('I check "{label}"')
135140
def when_i_check_label(context, label):
136141
context.page.get_by_label(label, exact=True).check()
142+
143+
144+
@when('I fill in "{label}" with "{value}"')
145+
def when_i_fill_in_label_with_value(context, label, value):
146+
context.page.get_by_label(label, exact=True).fill(value)

features/steps/preflight_steps.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
from behave import given
2-
from datetime import datetime
3-
from dateutil.relativedelta import relativedelta
2+
3+
from features.steps.form_steps import (
4+
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago,
5+
when_i_submit_the_form,
6+
when_i_check_label,
7+
when_i_fill_in_label_with_value
8+
)
9+
410
from lung_cancer_screening.questions.tests.factories.have_you_ever_smoked_response_factory import (
511
ResponseSetFactory,
612
)
713
from lung_cancer_screening.questions.tests.factories.have_you_ever_smoked_response_factory import (
814
HaveYouEverSmokedResponseFactory,
915
)
10-
from lung_cancer_screening.questions.models.have_you_ever_smoked_response import (
11-
HaveYouEverSmokedValues,
12-
)
1316
from lung_cancer_screening.questions.tests.factories.date_of_birth_response_factory import (
1417
DateOfBirthResponseFactory,
1518
)
16-
from lung_cancer_screening.questions.tests.factories.check_need_appointment_response_factory import (
17-
CheckNeedAppointmentResponseFactory,
19+
from lung_cancer_screening.questions.tests.factories.age_when_started_smoking_response_factory import (
20+
AgeWhenStartedSmokingResponseFactory,
1821
)
1922

2023

@@ -26,6 +29,7 @@ def get_or_create_response_set(context):
2629
)
2730
)
2831

32+
2933
@given('I have answered have you ever smoked with an eligible response')
3034
def given_i_have_answered_have_your_ever_smoked_with_an_eligible_response(context):
3135
response_set = get_or_create_response_set(context)
@@ -46,9 +50,30 @@ def given_i_have_answered_date_of_birth_with_an_eligible_date_of_birth(context):
4650

4751

4852
@given("I have answered questions showing I am eligible")
49-
def step_impl(context):
53+
def given_i_have_answered_questions_showing_i_am_eligible(context):
5054
ResponseSetFactory.create(
5155
user=context.current_user,
5256
eligible=True,
5357
)
5458

59+
@given('I have answered questions showing I have smoked for "{years}" years')
60+
def given_i_have_answered_questions_showing_i_have_smoked_for_years_years(context, years):
61+
response_set = get_or_create_response_set(context)
62+
63+
AgeWhenStartedSmokingResponseFactory.create(
64+
response_set=response_set,
65+
value=response_set.date_of_birth_response.age_in_years() - int(years),
66+
)
67+
68+
@given('I have answered questions showing I am aged "{years}" years old')
69+
def given_i_have_answered_questions_showing_i_am_aged_60_years_old(context, years):
70+
context.page.goto(f"{context.live_server_url}/date-of-birth")
71+
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago(context, years)
72+
73+
74+
@given('I have answered questions showing I stopped smoking for "{years}" years')
75+
def given_i_have_answered_questions_showing_i_stopped_smoking_for_years_years(context, years):
76+
context.page.goto(f"{context.live_server_url}/periods-when-you-stopped-smoking")
77+
when_i_check_label(context, "Yes")
78+
when_i_fill_in_label_with_value(context, "Enter the total number of years you stopped smoking for", years)
79+
when_i_submit_the_form(context)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
import "nhsuk-frontend/packages/nhsuk.js";
1+
import { initAll } from "nhsuk-frontend";
2+
3+
document.addEventListener("DOMContentLoaded", () => {
4+
// Initialise NHS.UK frontend components
5+
initAll();
6+
});

lung_cancer_screening/questions/forms/age_when_started_smoking_form.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@ def __init__(self, *args, **kwargs):
2828
class Meta:
2929
model = AgeWhenStartedSmokingResponse
3030
fields = ["value"]
31+
32+
33+
def save(self, commit=True):
34+
instance = super(AgeWhenStartedSmokingForm, self).save(commit=False)
35+
36+
self._cleanup_periods_stopped_smoking_if_value_changed()
37+
38+
if commit:
39+
instance.save()
40+
41+
return instance
42+
43+
def _cleanup_periods_stopped_smoking_if_value_changed(self):
44+
if 'value' in self.changed_data and hasattr(self.instance.response_set, 'periods_when_you_stopped_smoking_response'):
45+
self.instance.response_set.periods_when_you_stopped_smoking_response.delete()

0 commit comments

Comments
 (0)