Skip to content

Commit 2756bae

Browse files
committed
PPHA-525: Ensure user has to change periods stopped smoking if changeing age started smoking
1 parent 8c1ca7b commit 2756bae

15 files changed

+145
-22
lines changed

.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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

features/periods_when_you_stopped_smoking.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Feature: Periods when you stopped smoking page
2222
And I have answered questions showing I am eligible
2323
And I have answered questions showing I have smoked for "10" years
2424
When I go to "/periods-when-you-stopped-smoking"
25-
Then I see a back link to "/family-history-lung-cancer"
25+
Then I see a back link to "/age-when-started-smoking"
2626
When I check "Yes"
2727
And I fill in "Enter the total number of years you stopped smoking for" with "1"
2828
And I submit the form

features/steps/accessibility_steps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ def then_there_are_no_accessibility_violations(context):
99
f"Found the following accessibility violations: \n"
1010
f"{axe_results.generate_snapshot()}"
1111
)
12-
print(axe_results)
1312
assert axe_results.violations_count == 0, violations_msg

features/steps/preflight_steps.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
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
)
@@ -23,6 +29,7 @@ def get_or_create_response_set(context):
2329
)
2430
)
2531

32+
2633
@given('I have answered have you ever smoked with an eligible response')
2734
def given_i_have_answered_have_your_ever_smoked_with_an_eligible_response(context):
2835
response_set = get_or_create_response_set(context)
@@ -57,3 +64,16 @@ def given_i_have_answered_questions_showing_i_have_smoked_for_years_years(contex
5764
response_set=response_set,
5865
value=response_set.date_of_birth_response.age_in_years() - int(years),
5966
)
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)

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()

lung_cancer_screening/questions/tests/factories/periods_when_you_stopped_smoking_response_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ class Meta:
1010

1111
response_set = factory.SubFactory(ResponseSetFactory)
1212
value = False
13+
duration_years = None

lung_cancer_screening/questions/tests/unit/forms/test_age_when_started_smoking_form.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from ...factories.response_set_factory import ResponseSetFactory
99
from ...factories.date_of_birth_response_factory import DateOfBirthResponseFactory
1010
from ....forms.age_when_started_smoking_form import AgeWhenStartedSmokingForm
11+
from ...factories.periods_when_you_stopped_smoking_response_factory import PeriodsWhenYouStoppedSmokingResponseFactory
12+
from ....models.periods_when_you_stopped_smoking_response import PeriodsWhenYouStoppedSmokingResponse
1113

1214

1315
@tag("AgeWhenStartedSmoking")
@@ -106,3 +108,43 @@ def test_is_invalid_when_age_entered_greater_than_current_age(self):
106108
form.errors["value"],
107109
["The age you started smoking must be the same as, or less than your current age"]
108110
)
111+
112+
113+
def test_deletes_periods_when_stopped_smoking_response_if_age_started_smoking_is_changed(self):
114+
self.response.value = 17
115+
self.response.save()
116+
117+
PeriodsWhenYouStoppedSmokingResponseFactory.create(
118+
response_set=self.response_set,
119+
value=True,
120+
duration_years=self.response.years_smoked_including_stopped() - 1
121+
)
122+
form = AgeWhenStartedSmokingForm(
123+
instance=self.response,
124+
data={
125+
"value": 18
126+
}
127+
)
128+
form.save()
129+
130+
self.assertFalse(PeriodsWhenYouStoppedSmokingResponse.objects.filter(response_set=self.response_set).exists())
131+
132+
133+
def test_does_not_delete_periods_when_stopped_smoking_response_if_age_started_smoking_is_not_changed(self):
134+
self.response.value = 18
135+
self.response.save()
136+
137+
PeriodsWhenYouStoppedSmokingResponseFactory.create(
138+
response_set=self.response_set,
139+
value=True,
140+
duration_years=self.response.years_smoked_including_stopped() - 1
141+
)
142+
form = AgeWhenStartedSmokingForm(
143+
instance=self.response,
144+
data={
145+
"value": 18
146+
}
147+
)
148+
form.save()
149+
150+
self.assertTrue(PeriodsWhenYouStoppedSmokingResponse.objects.filter(response_set=self.response_set).exists())

0 commit comments

Comments
 (0)