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

Transform Javascript IF statement

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

  • Transform Javascript IF statement

    In my transformer I have a javascript step that is using a IF statement to populate the PV1.3.4 field in my HL7 message. I need the step to look at the PV1.2 field for a certain value and then populate the PV1.3.4 field based on that value. Below is the code that I am using.

    if (msg['PV1']['PV1.2'].toString() == "E") {
    msg['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";
    } else {
    msg['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";
    }

    When I send a message the transformed message tab shows the if statement working, but the encoded message does not have the PV1.3.4 field being populated. Any help would be appreciated.

    Post edited by: pfrey, at: 02/15/2008 07:55

  • #2
    Re:Transform Javascript IF statement

    Change the msg to tmp. I think the msg is the original message, and tmp is the message set to send to the outbound connection with all the transformers/modifications.


    if (msg['PV1']['PV1.2'].toString() == "E") {

    tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";

    } else {

    tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";

    }
    Reid Hospital and Healthcare

    Comment


    • #3
      Re:Transform Javascript IF statement

      Thanks for the suggestion but it did not help. There is no message in the encoded tab and the transformed message is not displaying the change now either. I am using Mirth 1.6.1 if that makes a difference. Any other suggestions?

      Comment


      • #4
        Re:Transform Javascript IF statement

        When I use tmp in the javascript code, it returns an error stating

        ReferenceError: "tmp" is not defined.

        When I change the code back to msg then the values do not appear in the PV1.3.4 field in the encoded message. Any other ideas or suggestions?

        Thanks!

        Comment


        • #5
          Temporary work space needed

          AfterDark was correct, however, you need to declare the tmp variable before using it.


          Code:
          // Create a temporary workspace variable
          tmp=msg;
          
          if (msg['PV1']['PV1.2'].toString() == "E") {
          
          tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";
          
          } else {
          
          tmp['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";
          
          }

          Comment


          • #6
            tmp is only valid if you're using an outbound message template. If you're not using an outbound template you'll need to include 'return tmp;' at the end of your transformer or none of your modifications will work. I think... a little out of current practice.

            The code originally posted looks sane. Try logger.info('Found E!'); inside the first braces so you can see the conditional match dumped to the console and verify that the logic is triggered by the condition.

            Comment

            Working...
            X