Coverage for tasks/irac.py : 69%

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