Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ infrastructure/bootstrap/main.bicep:generic-api-key:32
infrastructure/bootstrap/modules/storage.bicep:generic-api-key:59
infrastructure/bootstrap/modules/keyVault.bicep:generic-api-key:10
infrastructure/bootstrap/modules/storage.bicep:generic-api-key:59
infrastructure/terraform/hub/data.tf:generic-api-key:18
infrastructure/terraform/hub/data.tf:generic-api-key:22
infrastructure/terraform/hub/data.tf:generic-api-key:19
infrastructure/terraform/hub/data.tf:generic-api-key:23
infrastructure/terraform/resource_group_init/core.bicep:generic-api-key:11
infrastructure/terraform/resource_group_init/keyVault.bicep:generic-api-key:10
infrastructure/terraform/resource_group_init/main.bicep:generic-api-key:30
21 changes: 21 additions & 0 deletions docs/diagrams/PlantUML/data_flow_diagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@startuml

actor "Participant" as Participant
entity "LCS App" as LCS_App
entity "NHS Login" as NHS_Login
entity "In Health" as InHealth
entity "NHS Incentivisation system" as NHS_Incentivisation_System

' Date flow into LCS App
Participant -> LCS_App
LCS_App -> NHS_Login
NHS_Login -> LCS_App: Participant logs in and shares profile, email address and NHS Number (scopes "openid profile email") with LCS app
Participant -> LCS_App: Completes questionnaire

' Data flow from LCS App to In Health
LCS_App -> InHealth: Completed digital participant NHS Numbers shared with InHealth
InHealth -> LCS_App: InHealth share completed telephone responses corresponding to digital NHS number responses

' Data flow from LCS App to NHS Incentivisation system
LCS_App -> NHS_Incentivisation_System: Eligible participant's email addresses shared with NHS Incentivisation system
NHS_Incentivisation_System -> Participant: Participant is incentivised
20 changes: 20 additions & 0 deletions docs/diagrams/PlantUML/user_flow_diagram_returning_user.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@startuml

entity "In Health" as InHealth
actor "Participant" as Participant
entity "LCS App" as LCS_App
entity "NHS Login" as NHS_Login
entity "NHS Incentivisation system" as NHS_Incentivisation_System

' Participant flow
InHealth -> Participant: Initial contact via letter or SMS
Participant -> LCS_App
LCS_App -> NHS_Login: Participant clicks start and is redirected to NHS Login
NHS_Login -> LCS_App: NHS Login shares profile, email address and NHS Number (scopes "openid profile email")
Participant -> LCS_App: Completes questionnaire and submits

' In Health flow
LCS_App -> InHealth: Completed digital participant NHS Numbers shared with InHealth
InHealth -> LCS_App: In Health shared completed telephone responses corresponding to digital NHS number responses
LCS_App -> NHS_Incentivisation_System: Eligible participant's email addresses shared with NHS Incentivisation system
NHS_Incentivisation_System -> Participant: Participant is incentivised
5 changes: 2 additions & 3 deletions features/age_when_started_smoking.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feature: Age when started smoking
When I go to "/age-when-started-smoking"
Then I see a back link to "/relatives-age-when-diagnosed"
When I fill in "How old were you when you started smoking?" as "18" and submit
Then I am on "/check-your-answers"
Then I am on "/periods-when-you-stopped-smoking"

Scenario: Checking responses and changing them
Given I am logged in
Expand All @@ -40,5 +40,4 @@ Feature: Age when started smoking
Then I am on "/age-when-started-smoking?change=True"
And I see "18" filled in for "How old were you when you started smoking?"
When I fill in "How old were you when you started smoking?" as "22" and submit
Then I am on "/check-your-answers"
And I see "22" as a response to "Age you started smoking" under "Smoking history"
Then I am on "/periods-when-you-stopped-smoking?change=True"
48 changes: 48 additions & 0 deletions features/periods_when_you_stopped_smoking.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@PeriodsWhenYouStoppedSmoking
Feature: Periods when you stopped smoking page
Scenario: The page is accessible
Given I am logged in
And I have answered questions showing I am eligible
When I go to "/periods-when-you-stopped-smoking"
# TODO: problem with aria expanded from nhsuk frontend
# Then there are no accessibility violations

Scenario: Form errors
Given I am logged in
And I have answered questions showing I am eligible
When I go to "/periods-when-you-stopped-smoking"
When I submit the form
Then I am on "/periods-when-you-stopped-smoking"
And I see a form error "Select if you ever stopped smoking for periods of 1 year or longer"
# TODO: problem with aria expanded from nhsuk frontend
# 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
When I go to "/periods-when-you-stopped-smoking"
Then I see a back link to "/age-when-started-smoking"
When I check "Yes"
And I fill in "Enter the total number of years you stopped smoking for" with "1"
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
When I go to "/periods-when-you-stopped-smoking"
And I check "Yes"
And I fill in "Enter the total number of years you stopped smoking for" with "1"
And I submit the form
When I go to "/check-your-answers"
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"
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"
When I click the link to change "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
Then I am on "/periods-when-you-stopped-smoking?change=True"
And I see "Yes" selected
When I check "No"
And I submit the form
Then I am on "/check-your-answers"
And I see "No" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
11 changes: 10 additions & 1 deletion features/questionnaire.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ Feature: Questionnaire
Then I am on "/age-when-started-smoking"
When I fill in "How old were you when you started smoking?" as "18" and submit


Then I am on "/periods-when-you-stopped-smoking"
When I check "Yes"
And I fill in "Enter the total number of years you stopped smoking for" with "10"
And I submit the form

Then I am on "/check-your-answers"
And I see a back link to "/age-when-started-smoking"
And I see a back link to "/periods-when-you-stopped-smoking"

And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"
Expand All @@ -78,5 +84,8 @@ Feature: Questionnaire
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"
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"

And I see "18" as a response to "Age you started smoking" under "Smoking history"
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"

When I click "Submit"
Then I am on "/confirmation"
10 changes: 10 additions & 0 deletions features/steps/form_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def when_i_fill_in_and_submit_my_cancer_diagnosis(context, relatives_age_when_di
context.page.get_by_label(relatives_age_when_diagnosed, exact=True).check()
when_i_submit_the_form(context)

@when(u'I fill in and submit my periods when you stopped smoking with "{periods_when_you_stopped_smoking}"')
def when_i_fill_in_and_submit_my_periods_when_you_stopped_smoking(context, periods_when_you_stopped_smoking):
context.page.get_by_label(periods_when_you_stopped_smoking, exact=True).check()
when_i_submit_the_form(context)

@when('I submit the form')
def when_i_submit_the_form(context):
when_i_click(context, "Continue")
Expand All @@ -134,3 +139,8 @@ def then_i_see_value_filled_in_for_label(context, value, label):
@when('I check "{label}"')
def when_i_check_label(context, label):
context.page.get_by_label(label, exact=True).check()


@when('I fill in "{label}" with "{value}"')
def when_i_fill_in_label_with_value(context, label, value):
context.page.get_by_label(label, exact=True).fill(value)
41 changes: 33 additions & 8 deletions features/steps/preflight_steps.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
from behave import given
from datetime import datetime
from dateutil.relativedelta import relativedelta

from features.steps.form_steps import (
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago,
when_i_submit_the_form,
when_i_check_label,
when_i_fill_in_label_with_value
)

from lung_cancer_screening.questions.tests.factories.have_you_ever_smoked_response_factory import (
ResponseSetFactory,
)
from lung_cancer_screening.questions.tests.factories.have_you_ever_smoked_response_factory import (
HaveYouEverSmokedResponseFactory,
)
from lung_cancer_screening.questions.models.have_you_ever_smoked_response import (
HaveYouEverSmokedValues,
)
from lung_cancer_screening.questions.tests.factories.date_of_birth_response_factory import (
DateOfBirthResponseFactory,
)
from lung_cancer_screening.questions.tests.factories.check_need_appointment_response_factory import (
CheckNeedAppointmentResponseFactory,
from lung_cancer_screening.questions.tests.factories.age_when_started_smoking_response_factory import (
AgeWhenStartedSmokingResponseFactory,
)


Expand All @@ -26,6 +29,7 @@ def get_or_create_response_set(context):
)
)


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


@given("I have answered questions showing I am eligible")
def step_impl(context):
def given_i_have_answered_questions_showing_i_am_eligible(context):
ResponseSetFactory.create(
user=context.current_user,
eligible=True,
)

@given('I have answered questions showing I have smoked for "{years}" years')
def given_i_have_answered_questions_showing_i_have_smoked_for_years_years(context, years):
response_set = get_or_create_response_set(context)

AgeWhenStartedSmokingResponseFactory.create(
response_set=response_set,
value=response_set.date_of_birth_response.age_in_years() - int(years),
)

@given('I have answered questions showing I am aged "{years}" years old')
def given_i_have_answered_questions_showing_i_am_aged_60_years_old(context, years):
context.page.goto(f"{context.live_server_url}/date-of-birth")
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago(context, years)


@given('I have answered questions showing I stopped smoking for "{years}" years')
def given_i_have_answered_questions_showing_i_stopped_smoking_for_years_years(context, years):
context.page.goto(f"{context.live_server_url}/periods-when-you-stopped-smoking")
when_i_check_label(context, "Yes")
when_i_fill_in_label_with_value(context, "Enter the total number of years you stopped smoking for", years)
when_i_submit_the_form(context)
7 changes: 6 additions & 1 deletion lung_cancer_screening/assets/js/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import "nhsuk-frontend/packages/nhsuk.js";
import { initAll } from "nhsuk-frontend";

document.addEventListener("DOMContentLoaded", () => {
// Initialise NHS.UK frontend components
initAll();
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ def __init__(self, *args, **kwargs):
class Meta:
model = AgeWhenStartedSmokingResponse
fields = ["value"]


def save(self, commit=True):
instance = super(AgeWhenStartedSmokingForm, self).save(commit=False)

self._cleanup_periods_stopped_smoking_if_value_changed()

if commit:
instance.save()

return instance

def _cleanup_periods_stopped_smoking_if_value_changed(self):
if 'value' in self.changed_data and hasattr(self.instance.response_set, 'periods_when_you_stopped_smoking_response'):
self.instance.response_set.periods_when_you_stopped_smoking_response.delete()
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django import forms

from ...nhsuk_forms.integer_field import IntegerField
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
from ..models.periods_when_you_stopped_smoking_response import PeriodsWhenYouStoppedSmokingResponse


class PeriodsWhenYouStoppedSmokingForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["value"] = TypedChoiceField(
choices=[(True, "Yes"), (False, "No")],
widget=forms.RadioSelect,
label="Have you ever stopped smoking for periods of 1 year or longer?",
label_classes="nhsuk-fieldset__legend--m",
coerce=lambda x: x == "True",
error_messages={
"required": "Select if you ever stopped smoking for periods of 1 year or longer"
},
)

self.fields["duration_years"] = IntegerField(
label="Enter the total number of years you stopped smoking for",
label_classes="nhsuk-fieldset__legend--s",
classes="nhsuk-input--width-4",
hint="Give an estimate if you are not sure",
required=False,
suffix="years",
error_messages={
"required": "Enter the total number of years you stopped smoking for"
},
)

class Meta:
model = PeriodsWhenYouStoppedSmokingResponse
fields = ["value", "duration_years"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends 'layout.jinja' %}

{% from 'nhsuk/components/button/macro.jinja' import button %}

{% if error %}
{% set error_message = { "text": error } %}
{% endif %}

{% block page_content %}
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
<form action="{{ request.path }}" method="POST">
{{ csrf_input }}

{% if request.GET.get("change") == "True" %}
<input type="hidden" name="change" value="True">
{% endif %}

<h1 class="nhsuk-heading-l">Periods when you stopped smoking</h1>

<p>There may have been periods when you stopped or quit smoking.</p>
<p>If you stopped smoking for periods of 1 year or longer, tell us the total number of years you stopped smoking.</p>

{% do form.value.add_conditional_html(
True,
form.duration_years.as_field_group()
) %}

{{ form.value.as_field_group() }}

{{ button({
"text": "Continue"
}) }}
</form>
</div>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("questions", "0043_agewhenstartedsmokingresponse"),
]

operations = [
migrations.CreateModel(
name='PeriodsWhenYouStoppedSmokingResponse',
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.BooleanField()),
('response_set', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='periods_when_you_stopped_smoking_response', to='questions.responseset')),
],
options={
'abstract': False,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2.10 on 2026-01-21 11:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0044_periodswhenyoustoppedsmokingresponse'),
]

operations = [
migrations.AddField(
model_name='periodswhenyoustoppedsmokingresponse',
name='duration_years',
field=models.IntegerField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions lung_cancer_screening/questions/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .gender_response import GenderResponse # noqa: F401
from .have_you_ever_smoked_response import HaveYouEverSmokedResponse # noqa: F401
from .height_response import HeightResponse # noqa: F401
from .periods_when_you_stopped_smoking_response import PeriodsWhenYouStoppedSmokingResponse # noqa: F401
from .relatives_age_when_diagnosed_response import RelativesAgeWhenDiagnosedResponse # noqa: F401
from .respiratory_conditions_response import RespiratoryConditionsResponse # noqa: F401
from .sex_at_birth_response import SexAtBirthResponse # noqa: F401
Expand Down
Loading