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/srs.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 Date, Float, Integer 

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 ZERO_TO_10_CHECKER 

41) 

42from camcops_server.cc_modules.cc_summaryelement import SummaryElement 

43from camcops_server.cc_modules.cc_task import ( 

44 Task, 

45 TaskHasPatientMixin, 

46) 

47 

48 

49# ============================================================================= 

50# SRS 

51# ============================================================================= 

52 

53class Srs(TaskHasPatientMixin, Task): 

54 """ 

55 Server implementation of the SRS task. 

56 """ 

57 __tablename__ = "srs" 

58 shortname = "SRS" 

59 provides_trackers = True 

60 

61 COMPLETED_BY_SELF = 0 

62 COMPLETED_BY_OTHER = 1 

63 

64 VAS_MIN_INT = 0 

65 VAS_MAX_INT = 10 

66 

67 q_session = CamcopsColumn("q_session", Integer, comment="Session number") 

68 q_date = CamcopsColumn("q_date", Date, comment="Session date") 

69 q_relationship = CamcopsColumn( 

70 "q_relationship", Float, 

71 comment="Rating of patient-therapist relationship (0-10, 10 better)", 

72 permitted_value_checker=ZERO_TO_10_CHECKER) 

73 q_goals = CamcopsColumn( 

74 "q_goals", Float, 

75 comment="Rating for topics discussed (0-10, 10 better)", 

76 permitted_value_checker=ZERO_TO_10_CHECKER) 

77 q_approach = CamcopsColumn( 

78 "q_approach", Float, 

79 comment="Rating for therapist's approach (0-10, 10 better)", 

80 permitted_value_checker=ZERO_TO_10_CHECKER) 

81 q_overall = CamcopsColumn( 

82 "q_overall", Float, 

83 comment="Overall rating (0-10, 10 better)", 

84 permitted_value_checker=ZERO_TO_10_CHECKER) 

85 

86 @staticmethod 

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

88 _ = req.gettext 

89 return _("Session Rating Scale") 

90 

91 def is_complete(self) -> bool: 

92 required_always = [ 

93 "q_session", 

94 "q_date", 

95 "q_relationship", 

96 "q_goals", 

97 "q_approach", 

98 "q_overall", 

99 ] 

100 for field in required_always: 

101 if getattr(self, field) is None: 

102 return False 

103 return True 

104 

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

106 return self.standard_task_summary_fields() 

107 

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

109 fields = ["q_relationship", "q_goals", "q_approach", "q_overall"] 

110 q_a = "" 

111 for field in fields: 

112 question = field.split("_")[1].capitalize() 

113 q_a += tr_qa(question, getattr(self, field)) 

114 

115 return f""" 

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

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

118 {self.get_is_complete_tr(req)} 

119 {tr_qa("Session number", self.q_session)} 

120 </table> 

121 </div> 

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

123 Scores represent a selection on a scale from 

124 {self.VAS_MIN_INT} to {self.VAS_MAX_INT} 

125 ({self.VAS_MAX_INT} better). Scores indicate the patient’s 

126 feelings about different aspects of the day’s therapy session. 

127 </div> 

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

129 <tr> 

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

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

132 </tr> 

133 {q_a} 

134 </table> 

135 <div class="{CssClass.FOOTNOTES}"> 

136 </div> 

137 """