Coverage for cc_modules/cc_text.py: 37%

134 statements  

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

1""" 

2camcops_server/cc_modules/cc_text.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**Text used by the server, and translated.** 

27 

28""" 

29 

30from enum import auto, Enum, unique 

31from typing import TYPE_CHECKING 

32 

33from pendulum import Date 

34 

35if TYPE_CHECKING: 

36 from camcops_server.cc_modules.cc_request import CamcopsRequest 

37 

38 

39TERMS_CONDITIONS_UPDATE_DATE = Date(2020, 6, 29) 

40 

41 

42@unique 

43class SS(Enum): 

44 """ 

45 Server string enumeration. All elements have type ``<enum 'SS'>`` and 

46 ``isinstance(SS.ANSWER, SS)`` is true. 

47 """ 

48 

49 ABNORMAL = auto() 

50 ABSENT = auto() 

51 ABSENT_OR_MILD = auto() 

52 ANONYMOUS_TASK = auto() 

53 ANSWER = auto() 

54 AUDITORY = auto() 

55 

56 CATEGORY = auto() 

57 

58 DISCLAIMER_TITLE = auto() 

59 DISCLAIMER_SUBTITLE = auto() 

60 DISCLAIMER_CONTENT = auto() 

61 DISCLAIMER_AGREE = auto() 

62 

63 EVENT = auto() 

64 

65 FALSE = auto() 

66 FEMALE = auto() 

67 

68 GENERAL = auto() 

69 GLOBAL_SCORE = auto() 

70 

71 IF_APPLICABLE = auto() 

72 

73 LOCATION = auto() 

74 

75 MALE = auto() 

76 MEETS_CRITERIA = auto() 

77 MILD = auto() 

78 MILD_TO_MODERATE = auto() 

79 MODERATE = auto() 

80 MODERATELY_SEVERE = auto() 

81 MODERATE_TO_SEVERE = auto() 

82 

83 NA = auto() 

84 NO = auto() 

85 NONE = auto() 

86 NORMAL = auto() 

87 NOTE = auto() 

88 

89 PRESENT = auto() 

90 

91 QUESTION = auto() 

92 

93 SEVERE = auto() 

94 SEX = auto() 

95 

96 TOTAL_SCORE = auto() 

97 TRUE = auto() 

98 

99 UNKNOWN = auto() 

100 

101 VERY_SEVERE = auto() 

102 VISUAL = auto() 

103 VOLUME_0_TO_1 = auto() 

104 

105 YES = auto() 

106 

107 

108def server_string(req: "CamcopsRequest", w: SS) -> str: 

109 """ 

110 Returns a translated server string. 

111 

112 Use this mechanism when the same string is re-used in several places in 

113 the server (but not by the client). 

114 

115 Args: 

116 req: 

117 a :class:`camcops_server.cc_modules.cc_request.CamcopsRequest` 

118 w: 

119 which string? A :class:`camcops_server.cc_modules.cc_text.SS` 

120 enumeration value 

121 

122 Returns: 

123 the translated string 

124 

125 """ 

126 _ = req.gettext 

127 

128 if w == SS.ABNORMAL: 

129 return _("Abnormal") 

130 elif w == SS.ABSENT: 

131 return _("Absent") 

132 elif w == SS.ABSENT_OR_MILD: 

133 return _("Absent or mild") 

134 elif w == SS.ANONYMOUS_TASK: 

135 return _("Anonymous task") 

136 elif w == SS.ANSWER: 

137 return _("Answer") 

138 elif w == SS.AUDITORY: 

139 return _("Auditory") 

140 

141 elif w == SS.CATEGORY: 

142 return _("Category") 

143 

144 elif w == SS.DISCLAIMER_TITLE: 

145 return _("TERMS AND CONDITIONS OF USE") 

146 elif w == SS.DISCLAIMER_SUBTITLE: 

147 return _( 

148 "You must agree to the following terms and conditions in " 

149 "order to use CamCOPS." 

150 ) 

151 elif w == SS.DISCLAIMER_CONTENT: 

152 return _( 

153 "1. By using the Cambridge Cognitive and Psychiatric Assessment " 

154 "Kit application or web interface (“CamCOPS”), you are agreeing " 

155 "in full to these Terms and Conditions of Use. If you do not " 

156 "agree to these terms, do not use the software.\n" 

157 "\n" 

158 "2. Content that is original to CamCOPS is licensed as follows.\n" 

159 "\n" 

160 "CamCOPS is free software: you can redistribute it and/or modify " 

161 "it under the terms of the GNU General Public License as " 

162 "published by the Free Software Foundation, either version 3 of " 

163 "the License, or (at your option) any later version.\n" 

164 "\n" 

165 "CamCOPS is distributed in the hope that it will be useful, but " 

166 "WITHOUT ANY WARRANTY; without even the implied warranty of " 

167 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " 

168 "GNU General Public License for more details.\n" 

169 "\n" 

170 "You should have received a copy of the GNU General Public " 

171 "License along with CamCOPS. If not, see " 

172 "https://www.gnu.org/licenses/.\n" 

173 "\n" 

174 "3. Content created by others and distributed with CamCOPS may be " 

175 "in the public domain, or distributed under other licenses or " 

176 "permissions. THERE MAY BE CRITERIA THAT APPLY TO YOU THAT MEAN " 

177 "YOU ARE NOT PERMITTED TO USE SPECIFIC TASKS. IT IS YOUR " 

178 "RESPONSIBILITY TO CHECK THAT YOU ARE LEGALLY ENTITLED TO USE " 

179 "EACH TASK. You agree that the authors of CamCOPS are not " 

180 "responsible for any consequences that arise from your use of an " 

181 "unauthorized task.\n\n 4. While efforts have been made to ensure " 

182 "that CamCOPS is reliable and accurate, you agree that the " 

183 "authors and distributors of CamCOPS are not responsible for " 

184 "errors, omissions, or defects in the content, nor liable for any " 

185 "direct, indirect, incidental, special and/or consequential " 

186 "damages, in whole or in part, resulting from your use or any " 

187 "user’s use of or reliance upon its content.\n" 

188 "\n" 

189 "5. Content contained in or accessed through CamCOPS should not " 

190 "be relied upon for medical purposes in any way. This software is " 

191 "not designed for use by the general public. If medical advice is " 

192 "required you should seek expert medical assistance. You agree " 

193 "that you will not rely on this software for any medical " 

194 "purpose.\n" 

195 "\n" 

196 "6. Regarding the European Union Council Directive 93/42/EEC of " 

197 "14 June 1993 concerning medical devices (amended by further " 

198 "directives up to and including Directive 2007/47/EC of 5 " 

199 "September 2007) (“Medical Devices Directive”): CamCOPS is not " 

200 "intended for the diagnosis and/or monitoring of human disease. " 

201 "If it is used for such purposes, it must be used EXCLUSIVELY FOR " 

202 "CLINICAL INVESTIGATIONS in an appropriate setting by persons " 

203 "professionally qualified to do so. It has NOT undergone a " 

204 "conformity assessment under the Medical Devices Directive, and " 

205 "thus cannot be marketed or put into service as a medical device. " 

206 "You agree that you will not use it as a medical device.\n" 

207 "\n" 

208 "7. THIS SOFTWARE IS DESIGNED FOR USE BY QUALIFIED CLINICIANS " 

209 "ONLY. BY CONTINUING TO USE THIS SOFTWARE YOU ARE CONFIRMING THAT " 

210 "YOU ARE A QUALIFIED CLINICIAN, AND THAT YOU RETAIN " 

211 "RESPONSIBILITY FOR DIAGNOSIS AND MANAGEMENT.\n" 

212 "\n" 

213 "8. The CamCOPS server uses a single secure cookie for session " 

214 "authentication. The cookie is not used for any other purpose. " 

215 "It is deleted when you finish your session (it is a session cookie). " # noqa 

216 "By using a CamCOPS server, you agree to this use of cookies.\n" 

217 "\n" 

218 "These terms and conditions were last revised on 2020-10-12." 

219 ) 

220 # ... should match textconst::TERMS_CONDITIONS in the C++ app. 

221 # 

222 # ENSURE YOU ALSO UPDATE TERMS_CONDITIONS_UPDATE_DATE (above). 

223 # 

224 # [OLD CONSTRAINT: ... but don't include hyperlinks; they break the XML 

225 # reader] 

226 elif w == SS.DISCLAIMER_AGREE: 

227 return _("I agree to these terms and conditions") 

228 

229 elif w == SS.EVENT: 

230 return _("Event") 

231 

232 elif w == SS.FALSE: 

233 return _("False") 

234 elif w == SS.FEMALE: 

235 return _("Female") 

236 

237 elif w == SS.GENERAL: 

238 return _("General") 

239 elif w == SS.GLOBAL_SCORE: 

240 return _("Global score") 

241 

242 elif w == SS.IF_APPLICABLE: 

243 return _("If applicable") 

244 

245 elif w == SS.LOCATION: 

246 return _("Location") 

247 

248 elif w == SS.MALE: 

249 return _("Male") 

250 elif w == SS.MEETS_CRITERIA: 

251 return _("Meets criteria?") 

252 elif w == SS.MILD: 

253 return _("Mild") 

254 elif w == SS.MILD_TO_MODERATE: 

255 return _("Mild to moderate") 

256 elif w == SS.MODERATE: 

257 return _("Moderate") 

258 elif w == SS.MODERATELY_SEVERE: 

259 return _("Moderately severe") 

260 elif w == SS.MODERATE_TO_SEVERE: 

261 return _("Moderate to severe") 

262 

263 elif w == SS.NA: 

264 return _("N/A") 

265 elif w == SS.NO: 

266 return _("No") 

267 elif w == SS.NONE: 

268 return _("None") 

269 elif w == SS.NORMAL: 

270 return _("Normal") 

271 elif w == SS.NOTE: 

272 return _("Note") 

273 

274 elif w == SS.PRESENT: 

275 return _("Present") 

276 

277 elif w == SS.QUESTION: 

278 return _("Question") 

279 

280 elif w == SS.SEVERE: 

281 return _("Severe") 

282 elif w == SS.SEX: 

283 return _("Sex") 

284 

285 elif w == SS.TOTAL_SCORE: 

286 return _("Total score") 

287 elif w == SS.TRUE: 

288 return _("True") 

289 

290 elif w == SS.UNKNOWN: 

291 return _("Unknown") 

292 

293 elif w == SS.VERY_SEVERE: 

294 return _("Very severe") 

295 elif w == SS.VISUAL: 

296 return _("Visual") 

297 elif w == SS.VOLUME_0_TO_1: 

298 return _("Volume (0–1)") 

299 

300 elif w == SS.YES: 

301 return _("Yes") 

302 

303 raise ValueError("Bad value passed to server_string")