Coverage for tasks/isaaq.py: 76%

33 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/isaaq.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** Internet Severity and Activities Addiction Questionnaire (ISAAQ) task.** 

29 

30""" 

31 

32from typing import Any, Dict, Type, Tuple 

33 

34from cardinal_pythonlib.stringfunc import strseq 

35from sqlalchemy.ext.declarative import DeclarativeMeta 

36from sqlalchemy.sql.sqltypes import Integer 

37 

38from camcops_server.cc_modules.cc_db import add_multiple_columns 

39from camcops_server.cc_modules.cc_request import CamcopsRequest 

40from camcops_server.tasks.isaaqcommon import IsaaqCommon 

41 

42 

43class IsaaqMetaclass(DeclarativeMeta): 

44 def __init__( 

45 cls: Type["Isaaq"], 

46 name: str, 

47 bases: Tuple[Type, ...], 

48 classdict: Dict[str, Any], 

49 ) -> None: 

50 

51 add_multiple_columns( 

52 cls, 

53 cls.A_PREFIX, 

54 cls.FIRST_Q, 

55 cls.LAST_A_Q, 

56 coltype=Integer, 

57 minimum=0, 

58 maximum=5, 

59 comment_fmt=cls.A_PREFIX + "{n} - {s}", 

60 comment_strings=[ 

61 "losing track of time 0-5 (not at all - all the time)", 

62 "block disturbing thoughts 0-5 (not at all - all the time)", 

63 "loneliness or boredom 0-5 (not at all - all the time)", 

64 "neglect normal activities 0-5 (not at all - all the time)", 

65 "choose over intimacy 0-5 (not at all - all the time)", 

66 "financial consequences 0-5 (not at all - all the time)", 

67 "school/study suffers 0-5 (not at all - all the time)", 

68 "check email or social media 0-5 (not at all - all the time)", 

69 "others complain 0-5 (not at all - all the time)", 

70 "defensive or secretive 0-5 (not at all - all the time)", 

71 "try to arrest 0-5 (not at all - all the time)", 

72 "preoccupied when offline 0-5 (not at all - all the time)", 

73 "lose sleep 0-5 (not at all - all the time)", 

74 ( 

75 "physical or psychological problems 0-5 " 

76 "(not at all - all the time)" 

77 ), 

78 "try to cut down 0-5 (not at all - all the time)", 

79 ], 

80 ) 

81 

82 add_multiple_columns( 

83 cls, 

84 cls.B_PREFIX, 

85 cls.FIRST_Q, 

86 cls.LAST_B_Q, 

87 coltype=Integer, 

88 minimum=0, 

89 maximum=5, 

90 comment_fmt=cls.B_PREFIX + "{n} - {s}", 

91 comment_strings=[ 

92 "general surfing 0-5 (not at all - all the time)", 

93 "internet gaming 0-5 (not at all - all the time)", 

94 "skill games 0-5 (not at all - all the time)", 

95 "online shopping 0-5 (not at all - all the time)", 

96 "online gaming 0-5 (not at all - all the time)", 

97 "social networking 0-5 (not at all - all the time)", 

98 "health and medicine 0-5 (not at all - all the time)", 

99 "pornography 0-5 (not at all - all the time)", 

100 "streaming media 0-5 (not at all - all the time)", 

101 "cyberbullying 0-5 (not at all - all the time)", 

102 ], 

103 ) 

104 

105 super().__init__(name, bases, classdict) 

106 

107 

108class Isaaq(IsaaqCommon, metaclass=IsaaqMetaclass): 

109 __tablename__ = "isaaq" 

110 shortname = "ISAAQ" 

111 

112 A_PREFIX = "a" 

113 B_PREFIX = "b" 

114 FIRST_Q = 1 

115 LAST_A_Q = 15 

116 LAST_B_Q = 10 

117 

118 ALL_FIELD_NAMES = strseq(A_PREFIX, FIRST_Q, LAST_A_Q) + strseq( 

119 B_PREFIX, FIRST_Q, LAST_B_Q 

120 ) 

121 

122 @staticmethod 

123 def longname(req: CamcopsRequest) -> str: 

124 _ = req.gettext 

125 return _("Internet Severity and Activities Addiction Questionnaire") 

126 

127 def get_task_html_rows(self, req: CamcopsRequest) -> str: 

128 _ = req.gettext 

129 header_format = """ 

130 <tr> 

131 <th width="70%">{title}</th> 

132 <th width="30%">{score}</th> 

133 </tr> 

134 """ 

135 

136 # "Scale" is a visual thing for the original; use "score" here. 

137 score_text = _("Score") 

138 a_header = header_format.format( 

139 title=self.xstring(req, "a_title"), 

140 score=score_text, 

141 ) 

142 b_header = header_format.format( 

143 title=self.xstring(req, "b_title"), 

144 score=score_text, 

145 ) 

146 

147 return ( 

148 a_header 

149 + self.get_task_html_rows_for_range( 

150 req, self.A_PREFIX, self.FIRST_Q, self.LAST_A_Q 

151 ) 

152 + b_header 

153 + self.get_task_html_rows_for_range( 

154 req, self.B_PREFIX, self.FIRST_Q, self.LAST_B_Q 

155 ) 

156 )