Coverage for tasks/isaaqcommon.py: 40%
35 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/tasks/isaaq.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
28** Common functionality for Internet Severity and Activities Addiction
29 Questionnaire (ISAAQ) tasks.**
31"""
33from typing import Optional
35from camcops_server.cc_modules.cc_constants import CssClass
36from camcops_server.cc_modules.cc_html import tr_qa
37from camcops_server.cc_modules.cc_request import CamcopsRequest
38from camcops_server.cc_modules.cc_task import Task, TaskHasPatientMixin
41# noinspection PyAbstractClass
42class IsaaqCommon(TaskHasPatientMixin, Task):
43 __abstract__ = True
45 def is_complete(self) -> bool:
46 # noinspection PyUnresolvedReferences
47 if self.any_fields_none(self.ALL_FIELD_NAMES):
48 return False
50 return True
52 def get_task_html(self, req: CamcopsRequest) -> str:
53 rows = self.get_task_html_rows(req)
55 html = """
56 <div class="{CssClass.SUMMARY}">
57 <table class="{CssClass.SUMMARY}">
58 {tr_is_complete}
59 </table>
60 </div>
61 <table class="{CssClass.TASKDETAIL}">
62 {rows}
63 </table>
64 <div class="{CssClass.FOOTNOTES}">
65 </div>
66 """.format(
67 CssClass=CssClass,
68 tr_is_complete=self.get_is_complete_tr(req),
69 rows=rows,
70 )
71 return html
73 def get_task_html_rows(self, req: CamcopsRequest) -> str:
74 raise NotImplementedError
76 def get_task_html_rows_for_range(
77 self, req: CamcopsRequest, prefix: str, first_q: int, last_q: int
78 ):
79 rows = ""
80 for q_num in range(first_q, last_q + 1):
81 field = prefix + str(q_num)
82 question_cell = f"{q_num}. {self.xstring(req, field)}"
84 rows += tr_qa(
85 question_cell, self.get_answer_cell(req, prefix, q_num)
86 )
88 return rows
90 def get_answer_cell(
91 self, req: CamcopsRequest, prefix: str, q_num: int
92 ) -> Optional[str]:
93 q_field = prefix + str(q_num)
95 score = getattr(self, q_field)
96 if score is None:
97 return score
99 meaning = self.get_score_meaning(req, score)
101 answer_cell = f"{score} [{meaning}]"
103 return answer_cell
105 def get_score_meaning(self, req: CamcopsRequest, score: int) -> str:
106 return self.wxstring(req, f"freq_option_{score}")