Coverage for tasks/fft.py : 68%

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