Coverage for tasks/contactlog.py : 77%

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/contactlog.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
31from cardinal_pythonlib.datetimefunc import format_datetime, get_duration_h_m
32import cardinal_pythonlib.rnc_web as ws
33from sqlalchemy.sql.schema import Column
34from sqlalchemy.sql.sqltypes import Integer, UnicodeText
36from camcops_server.cc_modules.cc_constants import CssClass, DateFormat
37from camcops_server.cc_modules.cc_ctvinfo import CTV_INCOMPLETE, CtvInfo
38from camcops_server.cc_modules.cc_html import (
39 italic,
40 get_yes_no_none,
41 tr,
42 tr_qa,
43)
44from camcops_server.cc_modules.cc_request import CamcopsRequest
45from camcops_server.cc_modules.cc_sqla_coltypes import (
46 CamcopsColumn,
47 BIT_CHECKER,
48 PendulumDateTimeAsIsoTextColType,
49)
50from camcops_server.cc_modules.cc_task import (
51 Task,
52 TaskHasClinicianMixin,
53 TaskHasPatientMixin,
54)
57# =============================================================================
58# ContactLog
59# =============================================================================
61class ContactLog(TaskHasClinicianMixin, TaskHasPatientMixin, Task):
62 """
63 Server implementation of the ContactLog task.
64 """
65 __tablename__ = "contactlog"
66 shortname = "ContactLog"
68 location = Column(
69 "location", UnicodeText,
70 comment="Location"
71 )
72 start = Column(
73 "start", PendulumDateTimeAsIsoTextColType,
74 comment="Date/time that contact started"
75 )
76 end = Column(
77 "end", PendulumDateTimeAsIsoTextColType,
78 comment="Date/time that contact ended"
79 )
80 patient_contact = CamcopsColumn(
81 "patient_contact", Integer,
82 permitted_value_checker=BIT_CHECKER,
83 comment="Patient contact involved (0 no, 1 yes)?"
84 )
85 staff_liaison = CamcopsColumn(
86 "staff_liaison", Integer,
87 permitted_value_checker=BIT_CHECKER,
88 comment="Liaison with staff involved (0 no, 1 yes)?"
89 )
90 other_liaison = CamcopsColumn(
91 "other_liaison", Integer,
92 permitted_value_checker=BIT_CHECKER,
93 comment="Liaison with others (e.g. family) involved (0 no, 1 yes)?"
94 )
95 comment = Column(
96 "comment", UnicodeText,
97 comment="Comment"
98 )
100 @staticmethod
101 def longname(req: "CamcopsRequest") -> str:
102 _ = req.gettext
103 return _("Clinical contact log")
105 def get_clinical_text(self, req: CamcopsRequest) -> List[CtvInfo]:
106 if not self.is_complete():
107 return CTV_INCOMPLETE
108 contact_type = "Patient" if self.patient_contact else "Non-patient"
109 return [CtvInfo(content=(
110 f"{contact_type} contact. Duration (hours:minutes) "
111 f"{get_duration_h_m(self.start, self.end)}."
112 ))]
114 def is_complete(self) -> bool:
115 return (
116 self.start is not None and
117 self.end is not None and
118 self.field_contents_valid()
119 )
121 def get_task_html(self, req: CamcopsRequest) -> str:
122 return f"""
123 <table class="{CssClass.TASKDETAIL}">
124 <tr>
125 <td width="33%">Location:</td>
126 <td width="67%"><b>{ws.webify(self.location)}</b></td>
127 </tr>
128 {tr_qa("Start:", format_datetime(self.start,
129 DateFormat.SHORT_DATETIME,
130 None))}
131 {tr_qa("End:", format_datetime(self.end,
132 DateFormat.SHORT_DATETIME,
133 None))}
134 {tr(italic("Calculated duration (hours:minutes)"),
135 italic(get_duration_h_m(self.start, self.end)))}
136 {tr_qa("Patient contact?",
137 get_yes_no_none(req, self.patient_contact))}
138 {tr_qa("Staff liaison?",
139 get_yes_no_none(req, self.staff_liaison))}
140 {tr_qa("Other liaison?",
141 get_yes_no_none(req, self.other_liaison))}
142 {tr_qa("Comment:", self.comment)}
143 </table>
144 """