web stats
Creating a repeating field from multiple OBR segments - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-17-2016, 06:52 AM
atibbits atibbits is offline
Mirth Guru
 
Join Date: May 2012
Location: Salina, KS
Posts: 381
atibbits is on a distinguished road
Exclamation Creating a repeating field from multiple OBR segments

I have been tasked with combining any OBR segments into 1 and making OBR.4 into a repeating field that contains all of the OBR.4 values from the inbound OBR segments.

Here is what I am receiving....

Code:
MSH|^~\&|PRIMESUITE|1486|LabDaq||20160128175537||ORM^O01|258048|P|2.3|||AL
PID|||300065||Tiger^Baby||19960121|F|||222 N Smith St^^Salina^KS^67401||9999999999
IN1|0002|2015|1331|Sunflower State Health Plan|PO Box 4070^^Farmington^MO^63640-3833||||Sunflower State Health Plan||||||M|Tiger^Baby|5|1996-01-21T00:00:00|222 N Smith St^^Salina^KS^67401|Y||Y|||||||||N|||||00111422593
IN1|0001|1440|1034|Medicare|PO Box 7238^^Madison^WI^53707-7238|||NONE|Medicare Part B||||||C|Tiger^Baby|5|1996-01-21T00:00:00|222 N Smith St^^Salina^KS^67401|Y||N|||||||||N|||||123456789A
IN1|0004|1508|1035|BCBS|1133 SW Topeka Blvd^^Topeka^KS^66629-0001||8004320379|39485309845|Bcbs Of Federal||||||B|Tiger^Tony^T|5|1986-02-18T00:00:00|40 Salina Regional lane^^Salina^KS^67401|Y||U|||||||||N|||||945345839850980981
IN2||555268197
IN1|0003|1689|1269|Progressive Auto Insurance|Po Box 512926^^Los Angeles^CA^90051|||546046054654|Progressive Insurance Company||||||O|Tiger^Baby|5|1996-01-21T00:00:00|222 N Smith St^^Salina^KS^67401|Y||U|||||||||N|||||5406406046804
ORC|NW|1486.421445.1||1486.421445.1
OBR|1|1486.421445.1||110^CBC w diff|||2016012800|||||||||1497866099^Cobb^Matthew^L^^ ^MD
DG1|1|I10|K92.1|Blood In Stool
ORC|NW|1486.421445.1||1486.421445.1
OBR|1|1486.421445.1||007401^Dilantin 007401*|||2016012800|||||||||1497866099^Cobb^Matthew^L^^ ^MD
DG1|1|I10|K92.1|Blood In Stool
Here is what I need it to look like on the way out....


Code:
MSH|^~\&|PRIMESUITE|1486|LabDaq||20160128175537||ORM^O01|258048|P|2.3|||AL
PID|||300065||Tiger^Baby||19960121|F|||222 N Smith St^^Salina^KS^67401||9999999999
IN1|0002|2015|1331|Sunflower State Health Plan|PO Box 4070^^Farmington^MO^63640-3833||||Sunflower State Health Plan||||||M|Tiger^Baby|5|1996-01-21T00:00:00|222 N Smith St^^Salina^KS^67401|Y||Y|||||||||N|||||00111422593
IN1|0001|1440|1034|Medicare|PO Box 7238^^Madison^WI^53707-7238|||NONE|Medicare Part B||||||C|Tiger^Baby|5|1996-01-21T00:00:00|222 N Smith St^^Salina^KS^67401|Y||N|||||||||N|||||123456789A
IN1|0004|1508|1035|BCBS|1133 SW Topeka Blvd^^Topeka^KS^66629-0001||8004320379|39485309845|Bcbs Of Federal||||||B|Tiger^Tony^T|5|1986-02-18T00:00:00|40 Salina Regional lane^^Salina^KS^67401|Y||U|||||||||N|||||945345839850980981
IN2||555268197
IN1|0003|1689|1269|Progressive Auto Insurance|Po Box 512926^^Los Angeles^CA^90051|||546046054654|Progressive Insurance Company||||||O|Tiger^Baby|5|1996-01-21T00:00:00|222 N Smith St^^Salina^KS^67401|Y||U|||||||||N|||||5406406046804
ORC|NW|1486.421445.1||1486.421445.1
OBR|1|1486.421445.1||110^CBC w diff~007401^Dilantin 007401*|||2016012800|||||||||1497866099^Cobb^Matthew^L^^ ^MD
DG1|1|I10|K92.1|Blood In Stool
DG1|1|I10|K92.1|Blood In Stool
Any help would be appreciated!!!!!
Reply With Quote
  #2  
Old 02-17-2016, 08:46 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

This should work for you. You'll have to clean up the extra ORC segments

PHP Code:
var obrCount 0;
var 
OBRs = new Array();

for 
each(obr in msg.OBR)
{
    
obrCount obrCount+1;
    var 
obr4 SerializerFactory.getSerializer('HL7V2').fromXML(obr['OBR.4'].toString());
    
OBRs.push(obr4);
    
obr['OBR.4'] = '';
    
    if(
obrCount 1)
    {
        
delete (msg.children()[obr.childIndex()]);
    }
    
    
}

for (var 
i=0;i<OBRs.length;i++)
{
    if(
msg['OBR']['OBR.4'].toString().length 1)
    {
        
msg['OBR']['OBR.4'] = OBRs[i];
    }
    else
    {
        
msg['OBR']['OBR.4'] += '~'OBRs[i];
    }

Reply With Quote
  #3  
Old 02-17-2016, 10:11 AM
rutledj rutledj is offline
Mirth Guru
 
Join Date: Nov 2010
Location: North Carolina
Posts: 399
rutledj is on a distinguished road
Default

Came up with something similar. Great minds think alike?

Transformer javascript code:


Code:
var i = 0;
var obr4Contents = '';

//Remove all orcs after first one
for each (seg in msg..ORC) 
{
	if (i > 0)
	{
		logger.info('deleting ORC');
		delete msg.children()[seg.childIndex()];
	}	  

	i += 1;
}


//get all obrs after first one
i = 0;
for each (seg in msg..OBR) 
{
	obr4Contents += seg['OBR.4']['OBR.4.2'].toString() + '~';
	if (i > 0)
	{
		logger.info('deleting ');
		delete msg.children()[seg.childIndex()];
	}	  

	i += 1;
}

//set first obr.4 contents
msg['OBR'][0]['OBR.4']['OBR.4.2'] = obr4Contents.substring(0, obr4Contents.length -1);

Last edited by rutledj; 02-17-2016 at 10:16 AM.
Reply With Quote
  #4  
Old 02-17-2016, 10:43 AM
atibbits atibbits is offline
Mirth Guru
 
Join Date: May 2012
Location: Salina, KS
Posts: 381
atibbits is on a distinguished road
Default

This works great! I have already worked on the ORC segments so this was the piece I was struggling with! Thanks!!!
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 06:44 AM.


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