Skip to content

Commit a8ba634

Browse files
authored
Merge pull request #139 from NHSDigital/PPHA-269-asbestos-page
Add asbestos exposure form
2 parents 523445a + 29270dc commit a8ba634

15 files changed

+338
-7
lines changed

lung_cancer_screening/core/tests/acceptance/helpers/user_interaction_helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,11 @@ def fill_in_and_submit_ethnicity(page, ethnicity):
7676
page.get_by_label(ethnicity, exact=True).check()
7777

7878
page.click("text=Continue")
79+
80+
def fill_in_and_submit_asbestos_exposure(page, answer):
81+
expect(page.locator("legend")).to_have_text(
82+
"Have you ever worked in a job where you might have been exposed to asbestos?")
83+
84+
page.get_by_label(answer, exact=True).check()
85+
86+
page.click("text=Continue")

lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
fill_in_and_submit_date_of_birth,
1313
fill_in_and_submit_sex_at_birth,
1414
fill_in_and_submit_gender,
15-
fill_in_and_submit_ethnicity
15+
fill_in_and_submit_ethnicity,
16+
fill_in_and_submit_asbestos_exposure
1617
)
1718

1819
class TestQuestionnaire(StaticLiveServerTestCase):
@@ -46,6 +47,7 @@ def test_cannot_change_responses_once_checked_and_submitted(self):
4647
fill_in_and_submit_sex_at_birth(page, "Male")
4748
fill_in_and_submit_gender(page, "Male")
4849
fill_in_and_submit_ethnicity(page, "White")
50+
fill_in_and_submit_asbestos_exposure(page, "No")
4951

5052
page.click("text=Submit")
5153

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
fill_in_and_submit_weight_imperial,
1515
fill_in_and_submit_sex_at_birth,
1616
fill_in_and_submit_gender,
17-
fill_in_and_submit_ethnicity
17+
fill_in_and_submit_ethnicity,
18+
fill_in_and_submit_asbestos_exposure
1819
)
1920

2021
from .helpers.assertion_helpers import expect_back_link_to_have_url
@@ -90,9 +91,14 @@ def test_full_questionnaire_user_journey(self):
9091

9192
fill_in_and_submit_ethnicity(page, "White")
9293

93-
expect(page).to_have_url(f"{self.live_server_url}/responses")
94+
expect(page).to_have_url(f"{self.live_server_url}/asbestos-exposure")
9495
expect_back_link_to_have_url(page, "/ethnicity")
9596

97+
fill_in_and_submit_asbestos_exposure(page, "No")
98+
99+
expect(page).to_have_url(f"{self.live_server_url}/responses")
100+
expect_back_link_to_have_url(page, "/asbestos-exposure")
101+
96102
responses = page.locator(".responses")
97103
expect(responses).to_contain_text("Have you ever smoked? Yes, I used to smoke regularly")
98104
expect(responses).to_contain_text(
@@ -102,6 +108,7 @@ def test_full_questionnaire_user_journey(self):
102108
expect(responses).to_contain_text("What was your sex at birth? Male")
103109
expect(responses).to_contain_text("Which of these best describes you? Male")
104110
expect(responses).to_contain_text("What is your ethnic background? White")
111+
expect(responses).to_contain_text("Have you ever worked in a job where you might have been exposed to asbestos? No")
105112

106113
page.click("text=Submit")
107114

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django import forms
2+
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
3+
from ..models.response_set import ResponseSet
4+
5+
6+
class AsbestosExposureForm(forms.ModelForm):
7+
def __init__(self, *args, **kwargs):
8+
self.participant = kwargs.pop('participant')
9+
super().__init__(*args, **kwargs)
10+
self.instance.participant = self.participant
11+
12+
self.fields["asbestos_exposure"] = TypedChoiceField(
13+
choices=[(True, 'Yes'), (False, 'No')],
14+
widget=forms.RadioSelect,
15+
label="Have you ever worked in a job where you might have been exposed to asbestos?",
16+
label_classes="nhsuk-fieldset__legend--m",
17+
coerce=lambda x: x == 'True',
18+
error_messages={
19+
'required': 'Select if you have been exposed to asbestos.'
20+
}
21+
)
22+
23+
class Meta:
24+
model = ResponseSet
25+
fields = ['asbestos_exposure']
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{% extends 'layout.jinja' %}
2+
{% from 'nhsuk/components/button/macro.jinja' import button %}
3+
{% from 'nhsuk/components/back-link/macro.jinja' import backLink %}
4+
{% from 'nhsuk/components/details/macro.jinja' import details %}
5+
6+
{% block beforeContent %}
7+
{{
8+
backLink({
9+
"href": url("questions:ethnicity"),
10+
"text": "Back"
11+
})
12+
}}
13+
{% endblock beforeContent %}
14+
15+
{% block page_content %}
16+
<div class="nhsuk-grid-row">
17+
<div class="nhsuk-grid-column-two-thirds">
18+
<h1 class="nhsuk-heading-l">Tell us if you might have been exposed to asbestos at work</h1>
19+
20+
<p>You may have been exposed to asbestos if you worked in an industry such as building or construction, particularly from the 1950s to the 1990s.</p>
21+
22+
<p>You could be exposed to asbestos today if your job involves working in certain roles in old buildings.</p>
23+
24+
<p>Examples include:</p>
25+
<ul>
26+
<li>heating and ventilation engineers</li>
27+
<li>demolition workers</li>
28+
<li>plumbers</li>
29+
<li>construction workers</li>
30+
<li>electricians</li>
31+
</ul>
32+
33+
<p>You may have come into contact with asbestos from existing asbestos-containing materials in buildings and products. If they are intact or undamaged, they pose very little risk.</p>
34+
35+
{{
36+
details({
37+
"summaryText": "What is asbestos?",
38+
"html": "<p>Asbestos was used in a number of building materials and products. For example:</p>
39+
<ul>
40+
<li>boilers and pipes</li>
41+
<li>car brakes</li>
42+
<li>cement for roofing sheets</li>
43+
<li>floor tiles</li>
44+
<li>insulating board to protect buildings and ships against fire</li>
45+
</ul>
46+
<p>If you worked in an industry such as building or construction you are more likely to have come into contact with damaged asbestos materials and products.</p>"
47+
})
48+
}}
49+
50+
<form action="{{ request.path }}" method="POST">
51+
{{ csrf_input }}
52+
53+
{{ form }}
54+
55+
{{ button({
56+
"text": "Continue"
57+
}) }}
58+
</form>
59+
</div>
60+
</div>
61+
{% endblock %}

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{% block beforeContent %}
66
{{
77
backLink({
8-
"href": url("questions:ethnicity"),
8+
"href": url("questions:asbestos_exposure"),
99
"text": "Back"
1010
})
1111
}}
@@ -23,6 +23,7 @@
2323
<li>What was your sex at birth? {{ response_set.get_sex_at_birth_display() }}</li>
2424
<li>Which of these best describes you? {{ response_set.get_gender_display() }}</li>
2525
<li>What is your ethnic background? {{ response_set.get_ethnicity_display() }}</li>
26+
<li>Have you ever worked in a job where you might have been exposed to asbestos? {{ "Yes" if response_set.asbestos_exposure else "No" }}</li>
2627
</ul>
2728

2829
<form action="{{ request.path }}" method="post">
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.8 on 2025-11-12 08:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('questions', '0015_responseset_ethnicity_alter_responseset_gender'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='responseset',
15+
name='asbestos_exposure',
16+
field=models.CharField(blank=True, choices=[('Y', 'Yes'), ('N', 'No')], max_length=1, null=True),
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.7 on 2025-11-12 11:00
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('questions', '0016_responseset_asbestos_exposure'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='responseset',
15+
name='asbestos_exposure',
16+
field=models.BooleanField(blank=True, null=True),
17+
),
18+
]

lung_cancer_screening/questions/models/response_set.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ class ResponseSet(BaseModel):
9595
blank=True
9696
)
9797

98+
asbestos_exposure = models.BooleanField(
99+
null=True,
100+
blank=True
101+
)
102+
98103
submitted_at = models.DateTimeField(null=True, blank=True)
99104

100105
class Meta:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from django.test import TestCase
2+
3+
from ....models.participant import Participant
4+
from ....forms.asbestos_exposure_form import AsbestosExposureForm
5+
6+
7+
class TestAsbestosExposureForm(TestCase):
8+
def setUp(self):
9+
self.participant = Participant.objects.create(unique_id="1234567890")
10+
11+
def test_is_valid_with_yes(self):
12+
form = AsbestosExposureForm(
13+
participant=self.participant,
14+
data={
15+
"asbestos_exposure": True
16+
}
17+
)
18+
self.assertTrue(form.is_valid())
19+
self.assertEqual(
20+
form.cleaned_data["asbestos_exposure"],
21+
True
22+
)
23+
24+
def test_is_valid_with_no(self):
25+
form = AsbestosExposureForm(
26+
participant=self.participant,
27+
data={
28+
"asbestos_exposure": False
29+
}
30+
)
31+
self.assertTrue(form.is_valid())
32+
self.assertEqual(
33+
form.cleaned_data["asbestos_exposure"],
34+
False
35+
)
36+
37+
def test_is_invalid_with_an_invalid_value(self):
38+
form = AsbestosExposureForm(
39+
participant=self.participant,
40+
data={
41+
"asbestos_exposure": "invalid"
42+
}
43+
)
44+
self.assertFalse(form.is_valid())
45+
self.assertEqual(
46+
form.errors["asbestos_exposure"],
47+
["Select a valid choice. invalid is not one of the available choices."]
48+
)
49+
50+
def test_is_invalid_when_no_option_is_selected(self):
51+
form = AsbestosExposureForm(
52+
participant=self.participant,
53+
data={
54+
"asbestos_exposure": None
55+
}
56+
)
57+
self.assertFalse(form.is_valid())
58+
self.assertEqual(
59+
form.errors["asbestos_exposure"],
60+
["Select if you have been exposed to asbestos."]
61+
)

0 commit comments

Comments
 (0)