web stats
Insert a New OBX Segment in MSG - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2019, 12:57 PM
stuart stuart is offline
OBX.1 Kenobi
 
Join Date: Oct 2012
Posts: 33
stuart is on a distinguished road
Default Insert a New OBX Segment in MSG

Hello All,

I can find solutions to inserting before or after segments, but none to insert at current location-1.

While iterating thru OBX's, if a value changes in OBX.3.2, I would like to insert a new OBX. I can do that, but it writes over an existing OBX. I use a counter and the createSegment (xxx, xxx, counter-1), or variations of the counter. Can someone point me in the right direction ?

Thanks for any direction here.
Reply With Quote
  #2  
Old 02-12-2019, 01:40 PM
stuart stuart is offline
OBX.1 Kenobi
 
Join Date: Oct 2012
Posts: 33
stuart is on a distinguished road
Default

Ok, I'm getting close but my counter is off and I don't know how to correct. If I insert 2 rows for example, the end of the output is 2 segments off.

Code:
var currentOBXSeg = " " ;
var segCounter = 0 ;
for each (obx in msg.OBX)
{

if (currentOBXSeg != obx['OBX.3']['OBX.3.1']['OBX.3.1.2'].toString())
{
currentOBXSeg = obx['OBX.3']['OBX.3.1']['OBX.3.1.2'].toString();

if (currentOBXSeg.includes("ANT" ) )
{
var obxSegment = createSegment('OBX',msg, segCounter ) ;
obxSegment['OBX.1']['OBX.1.1'] = segCounter ;
obxSegment['OBX.3']['OBX.3.1'] = "================================ SPECIMEN PART =====================" ;

segCounter++ ;
}
else if (currentOBXSeg.includes("CDX" ) )
{
var obxSegment = createSegment('OBX',msg, segCounter ) ;
obxSegment['OBX.1']['OBX.1.1'] = segCounter ;
obxSegment['OBX.3']['OBX.3.1'] = "================================ CLINICAL HX =====================" ;

segCounter++ ;
}

}

msg['OBX'][segCounter] = obx;
segCounter++ ;


}

The end of the resulting output is 2 segments short. The Z seg should be the last segment:

OBX|33|
OBX|34|
ZIR
OBX|35|
OBX|36|

Thanks for any direction...
Reply With Quote
  #3  
Old 02-13-2019, 08:42 AM
stuart stuart is offline
OBX.1 Kenobi
 
Join Date: Oct 2012
Posts: 33
stuart is on a distinguished road
Default

CLOSED:

Never figured out why count was off, ended up deleting Z segment, as not needed. Solution was derived from link: http://www.mirthproject.org/communit...rt+segment+obx
Reply With Quote
Reply

Tags
createsegment, insert new segment

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:36 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation