diff --git a/hl7apy/parser.py b/hl7apy/parser.py index bb4b0d4..9615639 100644 --- a/hl7apy/parser.py +++ b/hl7apy/parser.py @@ -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 ` instances. If ``False``, the segments found are assigned as children of the :class:`Message ` instance - + :type force_validation: ``bool`` :type force_validation: if ``True``, automatically forces the message validation after the end of the parsing @@ -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 @@ -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 `. diff --git a/tests/test_validation.py b/tests/test_validation.py index a1bab52..51e32eb 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -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) @@ -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