Coverage for tasks/fft.py: 68%

28 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-15 14:23 +0100

1""" 

2camcops_server/tasks/fft.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CamCOPS. 

10 

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. 

15 

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. 

20 

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/>. 

23 

24=============================================================================== 

25 

26""" 

27 

28from typing import Optional 

29 

30from sqlalchemy.orm import Mapped, mapped_column 

31from sqlalchemy.sql.sqltypes import UnicodeText 

32 

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 mapped_camcops_column, 

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) 

46 

47 

48# ============================================================================= 

49# FFT 

50# ============================================================================= 

51 

52 

53class Fft(TaskHasPatientMixin, Task): # type: ignore[misc] 

54 """ 

55 Server implementation of the FFT task. 

56 """ 

57 

58 __tablename__ = "fft" 

59 shortname = "FFT" 

60 

61 service: Mapped[Optional[str]] = mapped_column( 

62 UnicodeText, comment="Clinical service being rated" 

63 ) 

64 rating: Mapped[Optional[int]] = mapped_camcops_column( 

65 permitted_value_checker=PermittedValueChecker(minimum=1, maximum=6), 

66 comment="Likelihood of recommendation to friends/family (1 " 

67 "extremely likely - 5 extremely unlikely, 6 don't know)", 

68 ) 

69 

70 @staticmethod 

71 def longname(req: "CamcopsRequest") -> str: 

72 _ = req.gettext 

73 return _("Friends and Family Test") 

74 

75 def is_complete(self) -> bool: 

76 return self.rating is not None and self.field_contents_valid() 

77 

78 def get_rating_text(self, req: CamcopsRequest) -> str: 

79 ratingdict = { 

80 None: None, 

81 1: self.wxstring(req, "a1"), 

82 2: self.wxstring(req, "a2"), 

83 3: self.wxstring(req, "a3"), 

84 4: self.wxstring(req, "a4"), 

85 5: self.wxstring(req, "a5"), 

86 6: self.wxstring(req, "a6"), 

87 } 

88 return get_from_dict(ratingdict, self.rating) 

89 

90 def get_task_html(self, req: CamcopsRequest) -> str: 

91 if self.rating is not None: 

92 r = f"{self.rating}. {self.get_rating_text(req)}" 

93 else: 

94 r = None 

95 return f""" 

96 <div class="{CssClass.SUMMARY}"> 

97 <table class="{CssClass.SUMMARY}"> 

98 {self.get_is_complete_tr(req)} 

99 </table> 

100 </div> 

101 <table class="{CssClass.TASKDETAIL}"> 

102 <tr> 

103 <th width="50%">Question</th> 

104 <th width="50%">Answer</th> 

105 </tr> 

106 {tr_qa(req.wappstring(AS.SATIS_SERVICE_BEING_RATED), 

107 self.service)} 

108 {tr_qa(self.wxstring(req, "q"), r)} 

109 </table> 

110 """