Coverage for tasks/isaaqed.py: 74%

31 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/isaaqed.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, Eating Disorders 

29 Appendix (ISAAQ-ED) task. ** 

30 

31""" 

32 

33from typing import Any, Dict, Type, Tuple 

34 

35from cardinal_pythonlib.stringfunc import strseq 

36from sqlalchemy.ext.declarative import DeclarativeMeta 

37from sqlalchemy.sql.sqltypes import Integer 

38 

39from camcops_server.cc_modules.cc_db import add_multiple_columns 

40from camcops_server.cc_modules.cc_request import CamcopsRequest 

41from camcops_server.tasks.isaaqcommon import IsaaqCommon 

42 

43 

44class IsaaqEdMetaclass(DeclarativeMeta): 

45 def __init__( 

46 cls: Type["IsaaqEd"], 

47 name: str, 

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

49 classdict: Dict[str, Any], 

50 ) -> None: 

51 

52 add_multiple_columns( 

53 cls, 

54 cls.Q_PREFIX, 

55 cls.FIRST_Q, 

56 cls.LAST_Q, 

57 coltype=Integer, 

58 minimum=0, 

59 maximum=5, 

60 comment_fmt=cls.Q_PREFIX + "{n} - {s}", 

61 comment_strings=[ 

62 "pro-ED websites 0-5 (not at all - all the time)", 

63 "fitspiration 0-5 (not at all - all the time)", 

64 "thinspiration 0-5 (not at all - all the time)", 

65 "bonespiration 0-5 (not at all - all the time)", 

66 "online dating 0-5 (not at all - all the time)", 

67 "calorie tracking 0-5 (not at all - all the time)", 

68 "fitness tracking 0-5 (not at all - all the time)", 

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

70 "mukbang 0-5 (not at all - all the time)", 

71 "appearance-focused gaming 0-5 (not at all - all the time)", 

72 ], 

73 ) 

74 

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

76 

77 

78class IsaaqEd(IsaaqCommon, metaclass=IsaaqEdMetaclass): 

79 __tablename__ = "isaaqed" 

80 shortname = "ISAAQ-ED" 

81 

82 Q_PREFIX = "e" 

83 FIRST_Q = 11 

84 LAST_Q = 20 

85 

86 ALL_FIELD_NAMES = strseq(Q_PREFIX, FIRST_Q, LAST_Q) 

87 

88 @staticmethod 

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

90 _ = req.gettext 

91 return _( 

92 "Internet Severity and Activities Addiction Questionnaire, " 

93 "Eating Disorders Appendix" 

94 ) 

95 

96 def is_complete(self) -> bool: 

97 if self.any_fields_none(self.ALL_FIELD_NAMES): 

98 return False 

99 

100 return True 

101 

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

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

104 _ = req.gettext 

105 header = """ 

106 <tr> 

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

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

109 </tr> 

110 """.format( 

111 title=self.xstring(req, "grid_title"), 

112 score=_("Score"), 

113 ) 

114 

115 return header + self.get_task_html_rows_for_range( 

116 req, self.Q_PREFIX, self.FIRST_Q, self.LAST_Q 

117 )