Skip to content

PipeParser treats choice/conditional segments in groups as invalid segments #794

@rlannon

Description

@rlannon

Describe the bug
PipeParser.Parse() does not properly parse conditional segments in groups, such as in the ORDER_DETAIL group in ORM_O01 messages. Instead, the parser erroneously treats these as invalid segments.

Attempt to parse the attached HL7 message using a PipeParser with the option:

UnexpectedSegmentBehaviour = UnexpectedSegmentBehaviour.ThrowHl7Exception

The call to Parse() will throw an exception, despite the HL7 message being valid. The exception message states that RXO is not a valid segment when attempting to parse the ORDER_DETAIL group. RXO should be parsed correctly because it is a valid conditional element within the ORDER_DETAIL group. The message appears to be parsed correctly when using LegacyPipeParser. Without the parser option set, the message will parse, but the RXO structure will not be populated with the data from the message.

The error appears to stem from the fact that all of the models mark conditional fields as required, but IsChoiceElement is always set to false for these items. See AbstractGroup.cs(429). There appears to be no way to ascertain this information in the parser without changes to the generated models.

Here is an example HL7 message

MSH|^~\\&|HIS|MedCenter|LIS|MedCenter|20060307110114||ORM^O01|MSGID20060307110114|P|2.3.1
PID|||12001||Jones^John^^^Mr.||19670824|M|||123 West St.^^Denver^CO^80020^USA|||||||
PV1||O|OP^PAREG^||||2342^Jones^Bob|||OP|||||||||2|||||||||||||||||||||||||20060307110111|
ORC|NW|1016314
RXO|65862000330^MIRTAZAPINE^NDC^^REMERON^|1||30MG|TAB||1 TAB By Mouth QHS(2000)||G||60|Doses|0|123456^Jones, NP^Joan

Environment details:

  • OS: Windows 11
  • Target Framework: .NET 8
  • Version: 3.2.4
  • HL7 Version: tested using versions 2.3, 2.3.1, 2.5, 2.5.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions