web stats
ForEach Java Loop - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-12-2019, 11:35 AM
Character Zer0 Character Zer0 is offline
What's HL7?
 
Join Date: Dec 2019
Posts: 1
Character Zer0 is on a distinguished road
Default ForEach Java Loop

Hey Everyone,

I am sure this is a simple fix but I am kinda new to Javascript and trying to fix a problem I've been given.

Basically I have an incoming interface that gives me a dynamic number of OBX segments. Could be two or three or four. What I'm trying to do is take the data from OBX 5.1 and move that to OBX 5.5 while appending it with ^AP^PDF^Base64^.

In summary:
1 OBX 5.1 'random encoded data' -> OBX5.1 'AP'PDF'Base64'random encoded data'
2 OBX 5.1 'random encoded data' -> OBX5.1 'AP'PDF'Base64'random encoded data'
3 OBX 5.1 'random encoded data' -> OBX5.1 'AP'PDF'Base64'random encoded data'

Hope I'm explaining myself correctly but I've been looking at it for a half day and have no idea why it's not working.
Reply With Quote
  #2  
Old 12-18-2019, 07:22 AM
kirbykn2's Avatar
kirbykn2 kirbykn2 is offline
Mirth Guru
 
Join Date: Sep 2014
Location: Michigan
Posts: 613
kirbykn2 is on a distinguished road
Default

are you getting an error? can you post what you have already done?
__________________
Best,

Kirby

Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

Appliance Version 3.11.4
Mirth Connect Version 3.8.0
Java Version 1.6.0_45-b06
Java (64 bit) Version 1.6.0_45-b06
Java 7 (64 bit) Version 1.7.0_151-b15
Java 8 (64 bit) Version 1.8.0_181-b13
PostgreSQL Version 9.6.8
Reply With Quote
  #3  
Old 12-18-2019, 07:41 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,360
cory_cole is on a distinguished road
Default

obx_count = 0;

for each(obx in msg['OBX'])
{
msg['OBX'][obx_count]['OBX.5] = msg['OBX'][obx_count++]['OBX.1'].toString() + '^AP^PDF^Base64^';
}
Reply With Quote
  #4  
Old 12-18-2019, 08:17 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road
Default

I think this is what you were trying to say. You have to remember when you are in a transformer that you're working with xml objects, not strings. Your field and component separators are not part of your data.

Code:
for each (var obx5 in msg.OBX['OBX.5']) {
    obx5['OBX.5.2'] = 'AP';
    obx5['OBX.5.3'] = 'PDF';
    obx5['OBX.5.4'] = 'Base64';
    obx5['OBX.5.5'] = obx5['OBX.5.1'].toString();
}
It is a good idea when you post to include your code that isn't working, like Kirby said. It helps other people help you to understand what you are doing wrong.

Last edited by agermano; 12-18-2019 at 08:22 AM.
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:35 AM.


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