Coverage for tasks/gaf.py: 64%
42 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/gaf.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"""
30from typing import List, Optional
32from sqlalchemy.sql.sqltypes import Integer
34from camcops_server.cc_modules.cc_constants import (
35 CssClass,
36 DATA_COLLECTION_ONLY_DIV,
37)
38from camcops_server.cc_modules.cc_ctvinfo import CTV_INCOMPLETE, CtvInfo
39from camcops_server.cc_modules.cc_html import answer, tr
40from camcops_server.cc_modules.cc_request import CamcopsRequest
41from camcops_server.cc_modules.cc_snomed import SnomedExpression, SnomedLookup
42from camcops_server.cc_modules.cc_sqla_coltypes import (
43 CamcopsColumn,
44 PermittedValueChecker,
45)
46from camcops_server.cc_modules.cc_string import AS
47from camcops_server.cc_modules.cc_summaryelement import SummaryElement
48from camcops_server.cc_modules.cc_task import (
49 Task,
50 TaskHasPatientMixin,
51 TaskHasClinicianMixin,
52)
53from camcops_server.cc_modules.cc_trackerhelpers import TrackerInfo
56# =============================================================================
57# GAF (crippled)
58# =============================================================================
61class Gaf(TaskHasClinicianMixin, TaskHasPatientMixin, Task):
62 """
63 Server implementation of the GAF task.
64 """
66 __tablename__ = "gaf"
67 shortname = "GAF"
68 provides_trackers = True
70 score = CamcopsColumn(
71 "score",
72 Integer,
73 permitted_value_checker=PermittedValueChecker(minimum=0, maximum=100),
74 comment="GAF score (1-100 or 0 for insufficient information)",
75 )
77 @staticmethod
78 def longname(req: "CamcopsRequest") -> str:
79 _ = req.gettext
80 return _("Global Assessment of Functioning (data collection only)")
82 def is_complete(self) -> bool:
83 return (
84 self.score is not None
85 and self.score != 0
86 and self.field_contents_valid()
87 )
89 def get_trackers(self, req: CamcopsRequest) -> List[TrackerInfo]:
90 return [
91 TrackerInfo(
92 value=self.total_score(),
93 plot_label="GAF score (rating overall functioning)",
94 axis_label="Score (1-100)",
95 axis_min=0.5,
96 axis_max=100.5,
97 )
98 ]
100 def get_clinical_text(self, req: CamcopsRequest) -> List[CtvInfo]:
101 if not self.is_complete():
102 return CTV_INCOMPLETE
103 return [CtvInfo(content=f"GAF score {self.total_score()}")]
105 def get_summaries(self, req: CamcopsRequest) -> List[SummaryElement]:
106 return self.standard_task_summary_fields()
108 def total_score(self) -> Optional[int]:
109 if self.score == 0:
110 return None
111 return self.score
113 def get_task_html(self, req: CamcopsRequest) -> str:
114 return f"""
115 <div class="{CssClass.SUMMARY}">
116 <table class="{CssClass.SUMMARY}">
117 {self.get_is_complete_tr(req)}
118 {tr(req.wappstring(AS.GAF_SCORE), answer(self.score))}
119 </table>
120 </div>
121 {DATA_COLLECTION_ONLY_DIV}
122 """
124 def get_snomed_codes(self, req: CamcopsRequest) -> List[SnomedExpression]:
125 if not self.is_complete():
126 return []
127 return [SnomedExpression(req.snomed(SnomedLookup.GAF_SCALE))]