|
1 | 1 | from decimal import Decimal |
| 2 | +from django.urls import reverse |
2 | 3 |
|
3 | 4 | from ..models.education_response import EducationValues |
4 | 5 | from ..models.respiratory_conditions_response import RespiratoryConditionValues |
| 6 | +from ..models.family_history_lung_cancer_response import FamilyHistoryLungCancerValues |
5 | 7 |
|
6 | 8 | class ResponseSetPresenter: |
7 | 9 | DATE_FORMAT = "%-d %B %Y" # eg 8 September 2000 |
@@ -108,23 +110,146 @@ def relatives_age_when_diagnosed(self): |
108 | 110 |
|
109 | 111 | return self.response_set.relatives_age_when_diagnosed.get_value_display() |
110 | 112 |
|
| 113 | + |
111 | 114 | @property |
112 | 115 | def respiratory_conditions(self): |
113 | 116 | if not hasattr(self.response_set, 'respiratory_conditions_response'): |
114 | 117 | return None |
115 | 118 |
|
| 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 | + |
116 | 128 | return self._list_to_sentence([ |
117 | 129 | RespiratoryConditionValues(code).label |
118 | 130 | for code in self.response_set.respiratory_conditions_response.value |
119 | 131 | ]) |
120 | 132 |
|
121 | 133 |
|
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"): |
123 | 222 | if len(list) == 0: |
124 | 223 | return '' |
125 | 224 | if len(list) == 1: |
126 | 225 | return list[0] |
127 | 226 | 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 | + |
129 | 242 |
|
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