web stats
Creating a repeating field...help! - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-22-2016, 06:13 AM
atibbits atibbits is offline
Mirth Guru
 
Join Date: May 2012
Location: Salina, KS
Posts: 381
atibbits is on a distinguished road
Thumbs down Creating a repeating field...help!

I have been trying to create a repeating field and I am failing! I need to figure out a way to combine all of the DG1 and DG2 segments into 1 segment and turn DG1.3.1 into a repeating field that contains the codes.

Here is the before:

Code:
MSH|^~\&|PRIMESUITE|1486|LAB|LAB|20160817111109||ORM^O01|1185|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.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|1|1486.573059.2||PSA^PSA SERUM TUBE ONLY 2580^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00^TYPHOID AND PARATYPHOID FEVERS^I10
ORC|NW|1486.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|2|1486.573059.2||HGA1C^HEMOGLOBIN A1C (LABCORP) 001453^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00^TYPHOID AND PARATYPHOID FEVERS^I10
ORC|NW|1486.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|3|1486.573059.2||PT^PROTIME LABCORP 005199^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00^TYPHOID AND PARATYPHOID FEVERS^I10
DG1|2|I10|I25.10^CORONARY ARTERY DISEASE
ORC|NW|1486.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|4|1486.573059.2||T3FREE^T3 FREE^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00^TYPHOID AND PARATYPHOID FEVERS^I10
ORC|NW|1486.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|5|1486.573059.2||TESTF^TESTOSTERONE, FREE, DIRECT* 144980^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00^TYPHOID AND PARATYPHOID FEVERS^I10
ORC|NW|1486.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|6|1486.573059.2||THYAB^ANTITHYROID ANTIBODIES 006684^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00^TYPHOID AND PARATYPHOID FEVERS^I10
Here is what the after should look like:

Code:
MSH|^~\&|PRIMESUITE|1486|LAB|LAB|20160817111109||ORM^O01|1185|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.573059.2||1486.573059.2|||201608171009||201608171010|||1005^BAXTER^W REESE^^^ ^MD^L
OBR|1|1486.573059.2||PSA^PSA SERUM TUBE ONLY 2580^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
DG1|1|I10|A01.00~A01.00~A01.00~I25.10~A01.00~A01.00~A01.00
OBR|2|1486.573059.2||HGA1C^HEMOGLOBIN A1C (LABCORP) 001453^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
OBR|3|1486.573059.2||PT^PROTIME LABCORP 005199^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
OBR|4|1486.573059.2||T3FREE^T3 FREE^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
OBR|5|1486.573059.2||TESTF^TESTOSTERONE, FREE, DIRECT* 144980^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
OBR|6|1486.573059.2||THYAB^ANTITHYROID ANTIBODIES 006684^L|R|20160817|201608171010||||N|||||1005^BAXTER^W REESE^^^ ^MD^L|||||||||||^^^^^R
Any ideas would be very much appreciated!!

Thanks!!!!
Reply With Quote
  #2  
Old 08-22-2016, 06:25 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 841
siddharth is on a distinguished road
Default

I answered a similar question on SO 2 years ago. I hope this link will help you.
http://stackoverflow.com/questions/2...76720#21476720
Reply With Quote
  #3  
Old 08-22-2016, 07:44 AM
kab7715 kab7715 is offline
OBX.1 Kenobi
 
Join Date: Aug 2015
Posts: 47
kab7715 is on a distinguished road
Default

PHP Code:
//array to store all the dg1.3.1 values
var newDG131 = [];

//saving these fields to rebuld DG1
var dg1_1_1 msg['DG1'][0]['DG1.1']['DG1.1.1'].toString();
var 
dg1_2_1 msg['DG1'][0]['DG1.2']['DG1.2.1'].toString();

//pushing all the dg1.3.1 values to array
for each(var dg1_3_1 in msg.DG1['DG1.3']['DG1.3.1'])
{
    
newDG131.push(dg1_3_1.toString());
}

//delete all DG1s
delete msg['DG1'];


//creates the new single DG1 after the first OBR as in your output mssg sample 
var newDG1 createSegmentAfter('DG1'msg.OBR[0])
newDG1['DG1.1']['DG1.1.1'] = dg1_1_1.toString();
newDG1['DG1.2']['DG1.2.1'] = dg1_2_1.toString();

if(
newDG131.length 0)
{
    var 
counter 1;
    
logger.info(newDG131.length)
    for 
each(var d in newDG131)
    {
        if(
counter != newDG131.length)
        {
            
newDG1['DG1.3']['DG1.3.1'] += d.toString() + '~';
            
counter++;
        }
        else
        {
            
newDG1['DG1.3']['DG1.3.1'] += d.toString();
        }
    }

this should do it based on your source msg and output message examples, might be a slicker way of doing it but i like to piece the steps out makes it easier to read and see what its doing.
Reply With Quote
  #4  
Old 08-22-2016, 08:31 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!!!!!Thank you so much!!
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:10 AM.


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