Coverage for tasks/irac.py: 69%
29 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
1"""
2camcops_server/tasks/irac.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
11 CamCOPS is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CamCOPS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26"""
28from typing import Optional
29import cardinal_pythonlib.rnc_web as ws
31from sqlalchemy.orm import Mapped, mapped_column
32from sqlalchemy.sql.sqltypes import 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 mapped_camcops_column,
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# =============================================================================
53class Irac(TaskHasPatientMixin, Task): # type: ignore[misc]
54 """
55 Server implementation of the IRAC task.
56 """
58 __tablename__ = "irac"
59 shortname = "IRAC"
61 aim: Mapped[Optional[str]] = mapped_column(
62 UnicodeText, comment="Main aim of the contact"
63 )
64 achieved: Mapped[Optional[int]] = mapped_camcops_column(
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 (
78 self.all_fields_not_none(self.TASK_FIELDS)
79 and self.field_contents_valid()
80 )
82 def get_achieved_text(self, req: CamcopsRequest) -> str:
83 achieveddict = {
84 None: None,
85 0: self.wxstring(req, "achieved_0"),
86 1: self.wxstring(req, "achieved_1"),
87 2: self.wxstring(req, "achieved_2"),
88 }
89 return get_from_dict(achieveddict, self.achieved)
91 def get_task_html(self, req: CamcopsRequest) -> str:
92 if self.achieved is not None:
93 achieved = f"{self.achieved}. {self.get_achieved_text(req)}"
94 else:
95 achieved = None
96 return f"""
97 <div class="{CssClass.SUMMARY}">
98 <table class="{CssClass.SUMMARY}">
99 {self.get_is_complete_tr(req)}
100 </table>
101 </div>
102 <table class="{CssClass.TASKDETAIL}">
103 <tr>
104 <th width="50%">Question</th>
105 <th width="50%">Answer</th>
106 </tr>
107 {tr_qa(self.wxstring(req, "q_aim"), ws.webify(self.aim))}
108 {tr_qa(self.wxstring(req, "q_achieved"), achieved)}
109 </table>
110 """