Skip to content

Commit fd767c2

Browse files
committed
PPHA-512: Hide age when diagnosed when family history is not yes in response page
1 parent 30f6609 commit fd767c2

2 files changed

Lines changed: 48 additions & 26 deletions

File tree

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -168,33 +168,9 @@
168168

169169
<section>
170170
<h2 class="nhsuk-heading-m">Family history</h2>
171+
171172
{{ 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-
]
173+
"rows": response_set.family_history_responses_items()
198174
}) }}
199175
</section>
200176

lung_cancer_screening/questions/presenters/response_set_presenter.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
@@ -108,6 +109,7 @@ def relatives_age_when_diagnosed(self):
108109

109110
return self.response_set.relatives_age_when_diagnosed.get_value_display()
110111

112+
111113
@property
112114
def respiratory_conditions(self):
113115
if not hasattr(self.response_set, 'respiratory_conditions_response'):
@@ -119,6 +121,24 @@ def respiratory_conditions(self):
119121
])
120122

121123

124+
def family_history_responses_items(self):
125+
items = [
126+
self._check_your_answer_item(
127+
"Have any of your parents, siblings or children ever been diagnosed with lung cancer?",
128+
self.family_history_lung_cancer,
129+
"questions:family_history_lung_cancer",
130+
)
131+
]
132+
if self._should_display_relatives_age_when_diagnosed():
133+
items.append(self._check_your_answer_item(
134+
"Were any of your relatives younger than 60 years old when they were diagnosed with lung cancer?",
135+
self.relatives_age_when_diagnosed,
136+
"questions:relatives_age_when_diagnosed",
137+
))
138+
139+
return items
140+
141+
122142
def _list_to_sentence(self, list):
123143
if len(list) == 0:
124144
return ''
@@ -128,3 +148,29 @@ def _list_to_sentence(self, list):
128148
return '{} and {}'.format(list[0], list[1])
129149

130150
return '{}, and {}'.format(', '.join(list[:-1]), list[-1])
151+
152+
153+
def _should_display_relatives_age_when_diagnosed(self):
154+
if not hasattr(self.response_set, 'family_history_lung_cancer'):
155+
return False
156+
157+
return self.response_set.family_history_lung_cancer != FamilyHistoryLungCancerValues.YES
158+
159+
160+
def _change_query_params(self):
161+
return { "change": "True" }
162+
163+
164+
def _check_your_answer_item(self, question, value, url_lookup_name):
165+
return {
166+
"key": { "text": question },
167+
"value": { "text": value },
168+
"actions": {
169+
"items": [
170+
{
171+
"href": reverse(url_lookup_name, query = self._change_query_params()),
172+
"text": "Change"
173+
}
174+
]
175+
}
176+
}

0 commit comments

Comments
 (0)