#20 Terser getSegment() throws exception if segment not found

open
nobody
None
5
2010-11-12
2010-11-12
Steve Short
No

I'm trying to process a message that may (or may not) contain a non-standard ROL segment. I'm calling the Terser getSegment() method:

ISegment segment = messageTerser.getSegment("/.ROL");

This works fine when the non-standard ROL segment is present but fails with an HL7Exception and the message "End of message reached while iterating without loop" in MessageNavigator.iterate() if the segment is not present in the message.

Is this behaviour by design ?

If so, is there any way that I can programatically check whether the non-standard segment exists in the message before calling getSegment ? I've looked at methods such as Message.GetAll() and Terser.Finder.nextChild() but these only return the defined segments and don't include the non-standard segments. I can't find a way of determining whether the non-standard segment is present in the message or not.

Any help gratefully received...

Discussion

  • ChadC
    ChadC
    2010-11-12

    Are you using the standard HL7 models, or do you have your own? Usually, you shouldn't have to worry about getting into the guts of the parser, you can just parse your message and load up the model class.

     
  • Steve Short
    Steve Short
    2010-11-12

    I'm using the standard HL7 models. I know that I could create a custom HL7 message to represent this non-standard message but, in the past, I've taken the quick and easy option and just called Terser getSegment() to retrieve the non-standard segments.

    This has worked in the past because the non-standard segment(s) were always present in the message and so getSegment() always found and returned the segment. This time, the segment is present in some messages but not all of them and when it isn't present the exception is thrown by getSegment().

    If your advice is that I should define a custom message then that's fair enough but it would be nice to be able to detect whether a non-standard segment is present and retrieve it using getSegment().

    Best regards.

    PS. Sorry about the duplicated reports - I clicked 'Refresh' and it seems that the report was re-submitted.