Coverage for cc_modules/tests/cc_hl7_tests.py : 37%

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/cc_modules/tests/cc_hl7_tests.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===============================================================================
26"""
29import hl7
30from pendulum import Date, DateTime as Pendulum
32from camcops_server.cc_modules.cc_constants import FileType
33from camcops_server.cc_modules.cc_hl7 import (
34 escape_hl7_text,
35 get_mod11_checkdigit,
36 make_msh_segment,
37 make_obr_segment,
38 make_obx_segment,
39 make_pid_segment,
40)
41from camcops_server.cc_modules.cc_simpleobjects import (
42 HL7PatientIdentifier,
43 TaskExportOptions,
44)
45from camcops_server.cc_modules.cc_unittest import DemoDatabaseTestCase
46from camcops_server.tasks.phq9 import Phq9
49# =============================================================================
50# Unit tests
51# =============================================================================
53class HL7CoreTests(DemoDatabaseTestCase):
54 """
55 Unit tests.
56 """
57 def test_hl7core_func(self) -> None:
58 self.announce("test_hl7core_func")
60 pitlist = [
61 HL7PatientIdentifier(pid="1", id_type="TT",
62 assigning_authority="AA")
63 ]
64 # noinspection PyTypeChecker
65 dob = Date.today() # type: Date
66 now = Pendulum.now()
67 task = self.dbsession.query(Phq9).first()
68 assert task, "Missing Phq9 in demo database!"
70 self.assertIsInstance(get_mod11_checkdigit("12345"), str)
71 self.assertIsInstance(get_mod11_checkdigit("badnumber"), str)
72 self.assertIsInstance(get_mod11_checkdigit("None"), str)
73 self.assertIsInstance(make_msh_segment(now, "control_id"), hl7.Segment)
74 self.assertIsInstance(make_pid_segment(
75 forename="fname",
76 surname="sname",
77 dob=dob,
78 sex="M",
79 address="Somewhere",
80 patient_id_list=pitlist
81 ), hl7.Segment)
82 self.assertIsInstance(make_obr_segment(task), hl7.Segment)
83 for task_format in [FileType.PDF, FileType.HTML, FileType.XML]:
84 for comments in [True, False]:
85 export_options = TaskExportOptions(
86 xml_include_comments=comments,
87 xml_with_header_comments=comments,
88 )
89 self.assertIsInstance(make_obx_segment(
90 req=self.req,
91 task=task,
92 task_format=task_format,
93 observation_identifier="obs_id",
94 observation_datetime=now,
95 responsible_observer="responsible_observer",
96 export_options=export_options,
97 ), hl7.Segment)
98 self.assertIsInstance(escape_hl7_text("blahblah"), str)