Coverage for tasks/fft.py: 68%
28 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/fft.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"""
30from sqlalchemy.sql.schema import Column
31from sqlalchemy.sql.sqltypes import Integer, UnicodeText
33from camcops_server.cc_modules.cc_constants import CssClass
34from camcops_server.cc_modules.cc_html import tr_qa
35from camcops_server.cc_modules.cc_request import CamcopsRequest
36from camcops_server.cc_modules.cc_sqla_coltypes import (
37 CamcopsColumn,
38 PermittedValueChecker,
39)
40from camcops_server.cc_modules.cc_string import AS
41from camcops_server.cc_modules.cc_task import (
42 get_from_dict,
43 Task,
44 TaskHasPatientMixin,
45)
48# =============================================================================
49# FFT
50# =============================================================================
53class Fft(TaskHasPatientMixin, Task):
54 """
55 Server implementation of the FFT task.
56 """
58 __tablename__ = "fft"
59 shortname = "FFT"
61 service = Column(
62 "service", UnicodeText, comment="Clinical service being rated"
63 )
64 rating = CamcopsColumn(
65 "rating",
66 Integer,
67 permitted_value_checker=PermittedValueChecker(minimum=1, maximum=6),
68 comment="Likelihood of recommendation to friends/family (1 "
69 "extremely likely - 5 extremely unlikely, 6 don't know)",
70 )
72 @staticmethod
73 def longname(req: "CamcopsRequest") -> str:
74 _ = req.gettext
75 return _("Friends and Family Test")
77 def is_complete(self) -> bool:
78 return self.rating is not None and self.field_contents_valid()
80 def get_rating_text(self, req: CamcopsRequest) -> str:
81 ratingdict = {
82 None: None,
83 1: self.wxstring(req, "a1"),
84 2: self.wxstring(req, "a2"),
85 3: self.wxstring(req, "a3"),
86 4: self.wxstring(req, "a4"),
87 5: self.wxstring(req, "a5"),
88 6: self.wxstring(req, "a6"),
89 }
90 return get_from_dict(ratingdict, self.rating)
92 def get_task_html(self, req: CamcopsRequest) -> str:
93 if self.rating is not None:
94 r = f"{self.rating}. {self.get_rating_text(req)}"
95 else:
96 r = 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(req.wappstring(AS.SATIS_SERVICE_BEING_RATED),
109 self.service)}
110 {tr_qa(self.wxstring(req, "q"), r)}
111 </table>
112 """