web stats
Link OBX5 using assigned values - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2018, 10:42 AM
gojoshi gojoshi is offline
OBX.1 Kenobi
 
Join Date: Jul 2013
Posts: 35
gojoshi is on a distinguished road
Default Link OBX5 using assigned values

Hello Everyone,

I am working on a feed that has several OBX segments. There are OBX upwards of about 40 OBX segments on each message.

I need to do the following:
1. Take all of the OBX with the same values in OBX and add or clump the OBX5 values together.
2. Take all of the values in OBX 4 and assign the OBX set ID value accordingly.
3. Delete all of the original OBX segments

So, for example, suppose below are some of the OBX segments

OBX|1|NM|1|A|Hi|||||||
OBX|2|NM|2|B||I|||||||
OBX|3|NM|1|A|How||||||
OBX|4|NM|2|B|am|||||||
OBX|5|NM|1|A|Are||||||
OBX|6|NM|2|B|Fine|||||
OBX|7|NM|1|A|You||||||

The OBX structure should be transformed to the following
OBX|1|NM|||Hi how are you
OBX|2|NM|||I am fine


So basically, each of the OBX that has a value of 1 had the OBX5 values linked together. Likewise, all OBX segments with a value of 2 had the OBX5 linked together...
And OBX with a value of A was assigned a set ID of 1, and "B" set ID of 2.
And all of the original OBX segments have been removed

Any help on this will be greatly appreciated
Reply With Quote
  #2  
Old 07-23-2018, 11:42 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 747
agermano is on a distinguished road
Default

Code:
var obxGroups = [];
var newObxList = new XMLList();
for each (var obx in msg.OBX) {
    seqNo = obx['OBX.3']['OBX.3.1'].toString();
    if (typeof obxGroups[seqNo] == 'undefined') {
        obxGroups[seqNo] = [];
    }
    obxGroups[seqNo].push(obx['OBX.5']['OBX.5.1'].toString());
}

obxGroups.forEach(function(components,seqNo) {
    newObxList += <OBX>
        <OBX.1>
            <OBX.1.1>{seqNo}</OBX.1.1>
        </OBX.1>
        <OBX.2>
            <OBX.2.1>NM</OBX.2.1>
        </OBX.2>
        <OBX.3/>
        <OBX.4/>
        <OBX.5>
            <OBX.5.1>{components.join(' ')}</OBX.5.1>
        </OBX.5>
    </OBX>;
});

msg.OBX = newObxList;
Reply With Quote
  #3  
Old 07-31-2018, 08:35 AM
gojoshi gojoshi is offline
OBX.1 Kenobi
 
Join Date: Jul 2013
Posts: 35
gojoshi is on a distinguished road
Default

Thanks agermano. I have been OOO and back now. Will try the code you provided.. and update you.
Reply With Quote
  #4  
Old 08-03-2018, 07:40 AM
gojoshi gojoshi is offline
OBX.1 Kenobi
 
Join Date: Jul 2013
Posts: 35
gojoshi is on a distinguished road
Default

Hey agermano, this works great when OBX3.1 has a numeric value. Can't get it to work for non numeric values in OBX3.1, is there a way to change that?

Thanks for all of the help, much appreciated.
Reply With Quote
  #5  
Old 08-03-2018, 10:00 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 747
agermano is on a distinguished road
Default

Wouldn't OBX.3.1 have to have a numeric value if you're going to use that to set the OBX.1.1 value of the new segment?

Can you give another example where this isn't the case and how you want it to be handled?
Reply With Quote
Reply

Tags
concat, obx

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 03:52 PM.


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