web stats
Moving the DG1 Segment before each OBR - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2016, 06:37 AM
atibbits atibbits is offline
Mirth Guru
 
Join Date: May 2012
Location: Salina, KS
Posts: 381
atibbits is on a distinguished road
Question Moving the DG1 Segment before each OBR

Does anyone have any ideas on the best way to move the DG1 segments before each OBR? I have been tasked with this and I am having a mental block for some reason.

Here is an example of what the inbound messages looks like:

Code:
MSH|^~\&|PRIMESUITE|1486|LAB||20160817114900||ORM^O01|1186|P|2.5.1|||AL
PID|1|332267|||RUBBLE^BARNEY||20010101|M||C|127 MAIN ST^^LINDSBORG^KS^67456^1|MCPHERSON||||||^^^P^N||^KS||^NOT HISPANIC OR LATINO
PV1|0001||^^^1020|VOIDED VISITS|||1005^BAXTER^W REESE^^^^^L|^^^^^^^L|||||||||1005^BAXTER^W REESE^^^^^L||817720||||||||||||||||||||1020
GT1|1||RUBBLE^BARNEY||127 MAIN ST^^LINDSBORG^KS^67456^1^^^MCPHERSON|||2001-01-01T00:00:00|M||1^SELF
ORC|NW|1486.573145.2||1486.573145.2|||201608171044||201608171048|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|1|1486.573145.2||THYGAB^THYROGLOBULIN LEVEL^L|R|20160817|201608171048||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|E79.8^GOUT DUE TO HYPERURICEMIA ASSOCIATED WITH MUTATION IN HPRT1 GENE^I10
ORC|NW|1486.573145.2||1486.573145.2|||201608171044||201608171048|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|2|1486.573145.2||RPR^QUALITATIVE (EG, VDRL, RPR, ART) SYPHILIS TEST^L|R|20160817|201608171048||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|E79.8^GOUT DUE TO HYPERURICEMIA ASSOCIATED WITH MUTATION IN HPRT1 GENE^I10
ORC|NW|1486.573145.2||1486.573145.2|||201608171044||201608171048|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|3|1486.573145.2||RUBELLA^RUBELLA ANTIBODY^L|R|20160817|201608171048||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|E79.8^GOUT DUE TO HYPERURICEMIA ASSOCIATED WITH MUTATION IN HPRT1 GENE^I10
Here is what they want it to look like:

Code:
MSH|^~\&|PRIMESUITE|1486|LAB||20160817114900||ORM^O01|1186|P|2.5.1|||AL
PID|1|332267|||RUBBLE^BARNEY||20010101|M||C|127 MAIN ST^^LINDSBORG^KS^67456^1|MCPHERSON||||||^^^P^N||^KS||^NOT HISPANIC OR LATINO
PV1|0001||^^^1020|VOIDED VISITS|||1005^BAXTER^W REESE^^^^^L|^^^^^^^L|||||||||1005^BAXTER^W REESE^^^^^L||817720||||||||||||||||||||1020
GT1|1||RUBBLE^BARNEY||127 MAIN ST^^LINDSBORG^KS^67456^1^^^MCPHERSON|||2001-01-01T00:00:00|M||1^SELF
ORC|NW|1486.573145.2||1486.573145.2|||201608171044||201608171048|||1005^BAXTER^W REESE^^^ ^MD^L
DG1|1|I10|E79.8^GOUT DUE TO HYPERURICEMIA ASSOCIATED WITH MUTATION IN HPRT1 GENE^I10
OBR|1|1486.573145.2||THYGAB^THYROGLOBULIN LEVEL^L|R|20160817|201608171048||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
ORC|NW|1486.573145.2||1486.573145.2|||201608171044||201608171048|||1005^BAXTER^W REESE^^^ ^MD^L
DG1|1|I10|E79.8^GOUT DUE TO HYPERURICEMIA ASSOCIATED WITH MUTATION IN HPRT1 GENE^I10
OBR|2|1486.573145.2||RPR^QUALITATIVE (EG, VDRL, RPR, ART) SYPHILIS TEST^L|R|20160817|201608171048||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
ORC|NW|1486.573145.2||1486.573145.2|||201608171044||201608171048|||1005^BAXTER^W REESE^^^ ^MD^L
DG1|1|I10|E79.8^GOUT DUE TO HYPERURICEMIA ASSOCIATED WITH MUTATION IN HPRT1 GENE^I10
OBR|3|1486.573145.2||RUBELLA^RUBELLA ANTIBODY^L|R|20160817|201608171048||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
Reply With Quote
  #2  
Old 08-18-2016, 01:22 PM
tiskinty tiskinty is offline
OBX.1 Kenobi
 
Join Date: Jun 2016
Posts: 44
tiskinty is on a distinguished road
Default

try this:
Code:
var ORCsegments = getSegmentsAfter(msg,msg['MSH'],'ORC',false);
var DG1segments = [];
var i=0;	

for each(orc in ORCsegments){
	DG1segments = getSegmentsAfter(msg,orc,'DG1',false);
	msg.insertChildAfter(orc,DG1segments[0]);
}

for each(seg in msg.children()){
    if(seg.name().toString() == 'DG1'&&i%2!=0){
        delete (msg.children()[seg.childIndex()]);
		i++;
    } 
	else if(seg.name().toString()=='DG1'){i++;}
}
using getSegmentsAfter from here
__________________
Matt

http://theunofficialmirthadmin.blogspot.com/

Last edited by tiskinty; 08-19-2016 at 04:49 AM.
Reply With Quote
  #3  
Old 08-19-2016, 04:38 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

This will work as needed

PHP Code:
//ORC loop
for each(orc in msg.ORC)
{
    
//loop through OBR
    
for each(obr in getSegmentsAfter(msg,orc,'OBR'))
    {
        
//set the DG1s following OBR to variable
          
var dg1Group getSegmentsAfter(msg,obr,'DG1');
        if(
dg1Group.length 0)
        {
            
//loop through DG1s in reverse order
               
for (var dg1Group.length-1>= 0i--)
            {
                
//add the DG1s after the ORC
                    
msg.insertChildAfter(orc,dg1Group[i]);
                    
//delete the DG1s from after the OBR as you go
                
delete (msg.children()[dg1Group[i].childIndex()]);
            }
        }

    }

Reply With Quote
  #4  
Old 08-19-2016, 08:28 AM
atibbits atibbits is offline
Mirth Guru
 
Join Date: May 2012
Location: Salina, KS
Posts: 381
atibbits is on a distinguished road
Default

Thanks!!! These both work!
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:36 AM.


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