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

Repeating segments and populating database

  • Filter
  • Time
  • Show
Clear All
new posts

  • Repeating segments and populating database

    I'm trying to loop through all the DG1 segments that are send and populate a database field with the Diagnosis Type value. I have searched the forum to get some examples of looping through repeating segments. But I am having trouble getting each DG1 6.1 value into the DB successfully.

    Here is what I am getting:

    DG1Value value in DB: "<DG1.6.1>DA</DG1.6.1><DG1.6.1>DF</DG1.6.1>"
    diagnosisValue value in DB: ""

    var sql = "";
    for each (diagnosis in msg..DG1) {
    var DG1Value = msg['DG1']['DG1.6']['DG1.6.1'].toString();
    var diagnosisValue = diagnosis['DG1']['DG1.6']['DG1.6.1'].toString();
    sql = "insert into testdata values ('" + DG1Value + "')";
    var result = dbConn.executeUpdate(sql);
    Reid Hospital and Healthcare

  • #2
    Re:Repeating segments and populating database

    There is an existing transformer you can download from the File Repository of this website which sounds like it does something very similar to what you want to do:
    "Determine ORC Test Result"
    Description This transformer will check a laboratory result message for OBR segments and determine if all tests have been completed. If each OBR.25 segment is Final ('F') this transformer will put 'F' into the "testResults" variable. It will put 'P' if any OBR.25 segments are set to pending.

    The testResults variable can be used in a destination database with the following syntax:

    INSERT IGNORE INTO laboratory_results (test_results) VALUES (${testResults});

    The total count of OBR segments is also provided in the 'count' variable. Logger statements are included to help in testing.


    • #3
      Re:Repeating segments and populating database

      That's the example i have been trying to replicate.

      This is the code I am currently using:
      DG1Value = msg['DG1']['DG1.6']['DG1.6.1'].text();
      diagnosisValue = diagnosis['DG1.6'].toString();
      diagnosisValue2 = diagnosis['DG1.6'].text();
      This is what the Log Info has:
      DG1Value is: DADF
      diagnosisValue is: <DG1.6><DG1.6.1>DA</DG1.6.1></DG1.6>
      diagnosisValue2 is:

      The DG1Value has both DG1 1.6 fields concatenated together. I need them as separate values in the database.
      Reid Hospital and Healthcare


      • #4
        Re:Repeating segments and populating database

        I found a workaround.

        diagnosis['DG1.6'].toString() was giving me a value of "<DG1.6><DG1.6.1>DA</DG1.6.1></DG1.6>".

        I did a replace on what i didn't want in the DB.

        Here is my code now:
        diagnosisValue = diagnosis['DG1.6'].toString();
        diagnosisValue = diagnosisValue.replace("<DG1.6>", ""«»);
        diagnosisValue = diagnosisValue .replace("<DG1.6.1>", ""«»);
        diagnosisValue = diagnosisValue .replace("</DG1.6.1>", ""«»);
        diagnosisValue = diagnosisValue .replace("</DG1.6>", ""«»);
        Reid Hospital and Healthcare