Coverage for tasks/cpft_covid_medical.py: 59%

34 statements  

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

1""" 

2camcops_server/tasks/cpft_covid_medical.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**CPFT Post-Covid Clinic Medical Questionnaire task.** 

27 

28""" 

29 

30from typing import Any, Optional, Type 

31 

32from sqlalchemy.sql.sqltypes import Integer 

33 

34from camcops_server.cc_modules.cc_constants import CssClass 

35from camcops_server.cc_modules.cc_html import tr_qa 

36from camcops_server.cc_modules.cc_request import CamcopsRequest 

37from camcops_server.cc_modules.cc_sqla_coltypes import ( 

38 camcops_column, 

39 ZERO_TO_THREE_CHECKER, 

40) 

41from camcops_server.cc_modules.cc_task import Task, TaskHasPatientMixin 

42 

43 

44class CpftCovidMedical( # type: ignore[misc] 

45 TaskHasPatientMixin, 

46 Task, 

47): 

48 """ 

49 Server implementation of the CPFT_Covid_Medical task 

50 """ 

51 

52 __tablename__ = "cpft_covid_medical" 

53 shortname = "CPFT_Covid_Medical" 

54 provides_trackers = False 

55 

56 FN_HOW_AND_WHEN_SYMPTOMS = "how_and_when_symptoms" 

57 

58 @classmethod 

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

60 setattr( 

61 cls, 

62 cls.FN_HOW_AND_WHEN_SYMPTOMS, 

63 camcops_column( 

64 cls.FN_HOW_AND_WHEN_SYMPTOMS, 

65 Integer, 

66 permitted_value_checker=ZERO_TO_THREE_CHECKER, 

67 comment=( 

68 "0 Present before C-19, " 

69 "1 Within 6 weeks of catching C-19, " 

70 "2 Between 6 weeks and 6 months of catching C-19, " 

71 "3 Following immunisation for C-19" 

72 ), 

73 ), 

74 ) 

75 

76 @staticmethod 

77 def longname(req: "CamcopsRequest") -> str: 

78 _ = req.gettext 

79 return _("CPFT Post-COVID-19 Clinic Medical Questionnaire") 

80 

81 def is_complete(self) -> bool: 

82 if not self.field_contents_valid(): 

83 return False 

84 

85 if getattr(self, self.FN_HOW_AND_WHEN_SYMPTOMS) is None: 

86 return False 

87 

88 return True 

89 

90 def get_task_html(self, req: CamcopsRequest) -> str: 

91 rows = [ 

92 tr_qa( 

93 self.wxstring(req, f"q_{self.FN_HOW_AND_WHEN_SYMPTOMS}"), 

94 self.get_how_and_when_symptoms_answer(req), 

95 ) 

96 ] 

97 

98 html = f""" 

99 <div class="{CssClass.SUMMARY}"> 

100 <table class="{CssClass.SUMMARY}"> 

101 {self.get_is_complete_tr(req)} 

102 </table> 

103 </div> 

104 <table class="{CssClass.TASKDETAIL}"> 

105 <tr> 

106 <th width="60%">Question</th> 

107 <th width="40%">Answer</th> 

108 </tr> 

109 {''.join(rows)} 

110 </table> 

111 """ 

112 

113 return html 

114 

115 def get_how_and_when_symptoms_answer( 

116 self, req: CamcopsRequest 

117 ) -> Optional[str]: 

118 

119 answer = getattr(self, self.FN_HOW_AND_WHEN_SYMPTOMS) 

120 if answer is None: 

121 return None 

122 

123 return self.xstring( 

124 req, f"{self.FN_HOW_AND_WHEN_SYMPTOMS}_option{answer}" 

125 )