web stats
Better way to do this? Iterate HL7 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2018, 08:58 AM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default Better way to do this? Iterate HL7

Hi all,

I'm sure there is a better way to do what I'm doing, but I haven't mastered the use of the "iterator" abilities of Mirth.

I have an HL7 message with multiple AL1 segments and DG1 segments. I want to take all the values from AL1.3.2 and concatenate them into one field on the output separated by comma's. Same for the DG1 segments.

Currently I do this by creating a new mapping variable in the Message Tree (right click -> map to variable) for the maximum possible number of segments in the file. I then concatenate all of them in the destination like this:

//Concatonate the multiple allergies
var allergies = '';
allergies = $('allergy_info') + ", " + $('allergy_info2') + ", " + $('allergy_info3');

So my question is can this be done using the iterator instead? If so, can someone point me to a thread or explanation?

Thanks in advance.
Attached Images
File Type: jpg Iterator2.JPG (19.8 KB, 10 views)
File Type: jpg Iterator1.JPG (19.2 KB, 9 views)
Reply With Quote
  #2  
Old 08-28-2018, 10:48 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 963
agermano is on a distinguished road
Default

This is an Iterator step with a Message Builder sub-step followed by another Message Builder step that is not part of the Iterator. You can use the resulting allergies string in and steps following these steps. If you require the string in a mapper variable, you could also replace the last Message Builder step with a Mapper step, mapping allergies.join(',') to the variable.

When building the Iterators it is a good idea to frequently check the generated script tab to see what it's actually doing. In this case, it is initializing the allergies variable with a new javascript array in the global (to this transformer) scope.

Code:
Iterator:
    Iterator On: msg['AL1']['AL1.3']['AL1.3.2']
    Index Variable: i

    Message Builder (add AL1.3.2 to allergies array):
        Message Segment: allergies[i]
        Mapping: msg['AL1']['AL1.3']['AL1.3.2'][i].toString()

Message Builder (convert allergies array to comma joined string):
    Message Segment: allergies
    Mapping: allergies.join(',')
The placement of [i] can change and still work, depending on your needs. Having it after ['AL1.3.2'] instead of ['AL1'] means that it will pick up all of them individually, regardless if you have repeating AL1 segments or repeating AL1.3 fields.
Reply With Quote
  #3  
Old 08-28-2018, 01:49 PM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default

Thanks agermano,

I guess I need more info. When you say sub-step, does that mean embed the message builder within another message builder iterator? And would the join step be done on the source transformer or in the destination javascript I have in my original post?
Attached Images
File Type: jpg Iterator3.JPG (32.7 KB, 12 views)
File Type: jpg Iterator4.JPG (28.0 KB, 6 views)
Reply With Quote
  #4  
Old 08-29-2018, 02:12 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 93
amble is on a distinguished road
Default

Can't you just push them into an array then .toString() as a var? I use something similar for a different use case but it might work for you as well:

Code:
Test message

MSH|^~\&|||||||ADT^A31^ADT_A05||P|2.4
EVN|A31|||||
PID|1|||||||||||||||||||||||||||||||
PD1||||
AL1|1||^ALERT 1^||
AL1|2||^ALERT 2^||
AL1|3||^ALERT 3^||
AL1|4||^ALERT 4^||
AL1|5||^ALERT 5^||
AL1|6||^ALERT 6^||
AL1|7||^ALERT 7^||
Just do the same for DG1 as well if it works for you
Attached Files
File Type: xml al1Test.xml (21.0 KB, 33 views)
Reply With Quote
  #5  
Old 08-29-2018, 01:56 PM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default

Thanks Amble, this works well for what I need. However, I'm not sure how to access the javascript transformer in my destination javascript code.

For example, all the other source transformers I have are Mappers and can be access like this:
//Concatenate the multiple allergies here
var allergies = '';
allergies = ${allergy_info};
log(allergies);

but I don't have access to drag / drop the al1var the same way, how do I access this transformer?
Reply With Quote
  #6  
Old 08-30-2018, 06:31 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 963
agermano is on a distinguished road
Default

@amble I gave an Iterator solution because that is what was asked for. The default behaviors of calling toString() or join(',') on a javascript Array do the same thing, but the join makes the intended outcome clearer.

@psanders You don't need to store things in map variables if the only purpose is to use them in the current transformer. In amble's code, "obj" was the name given to the array. The following should work.

Code:
allergies = obj.join(',');
log(allergies);
Reply With Quote
Reply

Tags
hl7, iterate repeating fields

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 04:20 PM.


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