Coverage for cc_modules/tests/cc_hl7_tests.py: 35%
26 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 13:48 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 13:48 +0000
1"""
2camcops_server/cc_modules/tests/cc_hl7_tests.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
11 CamCOPS is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CamCOPS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
25"""
27import hl7
28from pendulum import Date, DateTime as Pendulum
30from camcops_server.cc_modules.cc_constants import FileType
31from camcops_server.cc_modules.cc_hl7 import (
32 escape_hl7_text,
33 get_mod11_checkdigit,
34 make_msh_segment,
35 make_obr_segment,
36 make_obx_segment,
37 make_pid_segment,
38)
39from camcops_server.cc_modules.cc_simpleobjects import (
40 HL7PatientIdentifier,
41 TaskExportOptions,
42)
43from camcops_server.cc_modules.cc_unittest import DemoDatabaseTestCase
44from camcops_server.tasks.phq9 import Phq9
47# =============================================================================
48# Unit tests
49# =============================================================================
52class HL7CoreTests(DemoDatabaseTestCase):
53 """
54 Unit tests.
55 """
57 def test_hl7core_func(self) -> None:
58 self.announce("test_hl7core_func")
60 pitlist = [
61 HL7PatientIdentifier(
62 pid="1", id_type="TT", assigning_authority="AA"
63 )
64 ]
65 # noinspection PyTypeChecker
66 dob = Date.today() # type: Date
67 now = Pendulum.now()
68 task = self.dbsession.query(Phq9).first()
69 assert task, "Missing Phq9 in demo database!"
71 self.assertIsInstance(get_mod11_checkdigit("12345"), str)
72 self.assertIsInstance(get_mod11_checkdigit("badnumber"), str)
73 self.assertIsInstance(get_mod11_checkdigit("None"), str)
74 self.assertIsInstance(make_msh_segment(now, "control_id"), hl7.Segment)
75 self.assertIsInstance(
76 make_pid_segment(
77 forename="fname",
78 surname="sname",
79 dob=dob,
80 sex="M",
81 address="Somewhere",
82 patient_id_list=pitlist,
83 ),
84 hl7.Segment,
85 )
86 self.assertIsInstance(make_obr_segment(task), hl7.Segment)
87 for task_format in (FileType.PDF, FileType.HTML, FileType.XML):
88 for comments in (True, False):
89 export_options = TaskExportOptions(
90 xml_include_comments=comments,
91 xml_with_header_comments=comments,
92 )
93 self.assertIsInstance(
94 make_obx_segment(
95 req=self.req,
96 task=task,
97 task_format=task_format,
98 observation_identifier="obs_id",
99 observation_datetime=now,
100 responsible_observer="responsible_observer",
101 export_options=export_options,
102 ),
103 hl7.Segment,
104 )
105 self.assertIsInstance(escape_hl7_text("blahblah"), str)