Wilber Tang · Jul 25, 2016 1m read

Tips & Tricks - How to remove a group of HL7 segments

EnsLib.HL7.Message.cls provides many API methods for manipulating an HL7 message.  RemoveSegmentAt(), for example, can be used to remove a segment by path or index, but only one segment at a time.   There may be times that you'll need to remove all segments within a group or even many groups of segments from the HL7 message.  Surely you can iterate through each segment in each group and remove them one by one, but there's a much easier way. 


With just one command, like below, you can remove all OBX segments in an ORU_R01 message (msg):

Set tSC = msg.SetValueAt(,"PIDgrpgrp(1).ORCgrp(1).OBXgrp()","remove")


Or, with just the following command, you can easily remove all PR1 and ROL segments within a specific group in an ADT_A01 message (msg):

Set tSC = msg.SetValueAt(,"PR1grp(1)","remove")


I hope you'll find this article helpful. Let me know if you have any question or concern. Cheers!


0 1 1,251 1


@Wilber Tang, Thanks to your example, I have resolved my problem.

I was developing in a transformation in Ensemble, and could successfully remove an invalid OBX segment with the line below:

<assign value='' property='target.{PIDgrpgrp(k1).ORCgrp(k2).OBXgrp(k3).OBX}' action='remove' key='k3' />