Coverage for tasks/isaaq10.py: 74%

31 statements  

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

1""" 

2camcops_server/tasks/isaaq10.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** Internet Severity and Activities Addiction Questionnaire, 10-items 

27 (ISAAQ-10) task.** 

28 

29""" 

30 

31from typing import Any, Type 

32 

33from cardinal_pythonlib.stringfunc import strseq 

34from sqlalchemy.sql.sqltypes import Integer 

35 

36from camcops_server.cc_modules.cc_db import add_multiple_columns 

37from camcops_server.cc_modules.cc_request import CamcopsRequest 

38from camcops_server.tasks.isaaqcommon import IsaaqCommon 

39 

40 

41class Isaaq10( 

42 IsaaqCommon, 

43): 

44 __tablename__ = "isaaq10" 

45 shortname = "ISAAQ-10" 

46 

47 prohibits_commercial = True 

48 

49 A_PREFIX = "a" 

50 B_PREFIX = "b" 

51 FIRST_Q = 1 

52 LAST_A_Q = 10 

53 LAST_B_Q = 10 

54 

55 @classmethod 

56 def extend_columns(cls: Type["Isaaq10"], **kwargs: Any) -> None: 

57 add_multiple_columns( 

58 cls, 

59 cls.A_PREFIX, 

60 cls.FIRST_Q, 

61 cls.LAST_A_Q, 

62 coltype=Integer, 

63 minimum=0, 

64 maximum=5, 

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

66 comment_strings=[ 

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

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

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

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

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

72 "try to stop 0-5 (not at all - all the time)", 

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

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

75 "physical or psychological problems 0-5 " 

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

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

78 ], 

79 ) 

80 

81 add_multiple_columns( 

82 cls, 

83 cls.B_PREFIX, 

84 cls.FIRST_Q, 

85 cls.LAST_B_Q, 

86 coltype=Integer, 

87 minimum=0, 

88 maximum=5, 

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

90 comment_strings=[ 

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

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

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

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

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

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

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

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

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

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

101 ], 

102 ) 

103 

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

105 B_PREFIX, FIRST_Q, LAST_B_Q 

106 ) 

107 

108 @staticmethod 

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

110 _ = req.gettext 

111 return _( 

112 "Internet Severity and Activities Addiction Questionnaire," 

113 " 10-items" 

114 ) 

115 

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

117 _ = req.gettext 

118 header_format = """ 

119 <tr> 

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

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

122 </tr> 

123 """ 

124 

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

126 score_text = _("Score") 

127 a_header = header_format.format( 

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

129 score=score_text, 

130 ) 

131 b_header = header_format.format( 

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

133 score=score_text, 

134 ) 

135 

136 return ( 

137 a_header 

138 + self.get_task_html_rows_for_range( 

139 req, self.A_PREFIX, self.FIRST_Q, self.LAST_A_Q 

140 ) 

141 + b_header 

142 + self.get_task_html_rows_for_range( 

143 req, self.B_PREFIX, self.FIRST_Q, self.LAST_B_Q 

144 ) 

145 )