web stats
Rearranging IN1 and IN2 segments - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2018, 03:27 PM
mpatterson mpatterson is offline
Mirth Newb
 
Join Date: Dec 2008
Posts: 9
mpatterson
Default Rearranging IN1 and IN2 segments

I am receiving ADT messages with the IN1 and IN2 segments ordered like this:

Code:
IN1|1|
IN1|2|
IN1|3|
IN2|1|
IN2|2|
IN2|3|
I need to re-arrange them so they look like this:

Code:
IN1|1|
IN2|1|
IN1|2|
IN2|2|
IN1|3|
IN2|3|
I'm not really good at Javascript in Mirth though. Any suggestions?
Reply With Quote
  #2  
Old 05-24-2018, 01:27 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 277
AlexNeiva is on a distinguished road
Default

Hello,


i create this code in order to rearrange the IN1 and IN2 segment.
Probably it can be done differently but i guess it works.


Code:
var arrIN1=[];
var arrIN2=[];

var xml=new XML();

for each (var seg in msg.children())
{
    if(seg.name() == "IN1")
        arrIN1.push(new XML(seg));
        
    if(seg.name() == "IN2")
        arrIN2.push(new XML(seg));
}

arrIN1.sort(function(a,b){return a['IN1.1']['IN1.1.1'] - b['IN1.1']['IN1.1.1']});
arrIN2.sort(function(a,b){return a['IN2.1']['IN2.1.1'] - b['IN2.1']['IN2.1.1']});

//--Having in consideration that IN1 and IN2 segment are have the same repetitions
for (var i=0; i<arrIN1.length; i++)
{
    xml+=arrIN1[i].toString() + arrIN2[i].toString();
}

xml="<HL7Message>" + 
        msg['MSH'].toString() + "\r\n" +
        msg['PID'].toString() + "\r\n" +
        xml + "\r\n" +
    "</HL7Message>";
     

msg=xml;

 //logger.info(SerializerFactory.getSerializer('HL7V2').fromXML(xml));
__________________
Best Regards,
Alex Neiva

Last edited by AlexNeiva; 05-24-2018 at 02:17 AM.
Reply With Quote
  #3  
Old 05-24-2018, 11:17 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

Code:
var reordered = new XMLList();
for each (var seg in msg.children()) {
    switch (seg.name().toString()) {
        case 'IN2':
            break;
        case 'IN1':
            reordered += seg;
            reordered += msg.IN2.(function() {return new XML(this)['IN2.1']['IN2.1.1'].toString() == seg['IN1.1']['IN1.1.1'].toString()}());
            break;
        default:
            reordered += seg;    
    }
}
msg.setChildren(reordered);
Reply With Quote
Reply

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:23 PM.


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