Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Processing message elements in a transformer

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

  • Processing message elements in a transformer

    I'm trying to write a transformer that handles an HL7 message that has variable segments. I've concocted the following fictitious message:

    MSH EVN PID [NK1]

    ie zero or more NK1 segments.

    I've written the following (abominable) JavaScript code to iterate across these segments and extract and concatenate the required data:

    Code:
    var count = 0;
    var nokArray = new Array();
    var first = "?";
    var middle = "?";
    surname = "?";
    var name = "?";
    
    
    for each (nk1 in msg..NK1) {
      first = msg['NK1'][count]['NK1.2.1'].toString();
      middle = msg['NK1'][count]['NK1.2.2'].toString();
      surname = nk1['NK1']['NK1.2']['NK1.2.3'].toString();
      nokArray[count] = first + "_" + middle + "_" + surname;
      count++;
    
    //  first = msg['NK1'][count]['NK1.2.1'];
    //  first = nk1.NK1.2.1.1;
    //  first= nk1.2.1.1;
    }
    
    logger.info('nokcount = ' + count);
    channelMap.put('nokcount', count);
    channelMap.put('noks', nokArray.toString());
    channelMap.put('fms', first + "/" + middle + "/" + surname);
    The 'for each' iteration works ok but extracting the first, middle and surname fields always returns a blank. Commented out are some attempts to use the iteration variable to access these fields - they also either return a blank or cause the channel not to be deployable.

    Could someone kindly point out the error of my ways or point me at some working example - I search the forum but found nothing that worked for me.

    Thanks,
    David

  • #2
    Re:Processing message elements in a transformer

    This works:

    Code:
    var count = 0;
    var nokArray = new Array();
    
    for each (nk1 in msg..NK1) {
      first = nk1['NK1.2']['NK1.2.1'];
      middle = nk1['NK1.2']['NK1.2.2'];
      surname = nk1['NK1.2']['NK1.2.3'];
      name = first + " " + middle + " " + surname;
    
      logger.info("Name: [" + name + "]"«»);
      nokArray[count] = name;
      count++;
    }
    but I was expecting a dot means of traversing the tree (eg nk1.2.1 etc) - is that possible?

    Comment


    • #3
      Re:Processing message elements in a transformer

      This works:

      Code:
      var count = 0;
      var nokArray = new Array();
      
      for each (nk1 in msg..NK1) {
        first = nk1['NK1.2']['NK1.2.1'];
        middle = nk1['NK1.2']['NK1.2.2'];
        surname = nk1['NK1.2']['NK1.2.3'];
        name = first + " " + middle + " " + surname;
      
        logger.info("Name: [" + name + "]"«»);
        nokArray[count] = name;
        count++;
      }
      but I was expecting a dot means of traversing the tree (eg nk1.2.1 etc) - is that possible?

      Comment


      • #4
        Re:Processing message elements in a transformer

        This works:

        Code:
        var count = 0;
        var nokArray = new Array();
        
        for each (nk1 in msg..NK1) {
          first = nk1['NK1.2']['NK1.2.1'];
          middle = nk1['NK1.2']['NK1.2.2'];
          surname = nk1['NK1.2']['NK1.2.3'];
          name = first + " " + middle + " " + surname;
        
          logger.info("Name: [" + name + "]"«»);
          nokArray[count] = name;
          count++;
        }
        but I was expecting a dot means of traversing the tree (eg nk1.2.1 etc) - is that possible?

        Comment


        • #5
          Re:Processing message elements in a transformer

          This works:

          Code:
          var count = 0;
          var nokArray = new Array();
          
          for each (nk1 in msg..NK1) {
            first = nk1['NK1.2']['NK1.2.1'];
            middle = nk1['NK1.2']['NK1.2.2'];
            surname = nk1['NK1.2']['NK1.2.3'];
            name = first + " " + middle + " " + surname;
          
            logger.info("Name: [" + name + "]"«»);
            nokArray[count] = name;
            count++;
          }
          but I was expecting a dot means of traversing the tree (eg nk1.2.1 etc) - is that possible?

          Comment


          • #6
            Re:Processing message elements in a transformer

            This works:

            Code:
            var count = 0;
            var nokArray = new Array();
            
            for each (nk1 in msg..NK1) {
              first = nk1['NK1.2']['NK1.2.1'];
              middle = nk1['NK1.2']['NK1.2.2'];
              surname = nk1['NK1.2']['NK1.2.3'];
              name = first + " " + middle + " " + surname;
            
              logger.info("Name: [" + name + "]"«»);
              nokArray[count] = name;
              count++;
            }
            but I was expecting a dot means of traversing the tree (eg nk1.2.1 etc) - is that possible?

            Comment


            • #7
              Maybe you could redirect localhost on your box to the proper IP? You would use the hosts file in windows to do this.


              _______________________________
              http://crave4leather.com
              Last edited by saboor; 11-12-2016, 03:00 AM.

              Comment

              Working...
              X