Coverage for tasks/irac.py: 69%
29 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/irac.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"""
30import cardinal_pythonlib.rnc_web as ws
32from sqlalchemy.sql.schema import Column
33from sqlalchemy.sql.sqltypes import Integer, UnicodeText
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_sqla_coltypes import (
39 CamcopsColumn,
40 ZERO_TO_TWO_CHECKER,
41)
42from camcops_server.cc_modules.cc_task import (
43 get_from_dict,
44 Task,
45 TaskHasPatientMixin,
46)
49# =============================================================================
50# IRAC
51# =============================================================================
54class Irac(TaskHasPatientMixin, Task):
55 """
56 Server implementation of the IRAC task.
57 """
59 __tablename__ = "irac"
60 shortname = "IRAC"
62 aim = Column("aim", UnicodeText, comment="Main aim of the contact")
63 achieved = CamcopsColumn(
64 "achieved",
65 Integer,
66 permitted_value_checker=ZERO_TO_TWO_CHECKER,
67 comment="Was the aim achieved? (0 not, 1 partially, 2 fully)",
68 )
70 TASK_FIELDS = ["aim", "achieved"]
72 @staticmethod
73 def longname(req: "CamcopsRequest") -> str:
74 _ = req.gettext
75 return _("Identify and Rate the Aim of the Contact")
77 def is_complete(self) -> bool:
78 return (
79 self.all_fields_not_none(self.TASK_FIELDS)
80 and self.field_contents_valid()
81 )
83 def get_achieved_text(self, req: CamcopsRequest) -> str:
84 achieveddict = {
85 None: None,
86 0: self.wxstring(req, "achieved_0"),
87 1: self.wxstring(req, "achieved_1"),
88 2: self.wxstring(req, "achieved_2"),
89 }
90 return get_from_dict(achieveddict, self.achieved)
92 def get_task_html(self, req: CamcopsRequest) -> str:
93 if self.achieved is not None:
94 achieved = f"{self.achieved}. {self.get_achieved_text(req)}"
95 else:
96 achieved = None
97 return f"""
98 <div class="{CssClass.SUMMARY}">
99 <table class="{CssClass.SUMMARY}">
100 {self.get_is_complete_tr(req)}
101 </table>
102 </div>
103 <table class="{CssClass.TASKDETAIL}">
104 <tr>
105 <th width="50%">Question</th>
106 <th width="50%">Answer</th>
107 </tr>
108 {tr_qa(self.wxstring(req, "q_aim"), ws.webify(self.aim))}
109 {tr_qa(self.wxstring(req, "q_achieved"), achieved)}
110 </table>
111 """