web stats
re-order HL7 Segments - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-04-2016, 08:47 AM
StickyBandit's Avatar
StickyBandit StickyBandit is offline
Mirth Guru
 
Join Date: Aug 2013
Location: Home Alone
Posts: 955
StickyBandit is on a distinguished road
Question re-order HL7 Segments

What would be the easiest (best way to code) the following?...
(using E4X I assume)

My work wants me to re-order some HL7 ERR segments based on a certain sorting of the value in ERR5.1 of each segment.
Reply With Quote
  #2  
Old 02-04-2016, 08:52 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

Quote:
Originally Posted by StickyBandit View Post
What would be the easiest (best way to code) the following?...
(using E4X I assume)

My work wants me to re-order some HL7 ERR segments based on a certain sorting of the value in ERR5.1 of each segment.
example message?
Reply With Quote
  #3  
Old 02-04-2016, 11:01 AM
StickyBandit's Avatar
StickyBandit StickyBandit is offline
Mirth Guru
 
Join Date: Aug 2013
Location: Home Alone
Posts: 955
StickyBandit is on a distinguished road
Default

MSH|^~\&|1111|UT0000|145|538|20160204115743||ACK^V 04^ACK|USIIS20160204115743|T|2.5.1
MSA|AR|20160127UU244223|Message Rejected.
ERR||PID^^5.3|101^Required field missing^HL70357|I^Information^HL70516|Q^Quality^US R0533|^^|
ERR||PID|^^HL70357|I^Information^HL70516|Q^Quality ^USR0533|^^|
ERR||RXA^^5.1|101^Required field missing^HL70357|I^Information^HL70516|V^Violation^ USR0533|^^|



We want the Violation first and the Quality below it.
Reply With Quote
  #4  
Old 02-04-2016, 11:06 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

Quote:
Originally Posted by StickyBandit View Post
MSH|^~\&|1111|UT0000|145|538|20160204115743||ACK^V 04^ACK|USIIS20160204115743|T|2.5.1
MSA|AR|20160127UU244223|Message Rejected.
ERR||PID^^5.3|101^Required field missing^HL70357|I^Information^HL70516|Q^Quality^US R0533|^^|
ERR||PID|^^HL70357|I^Information^HL70516|Q^Quality ^USR0533|^^|
ERR||RXA^^5.1|101^Required field missing^HL70357|I^Information^HL70516|V^Violation^ USR0533|^^|



We want the Violation first and the Quality below it.
I've done this before where I loaded all of the segments needed into an array, delete them from the message and then loop through the segments utilizing if statements to put them in the correct order. Might be a little overkill though

Here is what I did, you can modify it to meet your needs...

PHP Code:
//set the array
var message_segs = new Array();
//loop through message to add each segment to the array and delete segment from message
for each(seg in msg.children())
{
    var 
segi SerializerFactory.getSerializer('HL7V2').fromXML(seg);
    
message_segs.push(segi);
    
delete msg.children()[seg.childIndex()];
}
//loop through array and rebuild message in desired order
for(i=0;i<message_segs.length;i++)
{
    
//logger.info('seg: '+message_segs[i].toString().substring(0,3));
    
if(message_segs[i].toString().substring(0,3) == 'MSH')
    {
        
createSegment('MSH'msgi);
        
msg['MSH'][i] = message_segs[i].substring(4);
    }
    else if(
message_segs[i].toString().substring(0,3) == 'EVN')
    {
        
msg['EVN'][i] = message_segs[i].substring(4);
    }
    else if(
message_segs[i].toString().substring(0,3) == 'PID')
    {
        
msg['PID'][i] = message_segs[i].substring(4);
    }
    else if(
message_segs[i].toString().substring(0,3) == 'PV1')
    {
        
msg['PV1'][i] = message_segs[i].substring(4);
    }


Last edited by mcalKno; 02-04-2016 at 11:12 AM.
Reply With Quote
  #5  
Old 06-03-2016, 03:14 AM
ferdinand ferdinand is offline
OBX.1 Kenobi
 
Join Date: Sep 2014
Posts: 34
ferdinand is on a distinguished road
Default

Hi, i have modified it to suit my needs, but for a reason it does not run well, does not order the segments as I want...

PHP Code:
//set the array 
var message_segs = new Array(); 
//loop through message to add each segment to the array and delete segment from message 
for each(seg in msg.children()) 

    var 
segi SerializerFactory.getSerializer('HL7V2').fromXML(seg); 
    
message_segs.push(segi); 
    
delete msg.children()[seg.childIndex()]; 

//loop through array and rebuild message in desired order 
for(i=0;i<message_segs.length;i++) 

    
//logger.info('seg: '+message_segs[i].toString().substring(0,3)); 
    
if(message_segs[i].toString().substring(0,3) == 'MSH'
    { 
        
createSegment('MSH'msgi); 
        
msg['MSH'][i] = message_segs[i].substring(4); 
    } 
        else if(
message_segs[i].toString().substring(0,3) == 'PID'
    { 
        
msg['PID'][i] = message_segs[i].substring(4); 
    } 
    
    else if(
message_segs[i].toString().substring(0,3) == 'ORC'
    { 
         
msg['ORC'][i] = message_segs[i].substring(4); 
    }
    else if(
message_segs[i].toString().substring(0,3) == 'TQ1'
    { 
        
msg['TQ1'][i] = message_segs[i].substring(4); 
    }
    else if(
message_segs[i].toString().substring(0,3) == 'OBX'
    { 
        
msg['OBX'][i] = message_segs[i].substring(4); 
    }
    else if(
message_segs[i].toString().substring(0,3) == 'SPM'
    { 
        
msg['SPM'][i] = message_segs[i].substring(4); 
    }

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 07:08 PM.


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