Announcement

Collapse
No announcement yet.

Better way to do this? Iterate HL7

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 Files

  • #2
    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.

    Comment


    • #3
      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 Files

      Comment


      • #4
        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

        Comment


        • #5
          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?

          Comment


          • #6
            @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);

            Comment

            Working...
            X