Coverage for tasks/isaaqed.py: 71%

1"""

2 camcops_server/tasks/isaaqed.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, Eating Disorders

27 Appendix (ISAAQ-ED) task. **

28

29"""

30

31 from typing import Any, Type

32

33 from cardinal_pythonlib.stringfunc import strseq

34 from sqlalchemy.sql.sqltypes import Integer

35

36 from camcops_server.cc_modules.cc_db import add_multiple_columns

37 from camcops_server.cc_modules.cc_request import CamcopsRequest

38 from camcops_server.tasks.isaaqcommon import IsaaqCommon

39

40

41 class IsaaqEd(

42 IsaaqCommon,

43):

44 __tablename__ = "isaaqed"

45 shortname = "ISAAQ-ED"

46

47 Q_PREFIX = "e"

48 FIRST_Q = 11

49 LAST_Q = 20

50

51 @classmethod

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

53

54 add_multiple_columns(

55 cls,

56 cls.Q_PREFIX,

57 cls.FIRST_Q,

58 cls.LAST_Q,

59 coltype=Integer,

60 minimum=0,

61 maximum=5,

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

63 comment_strings=[

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

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

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

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

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

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

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

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

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

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

74 ],

75 )

76

77 ALL_FIELD_NAMES = strseq(Q_PREFIX, FIRST_Q, LAST_Q)

78

79 @staticmethod

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

81 _ = req.gettext

82 return _(

83 "Internet Severity and Activities Addiction Questionnaire, "

84 "Eating Disorders Appendix"

85 )

86

87 def is_complete(self) -> bool:

88 if self.any_fields_none(self.ALL_FIELD_NAMES):

89 return False

90

91 return True

92

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

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

95 _ = req.gettext

96 header = """

97 <tr>

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

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

100 </tr>

101 """.format(

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

103 score=_("Score"),

104 )

105

106 return header + self.get_task_html_rows_for_range(

107 req, self.Q_PREFIX, self.FIRST_Q, self.LAST_Q

108 )