Coverage for tasks/deakin_s1_healthreview.py : 93%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3"""
4camcops_server/tasks/deakin_s1_healthreview.py
6===============================================================================
8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).
10 This file is part of CamCOPS.
12 CamCOPS is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 CamCOPS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
25===============================================================================
27"""
29from sqlalchemy.sql.schema import Column
30from sqlalchemy.sql.sqltypes import Integer, String, Text, UnicodeText
32from camcops_server.cc_modules.cc_constants import CssClass
33from camcops_server.cc_modules.cc_html import tr_qa
34from camcops_server.cc_modules.cc_request import CamcopsRequest
35from camcops_server.cc_modules.cc_sqla_coltypes import (
36 BoolColumn,
37 CamcopsColumn,
38 MIN_ZERO_CHECKER,
39 PermittedValueChecker,
40 ZERO_TO_FOUR_CHECKER,
41)
42from camcops_server.cc_modules.cc_task import Task, TaskHasPatientMixin
45# =============================================================================
46# DeakinS1HealthReview
47# =============================================================================
49FREQUENCY_COMMENT = (
50 "Frequency (0 did not use, 1 occasionally, 2 monthly, 3 weekly, 4 daily)"
51)
54class DeakinS1HealthReview(TaskHasPatientMixin, Task):
55 """
56 Server implementation of the DeakinS1HealthReview task.
57 """
58 __tablename__ = "deakin_1_healthreview" # historically fixed
59 shortname = "Deakin_S1_HealthReview"
61 ethnicity = CamcopsColumn(
62 "ethnicity", Integer,
63 permitted_value_checker=PermittedValueChecker(minimum=1, maximum=16),
64 comment="Ethnicity code, per GMC Patient Questionnaire (1-16)"
65 )
66 ethnicity_text = CamcopsColumn(
67 "ethnicity_text", UnicodeText,
68 exempt_from_anonymisation=True,
69 comment="Ethnicity, description"
70 ) # Seems to be unused by the client!
71 ethnicity_other_details = Column(
72 "ethnicity_other_details", UnicodeText,
73 comment="Ethnicity, other, details"
74 )
76 handedness = CamcopsColumn(
77 "handedness", String(length=1), # was Text
78 permitted_value_checker=PermittedValueChecker(permitted_values=["L", "R"]), # noqa
79 comment="Handedness (L, R)"
80 )
81 education = CamcopsColumn(
82 "education", Text,
83 exempt_from_anonymisation=True
84 )
86 allergies = BoolColumn("allergies")
87 allergy_asthma = BoolColumn("allergy_asthma")
88 allergy_pollen_dust = BoolColumn("allergy_pollen_dust")
89 allergy_dermatitis = BoolColumn("allergy_dermatitis")
90 allergy_food = BoolColumn("allergy_food")
91 allergy_dander = BoolColumn("allergy_dander")
92 allergy_other = BoolColumn("allergy_other")
93 allergy_details = Column("allergy_details", Text)
95 vaccinations_last3months = BoolColumn("vaccinations_last3months")
96 vaccination_details = Column("vaccination_details", Text)
98 infections_last3months = BoolColumn("infections_last3months")
99 infection_recent_respiratory = BoolColumn("infection_recent_respiratory")
100 infection_recent_gastroenteritis = BoolColumn(
101 "infection_recent_gastroenteritis",
102 constraint_name="ck_deakin_1_healthreview_inf_recent_gastro"
103 )
104 infection_recent_urinary = BoolColumn("infection_recent_urinary")
105 infection_recent_sexual = BoolColumn("infection_recent_sexual")
106 infection_recent_hepatitis = BoolColumn("infection_recent_hepatitis")
107 infection_recent_other = BoolColumn("infection_recent_other")
108 infection_recent_details = Column("infection_recent_details", Text)
110 infections_chronic = BoolColumn("infections_chronic")
111 infection_chronic_respiratory = BoolColumn("infection_chronic_respiratory")
112 infection_chronic_gastroenteritis = BoolColumn(
113 "infection_chronic_gastroenteritis",
114 constraint_name="ck_deakin_1_healthreview_inf_chronic_gastro"
115 )
116 infection_chronic_urinary = BoolColumn("infection_chronic_urinary")
117 infection_chronic_sexual = BoolColumn("infection_chronic_sexual")
118 infection_chronic_hepatitis = BoolColumn("infection_chronic_hepatitis")
119 infection_chronic_other = BoolColumn("infection_chronic_other")
120 infection_chronic_details = Column("infection_chronic_details", Text)
122 immune_disorders = BoolColumn("immune_disorders")
123 immunity_ms = BoolColumn("immunity_ms")
124 immunity_sle = BoolColumn("immunity_sle")
125 immunity_arthritis = BoolColumn("immunity_arthritis")
126 immunity_hiv = BoolColumn("immunity_hiv")
127 immunity_graves = BoolColumn("immunity_graves")
128 immunity_diabetes = BoolColumn("immunity_diabetes")
129 immunity_other = BoolColumn("immunity_other")
130 immunity_details = Column("immunity_details", Text)
132 family_history = BoolColumn("family_history")
133 familyhistory_ms = BoolColumn("familyhistory_ms")
134 familyhistory_sle = BoolColumn("familyhistory_sle")
135 familyhistory_arthritis = BoolColumn("familyhistory_arthritis")
136 familyhistory_graves = BoolColumn("familyhistory_graves")
137 familyhistory_diabetes = BoolColumn("familyhistory_diabetes")
138 familyhistory_psychosis_sz = BoolColumn("familyhistory_psychosis_sz")
139 familyhistory_bipolar = BoolColumn("familyhistory_bipolar")
140 familyhistory_details = Column("familyhistory_details", Text)
142 health_anything_else = BoolColumn("health_anything_else")
143 health_anything_else_details = Column(
144 "health_anything_else_details", UnicodeText
145 )
147 drug_history = Column("drug_history", UnicodeText)
148 first_antipsychotic_medication = Column(
149 "first_antipsychotic_medication", UnicodeText
150 )
152 recreational_drug_in_last_3_months = BoolColumn(
153 "recreational_drug_in_last_3_months",
154 constraint_name="ck_deakin_1_healthreview_recdruglast3mo"
155 )
157 recdrug_tobacco_frequency = CamcopsColumn(
158 "recdrug_tobacco_frequency", Integer,
159 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
160 comment=FREQUENCY_COMMENT
161 )
162 recdrug_tobacco_cigsperweek = CamcopsColumn(
163 "recdrug_tobacco_cigsperweek", Integer,
164 permitted_value_checker=MIN_ZERO_CHECKER,
165 comment="Tobacco: cigarettes per week"
166 )
167 recdrug_tobacco_prevheavy = BoolColumn("recdrug_tobacco_prevheavy")
169 recdrug_cannabis_frequency = CamcopsColumn(
170 "recdrug_cannabis_frequency", Integer,
171 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
172 comment=FREQUENCY_COMMENT
173 )
174 recdrug_cannabis_jointsperweek = CamcopsColumn(
175 "recdrug_cannabis_jointsperweek", Integer,
176 permitted_value_checker=MIN_ZERO_CHECKER,
177 comment="Cannabis: joints per week"
178 )
179 recdrug_cannabis_prevheavy = BoolColumn("recdrug_cannabis_prevheavy")
181 recdrug_alcohol_frequency = CamcopsColumn(
182 "recdrug_alcohol_frequency", Integer,
183 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
184 comment=FREQUENCY_COMMENT
185 )
186 recdrug_alcohol_unitsperweek = CamcopsColumn(
187 "recdrug_alcohol_unitsperweek", Integer,
188 permitted_value_checker=MIN_ZERO_CHECKER,
189 comment="Alcohol: units per week")
190 recdrug_alcohol_prevheavy = BoolColumn("recdrug_alcohol_prevheavy")
192 recdrug_mdma_frequency = CamcopsColumn(
193 "recdrug_mdma_frequency", Integer,
194 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
195 comment=FREQUENCY_COMMENT
196 )
197 recdrug_mdma_prevheavy = BoolColumn("recdrug_mdma_prevheavy")
199 recdrug_cocaine_frequency = CamcopsColumn(
200 "recdrug_cocaine_frequency", Integer,
201 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
202 comment=FREQUENCY_COMMENT
203 )
204 recdrug_cocaine_prevheavy = BoolColumn("recdrug_cocaine_prevheavy")
206 recdrug_crack_frequency = CamcopsColumn(
207 "recdrug_crack_frequency", Integer,
208 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
209 comment=FREQUENCY_COMMENT
210 )
211 recdrug_crack_prevheavy = BoolColumn("recdrug_crack_prevheavy")
213 recdrug_heroin_frequency = CamcopsColumn(
214 "recdrug_heroin_frequency", Integer,
215 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
216 comment=FREQUENCY_COMMENT
217 )
218 recdrug_heroin_prevheavy = BoolColumn("recdrug_heroin_prevheavy")
220 recdrug_methadone_frequency = CamcopsColumn(
221 "recdrug_methadone_frequency", Integer,
222 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
223 comment=FREQUENCY_COMMENT
224 )
225 recdrug_methadone_prevheavy = BoolColumn("recdrug_methadone_prevheavy")
227 recdrug_amphetamines_frequency = CamcopsColumn(
228 "recdrug_amphetamines_frequency", Integer,
229 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
230 comment=FREQUENCY_COMMENT
231 )
232 recdrug_amphetamines_prevheavy = BoolColumn(
233 "recdrug_amphetamines_prevheavy",
234 constraint_name="ck_deakin_1_healthreview_amphetprevheavy"
235 )
237 recdrug_benzodiazepines_frequency = CamcopsColumn(
238 "recdrug_benzodiazepines_frequency", Integer,
239 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
240 comment=FREQUENCY_COMMENT
241 )
242 recdrug_benzodiazepines_prevheavy = BoolColumn(
243 "recdrug_benzodiazepines_prevheavy",
244 constraint_name="ck_deakin_1_healthreview_benzoprevheavy"
245 )
247 recdrug_ketamine_frequency = CamcopsColumn(
248 "recdrug_ketamine_frequency", Integer,
249 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
250 comment=FREQUENCY_COMMENT
251 )
252 recdrug_ketamine_prevheavy = BoolColumn("recdrug_ketamine_prevheavy")
254 recdrug_legalhighs_frequency = CamcopsColumn(
255 "recdrug_legalhighs_frequency", Integer,
256 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
257 comment=FREQUENCY_COMMENT
258 )
259 recdrug_legalhighs_prevheavy = BoolColumn("recdrug_legalhighs_prevheavy")
261 recdrug_inhalants_frequency = CamcopsColumn(
262 "recdrug_inhalants_frequency", Integer,
263 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
264 comment=FREQUENCY_COMMENT
265 )
266 recdrug_inhalants_prevheavy = BoolColumn("recdrug_inhalants_prevheavy")
268 recdrug_hallucinogens_frequency = CamcopsColumn(
269 "recdrug_hallucinogens_frequency", Integer,
270 permitted_value_checker=ZERO_TO_FOUR_CHECKER,
271 comment=FREQUENCY_COMMENT
272 )
273 recdrug_hallucinogens_prevheavy = BoolColumn(
274 "recdrug_hallucinogens_prevheavy",
275 constraint_name="ck_deakin_1_healthreview_hallucinogenprevheavy"
276 )
278 recdrug_details = Column("recdrug_details", UnicodeText)
280 recdrug_prevheavy = BoolColumn("recdrug_prevheavy")
281 recdrug_prevheavy_details = Column(
282 "recdrug_prevheavy_details", UnicodeText
283 )
285 mri_claustrophobic = BoolColumn("mri_claustrophobic")
286 mri_difficulty_lying_1_hour = BoolColumn("mri_difficulty_lying_1_hour")
287 mri_nonremovable_metal = BoolColumn("mri_nonremovable_metal")
288 mri_metal_from_operations = BoolColumn("mri_metal_from_operations")
289 mri_tattoos_nicotine_patches = BoolColumn("mri_tattoos_nicotine_patches")
290 mri_worked_with_metal = BoolColumn("mri_worked_with_metal")
291 mri_previous_brain_scan = BoolColumn("mri_previous_brain_scan")
292 mri_previous_brain_scan_details = Column(
293 "mri_previous_brain_scan_details", UnicodeText
294 )
295 other_relevant_things = BoolColumn("other_relevant_things")
296 other_relevant_things_details = Column(
297 "other_relevant_things_details", UnicodeText
298 )
300 willing_to_participate_in_further_studies = BoolColumn(
301 "willing_to_participate_in_further_studies",
302 constraint_name="ck_deakin_1_healthreview_wtpifs"
303 )
305 @staticmethod
306 def longname(req: "CamcopsRequest") -> str:
307 _ = req.gettext
308 return _("Deakin JB — Antibody-mediated psychosis study — health review") # noqa
310 def is_complete(self) -> bool:
311 return (
312 self.all_fields_not_none([
313 "ethnicity",
314 "handedness",
315 "education",
316 "allergies",
317 "vaccinations_last3months",
318 "infections_last3months",
319 "infections_chronic",
320 "immune_disorders",
321 "health_anything_else",
322 "recreational_drug_in_last_3_months",
323 "recdrug_prevheavy",
324 "mri_claustrophobic",
325 "mri_difficulty_lying_1_hour",
326 "mri_nonremovable_metal",
327 "mri_metal_from_operations",
328 "mri_tattoos_nicotine_patches",
329 "mri_worked_with_metal",
330 "mri_previous_brain_scan",
331 "other_relevant_things",
332 "willing_to_participate_in_further_studies"
333 ]) and
334 self.field_contents_valid()
335 )
337 def get_drug_frequency_row(self, fieldname: str) -> str:
338 drug_frequency_dict = {
339 0: "Did not use",
340 1: "Occasionally",
341 2: "Monthly",
342 3: "Weekly",
343 4: "Daily"
344 }
345 frequency = drug_frequency_dict.get(getattr(self, fieldname), None)
346 return tr_qa(fieldname, frequency)
348 def get_task_html(self, req: CamcopsRequest) -> str:
349 def twocol_bool_row(fieldname: str) -> str:
350 return self.get_twocol_bool_row(req, fieldname)
352 return f"""
353 <div class="{CssClass.SUMMARY}">
354 <table class="{CssClass.SUMMARY}">
355 {self.get_is_complete_tr(req)}
356 </table>
357 </div>
358 <table class="{CssClass.TASKDETAIL}">
359 <tr>
360 <th width="50%">Question</th>
361 <th width="50%">Answer</th>
362 </tr>
363 """ + (
364 self.get_twocol_val_row("ethnicity") +
365 # UNUSED BY CLIENT! # self.get_twocol_string_row("ethnicity_text") + # noqa
366 self.get_twocol_string_row("ethnicity_other_details") +
368 self.get_twocol_string_row("handedness") +
370 self.get_twocol_string_row("education") +
372 twocol_bool_row("allergies") +
373 twocol_bool_row("allergy_asthma") +
374 twocol_bool_row("allergy_pollen_dust") +
375 twocol_bool_row("allergy_dermatitis") +
376 twocol_bool_row("allergy_food") +
377 twocol_bool_row("allergy_dander") +
378 twocol_bool_row("allergy_other") +
379 self.get_twocol_string_row("allergy_details") +
381 twocol_bool_row("vaccinations_last3months") +
382 self.get_twocol_string_row("vaccination_details") +
384 twocol_bool_row("infections_last3months") +
385 twocol_bool_row("infection_recent_respiratory") +
386 twocol_bool_row("infection_recent_gastroenteritis") +
387 twocol_bool_row("infection_recent_urinary") +
388 twocol_bool_row("infection_recent_sexual") +
389 twocol_bool_row("infection_recent_hepatitis") +
390 twocol_bool_row("infection_recent_other") +
391 self.get_twocol_string_row("infection_recent_details") +
393 twocol_bool_row("infections_chronic") +
394 twocol_bool_row("infection_chronic_respiratory") +
395 twocol_bool_row("infection_chronic_gastroenteritis") +
396 twocol_bool_row("infection_chronic_urinary") +
397 twocol_bool_row("infection_chronic_sexual") +
398 twocol_bool_row("infection_chronic_hepatitis") +
399 twocol_bool_row("infection_chronic_other") +
400 self.get_twocol_string_row("infection_chronic_details") +
402 twocol_bool_row("immune_disorders") +
403 twocol_bool_row("immunity_ms") +
404 twocol_bool_row("immunity_sle") +
405 twocol_bool_row("immunity_arthritis") +
406 twocol_bool_row("immunity_hiv") +
407 twocol_bool_row("immunity_graves") +
408 twocol_bool_row("immunity_diabetes") +
409 twocol_bool_row("immunity_other") +
410 self.get_twocol_string_row("immunity_details") +
412 twocol_bool_row("family_history") +
413 twocol_bool_row("familyhistory_ms") +
414 twocol_bool_row("familyhistory_sle") +
415 twocol_bool_row("familyhistory_arthritis") +
416 twocol_bool_row("familyhistory_graves") +
417 twocol_bool_row("familyhistory_diabetes") +
418 twocol_bool_row("familyhistory_psychosis_sz") +
419 twocol_bool_row("familyhistory_bipolar") +
420 self.get_twocol_string_row("familyhistory_details") +
422 twocol_bool_row("health_anything_else") +
423 self.get_twocol_string_row("health_anything_else_details") +
425 self.get_twocol_string_row("drug_history") +
426 self.get_twocol_string_row("first_antipsychotic_medication") +
428 twocol_bool_row("recreational_drug_in_last_3_months") +
429 self.get_drug_frequency_row("recdrug_tobacco_frequency") +
430 self.get_twocol_val_row("recdrug_tobacco_cigsperweek") +
431 twocol_bool_row("recdrug_tobacco_prevheavy") +
432 self.get_drug_frequency_row("recdrug_cannabis_frequency") +
433 self.get_twocol_val_row("recdrug_cannabis_jointsperweek") +
434 twocol_bool_row("recdrug_cannabis_prevheavy") +
435 self.get_drug_frequency_row("recdrug_alcohol_frequency") +
436 self.get_twocol_val_row("recdrug_alcohol_unitsperweek") +
437 twocol_bool_row("recdrug_alcohol_prevheavy") +
438 self.get_drug_frequency_row("recdrug_mdma_frequency") +
439 twocol_bool_row("recdrug_mdma_prevheavy") +
440 self.get_drug_frequency_row("recdrug_cocaine_frequency") +
441 twocol_bool_row("recdrug_cocaine_prevheavy") +
442 self.get_drug_frequency_row("recdrug_crack_frequency") +
443 twocol_bool_row("recdrug_crack_prevheavy") +
444 self.get_drug_frequency_row("recdrug_heroin_frequency") +
445 twocol_bool_row("recdrug_heroin_prevheavy") +
446 self.get_drug_frequency_row("recdrug_methadone_frequency") +
447 twocol_bool_row("recdrug_methadone_prevheavy") +
448 self.get_drug_frequency_row("recdrug_amphetamines_frequency") +
449 twocol_bool_row("recdrug_amphetamines_prevheavy") +
450 self.get_drug_frequency_row("recdrug_benzodiazepines_frequency") +
451 twocol_bool_row("recdrug_benzodiazepines_prevheavy") +
452 self.get_drug_frequency_row("recdrug_ketamine_frequency") +
453 twocol_bool_row("recdrug_ketamine_prevheavy") +
454 self.get_drug_frequency_row("recdrug_legalhighs_frequency") +
455 twocol_bool_row("recdrug_legalhighs_prevheavy") +
456 self.get_drug_frequency_row("recdrug_inhalants_frequency") +
457 twocol_bool_row("recdrug_inhalants_prevheavy") +
458 self.get_drug_frequency_row("recdrug_hallucinogens_frequency") +
459 twocol_bool_row("recdrug_hallucinogens_prevheavy") +
460 self.get_twocol_string_row("recdrug_details") +
461 twocol_bool_row("recdrug_prevheavy") +
462 self.get_twocol_string_row("recdrug_prevheavy_details") +
464 twocol_bool_row("mri_claustrophobic") +
465 twocol_bool_row("mri_difficulty_lying_1_hour") +
466 twocol_bool_row("mri_nonremovable_metal") +
467 twocol_bool_row("mri_metal_from_operations") +
468 twocol_bool_row("mri_tattoos_nicotine_patches") +
469 twocol_bool_row("mri_worked_with_metal") +
470 twocol_bool_row("mri_previous_brain_scan") +
471 self.get_twocol_string_row("mri_previous_brain_scan_details") +
472 twocol_bool_row("other_relevant_things") +
473 self.get_twocol_string_row("other_relevant_things_details") +
474 twocol_bool_row(
475 "willing_to_participate_in_further_studies") +
477 "</table>"
478 )