Skip to content

Commit 6e4a8ee

Browse files
authored
Merge pull request #231 from NHSDigital/PPHA-512-check-answers-signoff-issues
PPHA-512: check answers labels and display logic
2 parents 945fa1e + 3ce5545 commit 6e4a8ee

5 files changed

Lines changed: 142 additions & 176 deletions

File tree

features/education.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ Feature: Education page
2828
And I check "GCSEs"
2929
And I click "Continue"
3030
When I go to "/check-your-answers"
31-
Then I see "GCSEs and A-levels" as a response to "Highest level of education" under "About you"
32-
And I see "/education?change=True" as a link to change "Highest level of education" under "About you"
33-
When I click the link to change "Highest level of education" under "About you"
31+
Then I see "GCSEs and A-levels" as a response to "Education" under "About you"
32+
And I see "/education?change=True" as a link to change "Education" under "About you"
33+
When I click the link to change "Education" under "About you"
3434
Then I am on "/education?change=True"
3535
And I see "A-levels" selected
3636
When I fill in and submit my education with "GCSEs"
3737
Then I am on "/check-your-answers"
38-
And I see "GCSEs" as a response to "Highest level of education" under "About you"
38+
And I see "GCSEs" as a response to "Education" under "About you"
3939

features/ethnicity.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ Feature: Ethnicity page
2525
When I go to "/ethnicity"
2626
And I fill in and submit my ethnicity with "White"
2727
When I go to "/check-your-answers"
28-
Then I see "White" as a response to "Ethnic group" under "About you"
29-
And I see "/ethnicity?change=True" as a link to change "Ethnic group" under "About you"
30-
When I click the link to change "Ethnic group" under "About you"
28+
Then I see "White" as a response to "Ethnic background" under "About you"
29+
And I see "/ethnicity?change=True" as a link to change "Ethnic background" under "About you"
30+
When I click the link to change "Ethnic background" under "About you"
3131
Then I am on "/ethnicity?change=True"
3232
And I see "White" selected
3333
When I fill in and submit my ethnicity with "Black, African, Caribbean or Black British"
3434
Then I am on "/check-your-answers"
35-
And I see "Black, African, Caribbean or Black British" as a response to "Ethnic group" under "About you"
35+
And I see "Black, African, Caribbean or Black British" as a response to "Ethnic background" under "About you"
3636

features/questionnaire.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Feature: Questionnaire
6666
And I see "5 stone 10 pounds" as a response to "Weight" under "About you"
6767
And I see "Male" as a response to "Sex at birth" under "About you"
6868
And I see "Female" as a response to "Gender identity" under "About you"
69-
And I see "White" as a response to "Ethnic group" under "About you"
69+
And I see "White" as a response to "Ethnic background" under "About you"
7070

7171
And I see "Pneumonia and Emphysema" as a response to "Diagnosed respiratory conditions" under "Your health"
7272
And I see "No" as a response to "Have you ever worked in a job where you were exposed to asbestos?" under "Your health"

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 5 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -13,188 +13,29 @@
1313
<section>
1414
<h2 class="nhsuk-heading-m">Eligibility</h2>
1515
{{ summaryList({
16-
"rows": [
17-
{
18-
"key": { "text": "Have you ever smoked tobacco?" },
19-
"value": { "text": response_set.have_you_ever_smoked },
20-
"actions": {
21-
"items": [
22-
{
23-
"href": url('questions:have_you_ever_smoked', query = change_query_params),
24-
"text": "Change"
25-
}
26-
]
27-
}
28-
},
29-
{
30-
"key": { "text": "Date of birth" },
31-
"value": { "text": response_set.date_of_birth },
32-
"actions": {
33-
"items": [
34-
{
35-
"href": url('questions:date_of_birth', query = change_query_params),
36-
"text": "Change"
37-
}
38-
]
39-
}
40-
}
41-
]
16+
"rows": response_set.eligibility_responses_items()
4217
}) }}
4318
</section>
4419

4520
<section>
4621
<h2 class="nhsuk-heading-m">About you</h2>
4722
{{ summaryList({
48-
"rows": [
49-
{
50-
"key": { "text": "Height" },
51-
"value": { "text": response_set.height },
52-
"actions": {
53-
"items": [
54-
{
55-
"href": url('questions:height', query = change_query_params),
56-
"text": "Change"
57-
}
58-
]
59-
}
60-
},
61-
{
62-
"key": { "text": "Weight" },
63-
"value": { "text": response_set.weight },
64-
"actions": {
65-
"items": [
66-
{
67-
"href": url('questions:weight', query = change_query_params),
68-
"text": "Change"
69-
}
70-
]
71-
}
72-
},
73-
{
74-
"key": { "text": "Sex at birth" },
75-
"value": { "text": response_set.sex_at_birth },
76-
"actions": {
77-
"items": [
78-
{
79-
"href": url('questions:sex_at_birth', query = change_query_params),
80-
"text": "Change"
81-
}
82-
]
83-
}
84-
},
85-
{
86-
"key": { "text": "Gender identity" },
87-
"value": { "text": response_set.gender },
88-
"actions": {
89-
"items": [
90-
{
91-
"href": url('questions:gender', query = change_query_params),
92-
"text": "Change"
93-
}
94-
]
95-
}
96-
},
97-
{
98-
"key": { "text": "Ethnic group" },
99-
"value": { "text": response_set.ethnicity },
100-
"actions": {
101-
"items": [
102-
{
103-
"href": url('questions:ethnicity', query = change_query_params),
104-
"text": "Change"
105-
}
106-
]
107-
}
108-
},
109-
{
110-
"key": { "text": "Highest level of education" },
111-
"value": { "text": response_set.education },
112-
"actions": {
113-
"items": [
114-
{
115-
"href": url('questions:education', query = change_query_params),
116-
"text": "Change"
117-
}
118-
]
119-
}
120-
},
121-
]
23+
"rows": response_set.about_you_responses_items()
12224
}) }}
12325
</section>
12426

12527
<section>
12628
<h2 class="nhsuk-heading-m">Your health</h2>
12729
{{ summaryList({
128-
"rows": [
129-
{
130-
"key": { "text": "Diagnosed respiratory conditions" },
131-
"value": { "text": response_set.respiratory_conditions },
132-
"actions": {
133-
"items": [
134-
{
135-
"href": url('questions:respiratory_conditions', query = change_query_params),
136-
"text": "Change"
137-
}
138-
]
139-
}
140-
},
141-
{
142-
"key": { "text": "Have you ever worked in a job where you were exposed to asbestos?" },
143-
"value": { "text": response_set.asbestos_exposure },
144-
"actions": {
145-
"items": [
146-
{
147-
"href": url('questions:asbestos_exposure', query = change_query_params),
148-
"text": "Change"
149-
}
150-
]
151-
}
152-
},
153-
{
154-
"key": { "text": "Have you ever been diagnosed with cancer?" },
155-
"value": { "text": response_set.cancer_diagnosis },
156-
"actions": {
157-
"items": [
158-
{
159-
"href": url('questions:cancer_diagnosis', query = change_query_params),
160-
"text": "Change"
161-
}
162-
]
163-
}
164-
}
165-
]
30+
"rows": response_set.your_health_responses_items()
16631
}) }}
16732
</section>
16833

16934
<section>
17035
<h2 class="nhsuk-heading-m">Family history</h2>
36+
17137
{{ summaryList({
172-
"rows": [
173-
{
174-
"key": { "text": "Have any of your parents, siblings or children ever been diagnosed with lung cancer?" },
175-
"value": { "text": response_set.family_history_lung_cancer },
176-
"actions": {
177-
"items": [
178-
{
179-
"href": url('questions:family_history_lung_cancer', query = change_query_params),
180-
"text": "Change"
181-
}
182-
]
183-
}
184-
},
185-
{
186-
"key": { "text": "Were any of your relatives younger than 60 years old when they were diagnosed with lung cancer?" },
187-
"value": { "text": response_set.relatives_age_when_diagnosed },
188-
"actions": {
189-
"items": [
190-
{
191-
"href": url('questions:relatives_age_when_diagnosed', query = change_query_params),
192-
"text": "Change"
193-
}
194-
]
195-
}
196-
}
197-
]
38+
"rows": response_set.family_history_responses_items()
19839
}) }}
19940
</section>
20041

lung_cancer_screening/questions/presenters/response_set_presenter.py

Lines changed: 128 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from decimal import Decimal
2+
from django.urls import reverse
23

34
from ..models.education_response import EducationValues
45
from ..models.respiratory_conditions_response import RespiratoryConditionValues
6+
from ..models.family_history_lung_cancer_response import FamilyHistoryLungCancerValues
57

68
class ResponseSetPresenter:
79
DATE_FORMAT = "%-d %B %Y" # eg 8 September 2000
@@ -108,23 +110,146 @@ def relatives_age_when_diagnosed(self):
108110

109111
return self.response_set.relatives_age_when_diagnosed.get_value_display()
110112

113+
111114
@property
112115
def respiratory_conditions(self):
113116
if not hasattr(self.response_set, 'respiratory_conditions_response'):
114117
return None
115118

119+
if RespiratoryConditionValues.NONE in self.response_set.respiratory_conditions_response.value:
120+
values_sentence = self._list_to_sentence([
121+
label
122+
for label in RespiratoryConditionValues.labels
123+
if label != RespiratoryConditionValues.NONE.label
124+
], final_separator = "or")
125+
126+
return f"No, I have not been diagnosed with {values_sentence}"
127+
116128
return self._list_to_sentence([
117129
RespiratoryConditionValues(code).label
118130
for code in self.response_set.respiratory_conditions_response.value
119131
])
120132

121133

122-
def _list_to_sentence(self, list):
134+
def eligibility_responses_items(self):
135+
return [
136+
self._check_your_answer_item(
137+
"Have you ever smoked tobacco?",
138+
self.have_you_ever_smoked,
139+
"questions:have_you_ever_smoked",
140+
),
141+
self._check_your_answer_item(
142+
"Date of birth",
143+
self.date_of_birth,
144+
"questions:date_of_birth",
145+
)
146+
]
147+
148+
def about_you_responses_items(self):
149+
return [
150+
self._check_your_answer_item(
151+
"Height",
152+
self.height,
153+
"questions:height",
154+
),
155+
self._check_your_answer_item(
156+
"Weight",
157+
self.weight,
158+
"questions:weight",
159+
),
160+
self._check_your_answer_item(
161+
"Sex at birth",
162+
self.sex_at_birth,
163+
"questions:sex_at_birth",
164+
),
165+
self._check_your_answer_item(
166+
"Gender identity",
167+
self.gender,
168+
"questions:gender",
169+
),
170+
self._check_your_answer_item(
171+
"Ethnic background",
172+
self.ethnicity,
173+
"questions:ethnicity",
174+
),
175+
self._check_your_answer_item(
176+
"Education",
177+
self.education,
178+
"questions:education",
179+
)
180+
]
181+
182+
183+
def your_health_responses_items(self):
184+
return [
185+
self._check_your_answer_item(
186+
"Diagnosed respiratory conditions",
187+
self.respiratory_conditions,
188+
"questions:respiratory_conditions",
189+
),
190+
self._check_your_answer_item(
191+
"Have you ever worked in a job where you were exposed to asbestos?",
192+
self.asbestos_exposure,
193+
"questions:asbestos_exposure",
194+
),
195+
self._check_your_answer_item(
196+
"Have you ever been diagnosed with cancer?",
197+
self.cancer_diagnosis,
198+
"questions:cancer_diagnosis",
199+
)
200+
]
201+
202+
203+
def family_history_responses_items(self):
204+
items = [
205+
self._check_your_answer_item(
206+
"Have any of your parents, siblings or children ever been diagnosed with lung cancer?",
207+
self.family_history_lung_cancer,
208+
"questions:family_history_lung_cancer",
209+
)
210+
]
211+
if self._should_display_relatives_age_when_diagnosed():
212+
items.append(self._check_your_answer_item(
213+
"Were any of your relatives younger than 60 years old when they were diagnosed with lung cancer?",
214+
self.relatives_age_when_diagnosed,
215+
"questions:relatives_age_when_diagnosed",
216+
))
217+
218+
return items
219+
220+
221+
def _list_to_sentence(self, list, final_separator = "and"):
123222
if len(list) == 0:
124223
return ''
125224
if len(list) == 1:
126225
return list[0]
127226
if len(list) == 2:
128-
return '{} and {}'.format(list[0], list[1])
227+
return f"{list[0]} {final_separator} {list[1]}"
228+
229+
return f"{', '.join(list[:-1])}, {final_separator} {list[-1]}"
230+
231+
232+
def _should_display_relatives_age_when_diagnosed(self):
233+
if not hasattr(self.response_set, 'family_history_lung_cancer'):
234+
return False
235+
236+
return self.response_set.family_history_lung_cancer != FamilyHistoryLungCancerValues.YES
237+
238+
239+
def _change_query_params(self):
240+
return { "change": "True" }
241+
129242

130-
return '{}, and {}'.format(', '.join(list[:-1]), list[-1])
243+
def _check_your_answer_item(self, question, value, url_lookup_name):
244+
return {
245+
"key": { "text": question },
246+
"value": { "text": value },
247+
"actions": {
248+
"items": [
249+
{
250+
"href": reverse(url_lookup_name, query = self._change_query_params()),
251+
"text": "Change"
252+
}
253+
]
254+
}
255+
}

0 commit comments

Comments
 (0)