From 7197b578b1d9e81b3c178ca1462d20fb36320780 Mon Sep 17 00:00:00 2001 From: Denys Melnyk Date: Sat, 27 Dec 2025 20:57:44 +0100 Subject: [PATCH] fix(core): update content type to 'sequence' when Field changes to complex datatype. Fixes #144 --- hl7apy/core.py | 1 + tests/test_core.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/hl7apy/core.py b/hl7apy/core.py index 960d11b..c7bd7b8 100644 --- a/hl7apy/core.py +++ b/hl7apy/core.py @@ -919,6 +919,7 @@ def _set_datatype(self, datatype): datatype not in ('varies', None, self.datatype) and self.datatype is not None: reference = load_reference(datatype, 'Datatypes_Structs', self.version) new_ref = [ref_item for ref_item in self.reference] + new_ref[0] = 'sequence' new_ref[1] = reference new_ref[2] = datatype structure = ElementFinder.get_structure(self, new_ref) diff --git a/tests/test_core.py b/tests/test_core.py index 469e2eb..58678e7 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1305,6 +1305,16 @@ def test_field_wgith_three_part_name_bug_39(self): self.assertEqual(f.cm_msg_1.value, 'SIU') self.assertEqual(f.cm_msg_2.value, 'S12') + def test_field_datatype_to_complex_serialization(self): + f = Field('OBX_5') + f.datatype = 'ED' + f.ed_1 = '' + f.ed_2 = 'IM' + f.ed_3 = 'JPEG' + f.ed_4 = 'Base64' + f.ed_5 = 'SomeData' + self.assertEqual(f.to_er7(), '^IM^JPEG^Base64^SomeData') + class TestComponent(unittest.TestCase):