Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion hl7apy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parse_message(message, validation_level=None, find_groups=True, message_prof
:param find_groups: if ``True``, automatically assign the segments found to the appropriate
:class:`Groups <hl7apy.core.Group>` instances. If ``False``, the segments found are assigned as
children of the :class:`Message <hl7apy.core.Message>` instance

:type force_validation: ``bool``
:type force_validation: if ``True``, automatically forces the message validation after the end of the parsing

Expand Down Expand Up @@ -152,6 +152,8 @@ def parse_segments(text, version=None, encoding_chars=None, validation_level=Non
segment = parse_segment(s.strip(), version, encoding_chars, validation_level)
segments.append(segment)
else:
current_parent = __go_to_previous_level_if_new_order_ORC_inside_an_OBSERVATION_REQUEST(
current_parent, parents_refs, s, segment_name)
ref, parents_refs = _get_segment_reference(segment_name, parents_refs)
if ref is None:
# group not found at the current level, go back to the previous level
Expand Down Expand Up @@ -195,6 +197,16 @@ def parse_segments(text, version=None, encoding_chars=None, validation_level=Non
return segments


def __go_to_previous_level_if_new_order_ORC_inside_an_OBSERVATION_REQUEST(current_parent, parents_refs, segment,
segment_name):
orc_1 = segment[4:6]
last_parent_reference = parents_refs[-1][0]
if segment_name == "ORC" and orc_1 == "NW" and '_OBSERVATION_REQUEST' in last_parent_reference:
parents_refs.pop()
current_parent = current_parent.parent
return current_parent


def parse_segment(text, version=None, encoding_chars=None, validation_level=None, reference=None):
"""
Parse the given ER7-encoded segment and return an instance of :class:`Segment <hl7apy.core.Segment>`.
Expand Down
18 changes: 3 additions & 15 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ def test_well_structured_message(self):
msg = self._create_message(msg_str)
self.assertTrue(msg.validate())

# def test_oml_o33_2_message(self):
# # This test is failing because the oml_o33_2 parsing creates a
# # OML_O33_ORDER_PRIOR which expect a OBR segment, but the parser's
# # implementation puts the OBR segment in the group OML_O33_OBSERVATION_REQUEST
# # This behaviour HL7 fault
# msg = self._create_message(self.oml_o33_2)
# self.assertTrue(msg.validate())
def test_oml_o33_2_message(self):
msg = self._create_message(self.oml_o33_2)
self.assertTrue(msg.validate())

def test_unknown_message(self):
msg = self._create_message(self.adt_a01)
Expand Down Expand Up @@ -424,14 +420,6 @@ def test_well_structured_message(self):
m = self._create_message(self.rsp_k21)
self.assertTrue(m.validate())

# def test_oml_o33_2_message(self):
# # This test is failing because the oml_o33_2 parsing creates a
# # OML_O33_ORDER_PRIOR which expect a OBR segment, but the parser's
# # implementation puts the OBR segment in the group OML_O33_OBSERVATION_REQUEST
# # This behaviour HL7 fault
# msg = self._create_message(self.oml_o33_2)
# self.assertTrue(msg.validate())

# def test_missing_required_group(self):
# """
# Test that if a required group is not present the messase in not validated
Expand Down