Coverage for tasks/gaf.py : 64%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3"""
4camcops_server/tasks/gaf.py
6===============================================================================
8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).
10 This file is part of CamCOPS.
12 CamCOPS is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 CamCOPS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
25===============================================================================
27"""
29from typing import List, Optional
31from sqlalchemy.sql.sqltypes import Integer
33from camcops_server.cc_modules.cc_constants import (
34 CssClass,
35 DATA_COLLECTION_ONLY_DIV,
36)
37from camcops_server.cc_modules.cc_ctvinfo import CTV_INCOMPLETE, CtvInfo
38from camcops_server.cc_modules.cc_html import answer, tr
39from camcops_server.cc_modules.cc_request import CamcopsRequest
40from camcops_server.cc_modules.cc_snomed import SnomedExpression, SnomedLookup
41from camcops_server.cc_modules.cc_sqla_coltypes import (
42 CamcopsColumn,
43 PermittedValueChecker,
44)
45from camcops_server.cc_modules.cc_string import AS
46from camcops_server.cc_modules.cc_summaryelement import SummaryElement
47from camcops_server.cc_modules.cc_task import (
48 Task,
49 TaskHasPatientMixin,
50 TaskHasClinicianMixin,
51)
52from camcops_server.cc_modules.cc_trackerhelpers import TrackerInfo
55# =============================================================================
56# GAF (crippled)
57# =============================================================================
59class Gaf(TaskHasClinicianMixin, TaskHasPatientMixin, Task):
60 """
61 Server implementation of the GAF task.
62 """
63 __tablename__ = "gaf"
64 shortname = "GAF"
65 provides_trackers = True
67 score = CamcopsColumn(
68 "score", Integer,
69 permitted_value_checker=PermittedValueChecker(minimum=0, maximum=100),
70 comment="GAF score (1-100 or 0 for insufficient information)"
71 )
73 @staticmethod
74 def longname(req: "CamcopsRequest") -> str:
75 _ = req.gettext
76 return _("Global Assessment of Functioning (data collection only)")
78 def is_complete(self) -> bool:
79 return (
80 self.score is not None and
81 self.score != 0 and
82 self.field_contents_valid()
83 )
85 def get_trackers(self, req: CamcopsRequest) -> List[TrackerInfo]:
86 return [TrackerInfo(
87 value=self.total_score(),
88 plot_label="GAF score (rating overall functioning)",
89 axis_label="Score (1-100)",
90 axis_min=0.5,
91 axis_max=100.5
92 )]
94 def get_clinical_text(self, req: CamcopsRequest) -> List[CtvInfo]:
95 if not self.is_complete():
96 return CTV_INCOMPLETE
97 return [CtvInfo(content=f"GAF score {self.total_score()}")]
99 def get_summaries(self, req: CamcopsRequest) -> List[SummaryElement]:
100 return self.standard_task_summary_fields()
102 def total_score(self) -> Optional[int]:
103 if self.score == 0:
104 return None
105 return self.score
107 def get_task_html(self, req: CamcopsRequest) -> str:
108 return f"""
109 <div class="{CssClass.SUMMARY}">
110 <table class="{CssClass.SUMMARY}">
111 {self.get_is_complete_tr(req)}
112 {tr(req.wappstring(AS.GAF_SCORE), answer(self.score))}
113 </table>
114 </div>
115 {DATA_COLLECTION_ONLY_DIV}
116 """
118 def get_snomed_codes(self, req: CamcopsRequest) -> List[SnomedExpression]:
119 if not self.is_complete():
120 return []
121 return [SnomedExpression(req.snomed(SnomedLookup.GAF_SCALE))]