Coverage for tasks/progressnote.py: 71%

34 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 23:14 +0000

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/tasks/progressnote.py 

5 

6=============================================================================== 

7 

8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

10 

11 This file is part of CamCOPS. 

12 

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. 

17 

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. 

22 

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/>. 

25 

26=============================================================================== 

27 

28""" 

29 

30from typing import Dict, List 

31 

32import cardinal_pythonlib.rnc_web as ws 

33from sqlalchemy.sql.schema import Column 

34from sqlalchemy.sql.sqltypes import UnicodeText 

35 

36from camcops_server.cc_modules.cc_constants import CssClass 

37from camcops_server.cc_modules.cc_ctvinfo import CtvInfo 

38from camcops_server.cc_modules.cc_html import answer 

39from camcops_server.cc_modules.cc_request import CamcopsRequest 

40from camcops_server.cc_modules.cc_snomed import ( 

41 SnomedConcept, 

42 SnomedExpression, 

43 SnomedLookup, 

44) 

45from camcops_server.cc_modules.cc_task import ( 

46 Task, 

47 TaskHasClinicianMixin, 

48 TaskHasPatientMixin, 

49) 

50from camcops_server.cc_modules.cc_text import SS 

51 

52 

53# ============================================================================= 

54# ProgressNote 

55# ============================================================================= 

56 

57 

58class ProgressNote(TaskHasPatientMixin, TaskHasClinicianMixin, Task): 

59 """ 

60 Server implementation of the ProgressNote task. 

61 """ 

62 

63 __tablename__ = "progressnote" 

64 shortname = "ProgressNote" 

65 info_filename_stem = "clinical" 

66 

67 location = Column("location", UnicodeText, comment="Location") 

68 note = Column("note", UnicodeText, comment="Clinical note") 

69 

70 @staticmethod 

71 def longname(req: "CamcopsRequest") -> str: 

72 _ = req.gettext 

73 return _("Clinical progress note") 

74 

75 def get_clinical_text(self, req: CamcopsRequest) -> List[CtvInfo]: 

76 return [CtvInfo(content=ws.webify(self.note))] 

77 

78 def is_complete(self) -> bool: 

79 return bool(self.note) 

80 

81 def get_task_html(self, req: CamcopsRequest) -> str: 

82 # Avoid tables - PDF generator crashes if text is too long. 

83 return f""" 

84 <div class="{CssClass.HEADING}"> 

85 {req.sstring(SS.LOCATION)} 

86 </div> 

87 <div> 

88 {answer(ws.webify(self.location), 

89 default_for_blank_strings=True)} 

90 </div> 

91 <div class="{CssClass.HEADING}"> 

92 {req.sstring(SS.NOTE)} 

93 </div> 

94 <div> 

95 {answer(self.note, default_for_blank_strings=True)} 

96 </div> 

97 """ 

98 

99 def get_snomed_codes(self, req: CamcopsRequest) -> List[SnomedExpression]: 

100 refinement = {} # type: Dict[SnomedConcept, str] 

101 if self.note: 

102 refinement[req.snomed(SnomedLookup.CLINICAL_NOTE)] = self.note 

103 codes = [ 

104 SnomedExpression( 

105 req.snomed(SnomedLookup.PROGRESS_NOTE_PROCEDURE), 

106 refinement=refinement or None, 

107 ) 

108 ] 

109 return codes