Coverage for tasks/cpft_covid_medical.py: 62%
37 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/tasks/cpft_covid_medical.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
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.
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.
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/>.
26===============================================================================
28**CPFT Post-Covid Clinic Medical Questionnaire task.**
30"""
32from typing import Any, Dict, Optional, Tuple, Type
34from sqlalchemy.ext.declarative import DeclarativeMeta
35from sqlalchemy.sql.sqltypes import Integer
37from camcops_server.cc_modules.cc_constants import CssClass
38from camcops_server.cc_modules.cc_html import tr_qa
39from camcops_server.cc_modules.cc_request import CamcopsRequest
40from camcops_server.cc_modules.cc_sqla_coltypes import (
41 CamcopsColumn,
42 ZERO_TO_THREE_CHECKER,
43)
44from camcops_server.cc_modules.cc_task import Task, TaskHasPatientMixin
47class CpftCovidMedicalMetaclass(DeclarativeMeta):
48 # noinspection PyInitNewSignature
49 def __init__(
50 cls: Type["CpftCovidMedical"],
51 name: str,
52 bases: Tuple[Type, ...],
53 classdict: Dict[str, Any],
54 ) -> None:
55 setattr(
56 cls,
57 cls.FN_HOW_AND_WHEN_SYMPTOMS,
58 CamcopsColumn(
59 cls.FN_HOW_AND_WHEN_SYMPTOMS,
60 Integer,
61 permitted_value_checker=ZERO_TO_THREE_CHECKER,
62 comment=(
63 "0 Present before C-19, "
64 "1 Within 6 weeks of catching C-19, "
65 "2 Between 6 weeks and 6 months of catching C-19, "
66 "3 Following immunisation for C-19"
67 ),
68 ),
69 )
71 super().__init__(name, bases, classdict)
74class CpftCovidMedical(
75 TaskHasPatientMixin, Task, metaclass=CpftCovidMedicalMetaclass
76):
77 """
78 Server implementation of the CPFT_Covid_Medical task
79 """
81 __tablename__ = "cpft_covid_medical"
82 shortname = "CPFT_Covid_Medical"
83 provides_trackers = False
85 FN_HOW_AND_WHEN_SYMPTOMS = "how_and_when_symptoms"
87 @staticmethod
88 def longname(req: "CamcopsRequest") -> str:
89 _ = req.gettext
90 return _("CPFT Post-COVID-19 Clinic Medical Questionnaire")
92 def is_complete(self) -> bool:
93 if not self.field_contents_valid():
94 return False
96 if getattr(self, self.FN_HOW_AND_WHEN_SYMPTOMS) is None:
97 return False
99 return True
101 def get_task_html(self, req: CamcopsRequest) -> str:
102 rows = [
103 tr_qa(
104 self.wxstring(req, f"q_{self.FN_HOW_AND_WHEN_SYMPTOMS}"),
105 self.get_how_and_when_symptoms_answer(req),
106 )
107 ]
109 html = f"""
110 <div class="{CssClass.SUMMARY}">
111 <table class="{CssClass.SUMMARY}">
112 {self.get_is_complete_tr(req)}
113 </table>
114 </div>
115 <table class="{CssClass.TASKDETAIL}">
116 <tr>
117 <th width="60%">Question</th>
118 <th width="40%">Answer</th>
119 </tr>
120 {''.join(rows)}
121 </table>
122 """
124 return html
126 def get_how_and_when_symptoms_answer(
127 self, req: CamcopsRequest
128 ) -> Optional[str]:
130 answer = getattr(self, self.FN_HOW_AND_WHEN_SYMPTOMS)
131 if answer is None:
132 return None
134 return self.xstring(
135 req, f"{self.FN_HOW_AND_WHEN_SYMPTOMS}_option{answer}"
136 )