Coverage for cc_modules/cc_text.py: 37%

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

29 

30""" 

31 

32from enum import auto, Enum, unique 

33from typing import TYPE_CHECKING 

34 

35from pendulum import Date 

36 

37if TYPE_CHECKING: 

38 from camcops_server.cc_modules.cc_request import CamcopsRequest 

39 

40 

41TERMS_CONDITIONS_UPDATE_DATE = Date(2020, 6, 29) 

42 

43 

44@unique 

45class SS(Enum): 

46 """ 

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

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

49 """ 

50 

51 ABNORMAL = auto() 

52 ABSENT = auto() 

53 ABSENT_OR_MILD = auto() 

54 ANONYMOUS_TASK = auto() 

55 ANSWER = auto() 

56 AUDITORY = auto() 

57 

58 CATEGORY = auto() 

59 

60 DISCLAIMER_TITLE = auto() 

61 DISCLAIMER_SUBTITLE = auto() 

62 DISCLAIMER_CONTENT = auto() 

63 DISCLAIMER_AGREE = auto() 

64 

65 EVENT = auto() 

66 

67 FALSE = auto() 

68 FEMALE = auto() 

69 

70 GENERAL = auto() 

71 

72 IF_APPLICABLE = auto() 

73 

74 LOCATION = auto() 

75 

76 MALE = auto() 

77 MEETS_CRITERIA = auto() 

78 MILD = auto() 

79 MILD_TO_MODERATE = auto() 

80 MODERATE = auto() 

81 MODERATELY_SEVERE = auto() 

82 MODERATE_TO_SEVERE = auto() 

83 

84 NA = auto() 

85 NO = auto() 

86 NONE = auto() 

87 NORMAL = auto() 

88 NOTE = auto() 

89 

90 PRESENT = auto() 

91 

92 QUESTION = auto() 

93 

94 SEVERE = auto() 

95 SEX = auto() 

96 

97 TOTAL_SCORE = auto() 

98 TRUE = auto() 

99 

100 UNKNOWN = auto() 

101 

102 VERY_SEVERE = auto() 

103 VISUAL = auto() 

104 VOLUME_0_TO_1 = auto() 

105 

106 YES = auto() 

107 

108 

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

110 """ 

111 Returns a translated server string. 

112 

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

114 the server (but not by the client). 

115 

116 Args: 

117 req: 

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

119 w: 

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

121 enumeration value 

122 

123 Returns: 

124 the translated string 

125 

126 """ 

127 _ = req.gettext 

128 

129 if w == SS.ABNORMAL: 

130 return _("Abnormal") 

131 elif w == SS.ABSENT: 

132 return _("Absent") 

133 elif w == SS.ABSENT_OR_MILD: 

134 return _("Absent or mild") 

135 elif w == SS.ANONYMOUS_TASK: 

136 return _("Anonymous task") 

137 elif w == SS.ANSWER: 

138 return _("Answer") 

139 elif w == SS.AUDITORY: 

140 return _("Auditory") 

141 

142 elif w == SS.CATEGORY: 

143 return _("Category") 

144 

145 elif w == SS.DISCLAIMER_TITLE: 

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

147 elif w == SS.DISCLAIMER_SUBTITLE: 

148 return _( 

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

150 "order to use CamCOPS." 

151 ) 

152 elif w == SS.DISCLAIMER_CONTENT: 

153 return _( 

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

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

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

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

158 "\n" 

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

160 "\n" 

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

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

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

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

165 "\n" 

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

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

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

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

170 "\n" 

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

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

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

174 "\n" 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

189 "\n" 

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

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

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

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

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

195 "purpose.\n" 

196 "\n" 

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

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

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

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

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

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

203 "CLINICAL INVESTIGATIONS in an appropriate setting by persons " 

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

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

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

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

208 "\n" 

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

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

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

212 "RESPONSIBILITY FOR DIAGNOSIS AND MANAGEMENT.\n" 

213 "\n" 

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

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

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

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

218 "\n" 

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

220 ) 

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

222 # 

223 # ENSURE YOU ALSO UPDATE TERMS_CONDITIONS_UPDATE_DATE (above). 

224 # 

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

226 # reader] 

227 elif w == SS.DISCLAIMER_AGREE: 

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

229 

230 elif w == SS.EVENT: 

231 return _("Event") 

232 

233 elif w == SS.FALSE: 

234 return _("False") 

235 elif w == SS.FEMALE: 

236 return _("Female") 

237 

238 elif w == SS.GENERAL: 

239 return _("General") 

240 

241 elif w == SS.IF_APPLICABLE: 

242 return _("If applicable") 

243 

244 elif w == SS.LOCATION: 

245 return _("Location") 

246 

247 elif w == SS.MALE: 

248 return _("Male") 

249 elif w == SS.MEETS_CRITERIA: 

250 return _("Meets criteria?") 

251 elif w == SS.MILD: 

252 return _("Mild") 

253 elif w == SS.MILD_TO_MODERATE: 

254 return _("Mild to moderate") 

255 elif w == SS.MODERATE: 

256 return _("Moderate") 

257 elif w == SS.MODERATELY_SEVERE: 

258 return _("Moderately severe") 

259 elif w == SS.MODERATE_TO_SEVERE: 

260 return _("Moderate to severe") 

261 

262 elif w == SS.NA: 

263 return _("N/A") 

264 elif w == SS.NO: 

265 return _("No") 

266 elif w == SS.NONE: 

267 return _("None") 

268 elif w == SS.NORMAL: 

269 return _("Normal") 

270 elif w == SS.NOTE: 

271 return _("Note") 

272 

273 elif w == SS.PRESENT: 

274 return _("Present") 

275 

276 elif w == SS.QUESTION: 

277 return _("Question") 

278 

279 elif w == SS.SEVERE: 

280 return _("Severe") 

281 elif w == SS.SEX: 

282 return _("Sex") 

283 

284 elif w == SS.TOTAL_SCORE: 

285 return _("Total score") 

286 elif w == SS.TRUE: 

287 return _("True") 

288 

289 elif w == SS.UNKNOWN: 

290 return _("Unknown") 

291 

292 elif w == SS.VERY_SEVERE: 

293 return _("Very severe") 

294 elif w == SS.VISUAL: 

295 return _("Visual") 

296 elif w == SS.VOLUME_0_TO_1: 

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

298 

299 elif w == SS.YES: 

300 return _("Yes") 

301 

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