Hide keyboard shortcuts

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 

2 

3""" 

4camcops_server/tasks/apeqpt.py 

5 

6=============================================================================== 

7 

8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com). 

9 

10 This file is part of CamCOPS. 

11 

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. 

16 

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. 

21 

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

24 

25=============================================================================== 

26 

27- By Joe Kearney, Rudolf Cardinal. 

28 

29""" 

30 

31from typing import List 

32 

33from sqlalchemy.sql.sqltypes import Integer, UnicodeText 

34 

35from camcops_server.cc_modules.cc_constants import CssClass 

36from camcops_server.cc_modules.cc_html import tr_qa 

37from camcops_server.cc_modules.cc_request import CamcopsRequest 

38from camcops_server.cc_modules.cc_sqla_coltypes import ( 

39 CamcopsColumn, 

40 PendulumDateTimeAsIsoTextColType, 

41 ZERO_TO_ONE_CHECKER, 

42 ZERO_TO_TWO_CHECKER, 

43 ZERO_TO_FOUR_CHECKER 

44) 

45from camcops_server.cc_modules.cc_summaryelement import SummaryElement 

46from camcops_server.cc_modules.cc_task import ( 

47 get_from_dict, 

48 Task, 

49) 

50 

51 

52# ============================================================================= 

53# APEQPT 

54# ============================================================================= 

55 

56class Apeqpt(Task): 

57 """ 

58 Server implementation of the APEQPT task. 

59 """ 

60 __tablename__ = "apeqpt" 

61 shortname = "APEQPT" 

62 provides_trackers = True 

63 

64 q_datetime = CamcopsColumn( 

65 "q_datetime", PendulumDateTimeAsIsoTextColType, 

66 comment="Date/time the assessment tool was completed") 

67 

68 N_CHOICE_QUESTIONS = 3 

69 q1_choice = CamcopsColumn( 

70 "q1_choice", Integer, 

71 comment="Enough information was provided (0 no, 1 yes)", 

72 permitted_value_checker=ZERO_TO_ONE_CHECKER) 

73 q2_choice = CamcopsColumn( 

74 "q2_choice", Integer, 

75 comment="Treatment preference (0 no, 1 yes)", 

76 permitted_value_checker=ZERO_TO_ONE_CHECKER) 

77 q3_choice = CamcopsColumn( 

78 "q3_choice", Integer, 

79 comment="Preference offered (0 no, 1 yes, 2 N/A)", 

80 permitted_value_checker=ZERO_TO_TWO_CHECKER) 

81 

82 q1_satisfaction = CamcopsColumn( 

83 "q1_satisfaction", Integer, 

84 comment=( 

85 "Patient satisfaction (0 not at all satisfied - " 

86 "4 completely satisfied)" 

87 ), 

88 permitted_value_checker=ZERO_TO_FOUR_CHECKER) 

89 q2_satisfaction = CamcopsColumn( 

90 "q2_satisfaction", UnicodeText, 

91 comment="Service experience") 

92 

93 MAIN_QUESTIONS = [ 

94 "q_datetime", 

95 "q1_choice", 

96 "q2_choice", 

97 "q3_choice", 

98 "q1_satisfaction", 

99 ] 

100 

101 @staticmethod 

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

103 _ = req.gettext 

104 return _("Assessment Patient Experience Questionnaire " 

105 "for Psychological Therapies") 

106 

107 def is_complete(self) -> bool: 

108 if self.any_fields_none(self.MAIN_QUESTIONS): 

109 return False 

110 if not self.field_contents_valid(): 

111 return False 

112 return True 

113 

114 def get_summaries(self, req: CamcopsRequest) -> List[SummaryElement]: 

115 return self.standard_task_summary_fields() 

116 

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

118 c_dict = { 

119 0: "0 — " + self.wxstring(req, "a0_choice"), 

120 1: "1 — " + self.wxstring(req, "a1_choice"), 

121 2: "2 — " + self.wxstring(req, "a2_choice"), 

122 } 

123 s_dict = { 

124 0: "0 — " + self.wxstring(req, "a0_satisfaction"), 

125 1: "1 — " + self.wxstring(req, "a1_satisfaction"), 

126 2: "2 — " + self.wxstring(req, "a2_satisfaction"), 

127 3: "3 — " + self.wxstring(req, "a3_satisfaction"), 

128 4: "4 — " + self.wxstring(req, "a4_satisfaction"), 

129 } 

130 q_a = "" 

131 for i in range(1, self.N_CHOICE_QUESTIONS + 1): 

132 nstr = str(i) 

133 q_a += tr_qa( 

134 self.wxstring(req, "q" + nstr + "_choice"), 

135 get_from_dict(c_dict, getattr(self, "q" + nstr + "_choice"))) 

136 

137 q_a += tr_qa(self.wxstring(req, "q1_satisfaction"), 

138 get_from_dict(s_dict, self.q1_satisfaction)) 

139 q_a += tr_qa(self.wxstring(req, "q2_satisfaction"), 

140 self.q2_satisfaction, default="") 

141 

142 return f""" 

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

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

145 {self.get_is_complete_tr(req)} 

146 </table> 

147 </div> 

148 <div class="{CssClass.EXPLANATION}"> 

149 Patient satisfaction rating for service provided. The service 

150 is rated on choice offered and general satisfaction. 

151 </div> 

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

153 <tr> 

154 <th width="60%">Question</th> 

155 <th width="40%">Answer</th> 

156 </tr> 

157 {q_a} 

158 </table> 

159 """