No announcement yet.

MySQL Query not recognizing variables declared in Javascript

  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL Query not recognizing variables declared in Javascript


    I am a very new user of Mirth Connect using Version

    I am trying to create a Mirth channel that takes an incoming ADT message from a file on a directory, pulls the field values and posts them to a MySQL database.

    Because blank dates error out in Mirth, I have escaped the date fields inside an 'if' statement in a JavaScript transformer:

    var PID_7_Patient_Date_Time_of_Birth = ""; 
    if (msg['PID']['PID.7']['PID.7.1'].toString() != "")
        PID_7_Patient_Date_Time_of_Birth = DateUtil.convertDate("yyyyMMdd", "yyyy-MM-dd", msg['PID']['PID.7']['PID.7.1'].toString()); 
    In my sql statement I have declared this variable the same way that I have declared the other variables defined using Mapper transformers. However, I notice that, while the variables defined using mapper transformers appear in the Destination Mappings column, the variables I defined using JavaScript do not.

    When I run the Mirth channel the PID 7 variable gets treated like a string with literal value " ${PID_7_Patient_Date_Time_of_Birth} " in the SQL database field DateOfBirth column, and errors out because the database is expecting a date value.

    What am I doing wrong and how do I use JavaScript defined variables in my SQL Query?

    I have attached the Mirth channel as "ADT_A08_to_MySQL.xml", and the stack trace of the error I received as "adt_SQL.txt".

    Thank You so much for the help,

    Griffin Lewis
    Attached Files

  • #2
    MySQL query :

    insert into patient (MRN, FirstName, LastName, MiddleInitial, DateOfBirth, Gender, Address1, Address2, City, State, ZipCode, HomePhone, BusinessPhone, SSN)
    values (${PID_3_Patient_Identifier_List}, ${PID_5_2_Patient_Name_Given_Name}, ${PID_5_1_Patient_Name_Family_Name}, ${PID_5_3_Paitent_Name_Middle_Initial}, 
    -- this variable is being declared by a Javascript transformer. It is not listed in the destination mappings.
    -- the rest of these variables are created in Mapper transformers. 
    ${PID_8_Patient_Sex}, ${PID_11_1_Patient_Address_Address1}, ${PID_11_2_Patient_Address_Address2}, ${PID_11_3_Patient_Address_City}, ${PID_11_4_Patient_Address_State}, ${PID_11_5_Patient_Address_Zip}, 
    ${PID_13_Patient_Phone_Number_Home}, ${PID_14_Patient_Phone_Number_Business}, ${PID_19_Patient_SSN});


    • #3
      You need to put those variables in one of the variable maps. Look at the References tab, there are entries specifically to do just that.
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

      - How do I foo?
      - You just bar.


      • #4
        Thank You so much, that one worked.