Coverage for tasks/progressnote.py : 70%

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/progressnote.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 Dict, List
31import cardinal_pythonlib.rnc_web as ws
32from sqlalchemy.sql.schema import Column
33from sqlalchemy.sql.sqltypes import UnicodeText
35from camcops_server.cc_modules.cc_constants import CssClass
36from camcops_server.cc_modules.cc_ctvinfo import CtvInfo
37from camcops_server.cc_modules.cc_html import answer
38from camcops_server.cc_modules.cc_request import CamcopsRequest
39from camcops_server.cc_modules.cc_snomed import (
40 SnomedConcept,
41 SnomedExpression,
42 SnomedLookup,
43)
44from camcops_server.cc_modules.cc_task import (
45 Task,
46 TaskHasClinicianMixin,
47 TaskHasPatientMixin,
48)
49from camcops_server.cc_modules.cc_text import SS
52# =============================================================================
53# ProgressNote
54# =============================================================================
56class ProgressNote(TaskHasPatientMixin, TaskHasClinicianMixin, Task):
57 """
58 Server implementation of the ProgressNote task.
59 """
60 __tablename__ = "progressnote"
61 shortname = "ProgressNote"
63 location = Column("location", UnicodeText, comment="Location")
64 note = Column("note", UnicodeText, comment="Clinical note")
66 @staticmethod
67 def longname(req: "CamcopsRequest") -> str:
68 _ = req.gettext
69 return _("Clinical progress note")
71 def get_clinical_text(self, req: CamcopsRequest) -> List[CtvInfo]:
72 return [CtvInfo(content=ws.webify(self.note))]
74 def is_complete(self) -> bool:
75 return bool(self.note)
77 def get_task_html(self, req: CamcopsRequest) -> str:
78 # Avoid tables - PDF generator crashes if text is too long.
79 return f"""
80 <div class="{CssClass.HEADING}">
81 {req.sstring(SS.LOCATION)}
82 </div>
83 <div>
84 {answer(ws.webify(self.location),
85 default_for_blank_strings=True)}
86 </div>
87 <div class="{CssClass.HEADING}">
88 {req.sstring(SS.NOTE)}
89 </div>
90 <div>
91 {answer(self.note, default_for_blank_strings=True)}
92 </div>
93 """
95 def get_snomed_codes(self, req: CamcopsRequest) -> List[SnomedExpression]:
96 refinement = {} # type: Dict[SnomedConcept, str]
97 if self.note:
98 refinement[req.snomed(SnomedLookup.CLINICAL_NOTE)] = self.note
99 codes = [SnomedExpression(
100 req.snomed(SnomedLookup.PROGRESS_NOTE_PROCEDURE),
101 refinement=refinement or None
102 )]
103 return codes