ED Coder · Jul 31, 2019

Remove a segment from the HL7 Message


I have a ORU message, which has a EVN segment that I want to remove and send the message across.

I tried to clone the request as below:

s newreq = request.constructClone

s changreq = newreq.RemoveSegmentAt("EVN")

Set request  = changereq

but it fails. Is there a way that I can safely remove a segment and pass it on?

Would appreciate your help in this



0 1,137
Discussion (12)0
Log in or sign up to continue

The method RemoveSegmentAt returns a status, not the message with the segment removed.

So your HL7 message with the EVN removed is still "newreq" and it is this that you want to pass on.

Hi Julian, thank you for pointing that out to me. Can you advice how I can remove that segment?

Thanks Jeff, that's a better articulation of what I originally tried to say. smiley

Hi Jeff, I tried that, but I am losing the rest of my message. I must be doing something wrong. Can you advice? Following is the error I am getting  once I remove segment and pass the messsage

Personally, I would use a DTL which removes the EVN, and then I would call the DTL class from objectscript:

Set tSC=$CLASSMETHOD("DEV.Transformations.DUMMY.A01toA01","Transform",request,.messageWithoutEVN)

So, "Transform" in quotes is the action, request is your original Enslib.HL7.Message coming in, and .messageWithoutEVN is the output from your DTL.

Does that help?

the message coming in is an ORU_R01 message, and contains an EVN segment, however in the schema 2.4 there is no EVN segment in the ORU message structure. so how can I remove the segment, is there a way to do that? Sorry for the hassle.  

I want to pass this message to the third party system having the EVN segment removed. Will keep trying but if you have any ideas would apprecaite.

Thank you

I would expect to see that error on the original message (before the EVN segment was deleted) but not on the cloned/modified version. Are you sure you're looking at the right message?

Yes Jeff, I was looking at the cloned message that was sent across. I removed by index now, and it works. so looking good. Thank you so much for guiding me on this

Ah, now it makes sense. The Document type you'd specified for the inbound message did not match the structure of the message itself, so the RemoveSegmentAt() method didn't know how to "find" the EVN segment ... it didn't exist in that schema.

The recommended approach would be to use a schema/document type (custom if necessary) that matches the structure of your inbound message, making the segment to be removed optional in the definition. With that in place, the RemoveSegmentAt() method would have worked as expected.

You are spot on Jeff. Yes, I was thinking if I should update the schema.. but didnt do it. The message we are getting is an ORU_01 but has the EVN segment.  Thank You, now I know what caused my issue too.

You were close with you original code ...

Set newreq = request.%ConstructClone()

Set sc = newreq.RemoveSegmentAt("EVN")

Set request = newreq

the variable sc is the status of the remove segment operation; the EVN segment is actually removed from newreq.

Was able to solve this by the following code.

//create a copy of the request
s newREQ = request.%ConstructClone()
ind = ""
EVNSeg = newREQ.FindSegment("EVN",.ind)
if EVNSeg '= ""
res = newREQ.RemoveSegmentAt(ind)

request = newREQ

Quit request