Coverage for tasks/srs.py: 67%

42 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 23:14 +0000

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/tasks/srs.py 

5 

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

7 

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

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

10 

11 This file is part of CamCOPS. 

12 

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. 

17 

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. 

22 

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

25 

26=============================================================================== 

27 

28- By Joe Kearney, Rudolf Cardinal. 

29 

30""" 

31 

32from typing import List 

33 

34from sqlalchemy.sql.sqltypes import Date, Float, Integer 

35 

36from camcops_server.cc_modules.cc_constants import CssClass 

37from camcops_server.cc_modules.cc_html import tr_qa 

38from camcops_server.cc_modules.cc_request import CamcopsRequest 

39from camcops_server.cc_modules.cc_sqla_coltypes import ( 

40 CamcopsColumn, 

41 ZERO_TO_10_CHECKER, 

42) 

43from camcops_server.cc_modules.cc_summaryelement import SummaryElement 

44from camcops_server.cc_modules.cc_task import Task, TaskHasPatientMixin 

45 

46 

47# ============================================================================= 

48# SRS 

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

50 

51 

52class Srs(TaskHasPatientMixin, Task): 

53 """ 

54 Server implementation of the SRS task. 

55 """ 

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

71 Float, 

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

73 permitted_value_checker=ZERO_TO_10_CHECKER, 

74 ) 

75 q_goals = CamcopsColumn( 

76 "q_goals", 

77 Float, 

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

79 permitted_value_checker=ZERO_TO_10_CHECKER, 

80 ) 

81 q_approach = CamcopsColumn( 

82 "q_approach", 

83 Float, 

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

85 permitted_value_checker=ZERO_TO_10_CHECKER, 

86 ) 

87 q_overall = CamcopsColumn( 

88 "q_overall", 

89 Float, 

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

91 permitted_value_checker=ZERO_TO_10_CHECKER, 

92 ) 

93 

94 @staticmethod 

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

96 _ = req.gettext 

97 return _("Session Rating Scale") 

98 

99 def is_complete(self) -> bool: 

100 required_always = [ 

101 "q_session", 

102 "q_date", 

103 "q_relationship", 

104 "q_goals", 

105 "q_approach", 

106 "q_overall", 

107 ] 

108 for field in required_always: 

109 if getattr(self, field) is None: 

110 return False 

111 return True 

112 

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

114 return self.standard_task_summary_fields() 

115 

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

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

118 q_a = "" 

119 for field in fields: 

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

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

122 

123 return f""" 

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

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

126 {self.get_is_complete_tr(req)} 

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

128 </table> 

129 </div> 

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

131 Scores represent a selection on a scale from 

132 {self.VAS_MIN_INT} to {self.VAS_MAX_INT} 

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

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

135 </div> 

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

137 <tr> 

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

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

140 </tr> 

141 {q_a} 

142 </table> 

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

144 </div> 

145 """