Question
Jordan Simpson · Jul 20

Looping Through Grouped NTE Segments

Hi!

Does anyone have a cleaner approach than this for looping through grouped NTE segments in order to set the segment ID in an ORM? I am aiming to avoid the NTE segments that may follow the PID segment and find the NTE's that follow the OBR segment. By using the below If statement in the While loop, I'm finding NTE's that have comments in the fourth field (PID NTE's tend not to have these in the messaging I'm seeing, I'm awaiting confirmation on this), as well as finding my newly inserted NTE segment using $FIND to locate the colon (I've concatenated some values).

Although this code is working, my worry is that if an NTE:4 field after the OBR segment happens to be blank for whatever reason then the If statement will miss out that NTE segment, also, if the NTE following the PID includes an NTE:4 then that will be recognised as part of this loop which isn't what I'd want. I don't suppose anyone has done something similar/cleaner without the need for this complexity?

 

Set SegCount=MsgOut.SegCountGet()
Set i=1
While i<=SegCount
{
        Set Seg=MsgOut.GetSegmentAt(i)
        If ((Seg.GetValueAt(0)="NTE")&&(Seg.GetValueAt(4)'=""))||($FIND(Seg.GetValueAt(3),":"))
        {
                Set tSC=Seg.SetValueAt($INCREMENT(NTEID),1)
        }
        Set i=i+1
}

 

Thanks!

00
2 0 3 59
Log in or sign up to continue

Are these messages all compliant with the doctype structure they're associated with?

If yes, why not use the symbolic path that the structure supplies ... i.e. something like MsgOut.GetValueAt("PIDgrpgrp.ORCgrp(n).OBXgrp(n).NTE(n)")?

Hi Jeffrey,

I was able to loop through the specific NTE segments with the following code:

Set NTEGroup=MsgIn.GetValueAt("ORCgrp(1).OBRuniongrp.NTE(*)")
Set i=1
While i<=NTEGroup
{
    Set NTESeg=MsgIn.GetValueAt("ORCgrp(1).OBRuniongrp.NTE("_i_")")
    $$$TRACE(NTESegIndex)
    Set i=i+1
}

The trouble I have now is moving these NTE's to the end of the message beneath the SPM segment without it disrupting anything else. I am attempting to do this by first of all getting the segment index and then removing the segment referenced (commented out below). I am then getting the full segment string and importing that as a segment to then append them to the outbound message.

Set NTEGroup=MsgIn.GetValueAt("ORCgrp(1).OBRuniongrp.NTE(*)")
Set i=1
While i<=NTEGroup
 {
    Set NTESegIndex=MsgIn.GetSegmentIndex("ORCgrp(1).OBRuniongrp.NTE("_i_")")
    ;Set tSC=MsgOut.RemoveSegmentAt(NTESegIndex)
    Set NTEStr=MsgIn.GetValueAt("ORCgrp(1).OBRuniongrp.NTE("_i_")")
    Set NTE=##class(EnsLib.HL7.Segment).ImportFromString(NTEStr,.tSC,MsgIn.Separators)
    Set tSC=MsgOut.AppendSegment(NTE)
    Set i=i+1
 }

If I remove the RemoveSegmentAt() line, the segments are appending without any issues. Once I start using the RemoveSegmentAt() line, they still append but it causes some issues with other segments by removing the SPM segment and not removing all the NTE's expectedly.

Without RemoveSegmentAt()

NTE|1||Transfusion indications->Hgb <= 9 g/dL with chronic transfusion therapy
NTE|2||Has consent been obtained?->Yes
SPM|1|||Environment^Environmental sample||||||||||||||||Y
NTE|1||Transfusion indications->Hgb <= 9 g/dL with chronic transfusion therapy
NTE|2||Has consent been obtained?->Yes

With RemoveSegmentAt()

NTE|2||Has consent been obtained?->Yes
NTE|1||Transfusion indications->Hgb <= 9 g/dL with chronic transfusion therapy
NTE|2||Has consent been obtained?->Yes

Is there another recommended way of doing this?

Thanks!

Edit - I've been able to achieve this by creating a new message and building it from scratch and only looping through and grabbing the segments I need.

Building a new message would have been my suggestion had I seen this in time, but you arrived at the same conclusion without my help!