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

How to dynamically control repeat fields on output template, tmp? (RESOLVED)

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to dynamically control repeat fields on output template, tmp? (RESOLVED)

    I'm using Mirth 3.11.0

    I am converting ORUs to MDMs. I have the template for the MDM message as the following:
    PV1|1||||||^^^|^^^~^^^~^^^~^^^|^^^~^^^~^^^~^^^|||| ||||^^^~^^^~^^^~^^^||||||||||||||||||||||||||||||| ||||^^^~^^^~^^^~^^^|
    TXA|1||||||||^^^~^^^~^^^~^^^||||||||F||||||^^^~^^^ ~^^^~^^^~^^^~^^^~^^^~^^^|

    As you can see, I have multiple components defined on some of the fields. Mostly the Provider fields like PV1.8 and PV1.9 and so on.
    When I attempt to access a tmp iteration that is not shown in the template, it issues an error:
    597: // PV1.9 can be a repeating field, so need to account for that
    598: for (i=0;i<msg['PV1']['PV1.9'].length();i++)
    599: {
    600: tmp['PV1']['PV1.9'][i]['PV1.9.1'] = validate(msg['PV1']['PV1.9'][i]['PV1.9.1'].toString(), '', new Array());
    601: tmp['PV1']['PV1.9'][i]['PV1.9.2'] = validate(msg['PV1']['PV1.9'][i]['PV1.9.2'].toString(), '', new Array());
    602: tmp['PV1']['PV1.9'][i]['PV1.9.3'] = validate(msg['PV1']['PV1.9'][i]['PV1.9.3'].toString(), '', new Array());
    603: tmp['PV1']['PV1.9'][i]['PV1.9.4'] = validate(msg['PV1']['PV1.9'][i]['PV1.9.4'].toString(), '', new Array());
    604: }
    LINE NUMBER: 600
    DETAILS: TypeError: Cannot set property "PV1.9.1" of
    undefined to "1407019037"

    In this case with PV1.9, the source message has 5 providers listed and I only have 4 in my template. It dies on the 5th entry.

    How can I dynamically generate repeats on the template?

    I have code in place that will generate a new OBX when needed. But, I have not found anyone in the forum that is talking about expanding repeating components in a field.
    Any ideas?

    Thanks in advance.
    Last edited by pacmano; 10-16-2021, 05:29 AM.

  • #2
    You have to build them on the fly.

    In your loop you will do something like this (FT1.19 example here)

    var newFT1 = new XML("<FT1.19/>");
    newFT1['FT1.19.1'] = <your array of values whatver they are>.toString()
    tmp['FT1'][<whatever this array index variable is>]['FT1.19'] += newFT1;

    Diridium Technologies, Inc.


    • #3
      Here is my loop code for loading:
      for (i=0;i<msg['PV1']['PV1.52'].length();i++)
      logger.error('PV1.52 entry ' + i + ': ' + msg['PV1']['PV1.52'][i]['PV1.52.1'].toString());
      var newTXA9 = new XML('<TXA.9/>');
      newTXA9['TXA.9.1'] = msg['PV1']['PV1.52'][i]['PV1.52.1'].toString();
      newTXA9['TXA.9.2'] = msg['PV1']['PV1.52'][i]['PV1.52.2'].toString();
      newTXA9['TXA.9.3'] = msg['PV1']['PV1.52'][i]['PV1.52.3'].toString();
      newTXA9['TXA.9.4'] = msg['PV1']['PV1.52'][i]['PV1.52.4'].toString();
      logger.error('TXA9 loaded: ' + newTXA9);
      tmp['TXA'][i]['TXA.9'] += newTXA9;
      logger.error('each entry: ' + newTXA9);

      //tmp['TXA']['TXA.9'][i]['TXA.9.1'] = msg['PV1']['PV1.52'][i]['PV1.52.1'].toString();
      //tmp['TXA']['TXA.9'][i]['TXA.9.2'] = msg['PV1']['PV1.52'][i]['PV1.52.2'].toString();
      //tmp['TXA']['TXA.9'][i]['TXA.9.3'] = msg['PV1']['PV1.52'][i]['PV1.52.3'].toString();
      //tmp['TXA']['TXA.9'][i]['TXA.9.4'] = msg['PV1']['PV1.52'][i]['PV1.52.4'].toString();
      This is what is output in the logger stmts:
      ERROR (transformer:?): TXA9 loaded: <TXA.9><TXA.9.1>123457</TXA.9.1><TXA.9.2>SMITH</TXA.9.2><TXA.9.3>FRED</TXA.9.3><TXA.9.4/></TXA.9>
      ERROR (transformer:?): PV1.52 entry 1: 123457
      ERROR (transformer:?): each entry: <TXA.9><TXA.9.1>123456</TXA.9.1><TXA.9.2>SMITH</TXA.9.2><TXA.9.3>JOE</TXA.9.3><TXA.9.4/></TXA.9>
      ERROR (transformer:?): TXA9 loaded: <TXA.9><TXA.9.1>123456</TXA.9.1><TXA.9.2>SMITH</TXA.9.2><TXA.9.3>JOE</TXA.9.3><TXA.9.4/></TXA.9>
      ERROR (transformer:?): PV1.52 entry 0: 123456

      Here is the error I'm getting (fyi...I have 4 repeat entries in the PV1.52 field)
      756: newTXA9['TXA.9.1'] = msg['PV1']['PV1.52'][i]['PV1.52.1'].toString();
      757: newTXA9['TXA.9.2'] = msg['PV1']['PV1.52'][i]['PV1.52.2'].toString();
      758: newTXA9['TXA.9.3'] = msg['PV1']['PV1.52'][i]['PV1.52.3'].toString();
      759: newTXA9['TXA.9.4'] = msg['PV1']['PV1.52'][i]['PV1.52.4'].toString();
      760: logger.error('TXA9 loaded: ' + newTXA9);
      761: tmp['TXA'][i]['TXA.9'] += newTXA9;
      762: logger.error('each entry: ' + newTXA9);
      763: //tmp['TXA']['TXA.9'][i]['TXA.9.1'] = msg['PV1']['PV1.52'][i]['PV1.52.1'].toString();
      764: //tmp['TXA']['TXA.9'][i]['TXA.9.2'] = msg['PV1']['PV1.52'][i]['PV1.52.2'].toString();
      765: //tmp['TXA']['TXA.9'][i]['TXA.9.3'] = msg['PV1']['PV1.52'][i]['PV1.52.3'].toString();

      LINE NUMBER: 761
      DETAILS: TypeError: Cannot read property "TXA.9" from undefined

      What am I missing?


      • #4
        Post a before and after message. I don’t understand what you are doing.
        Diridium Technologies, Inc.


        • #5
          What I'm wanting to do is to eliminate the need for the defined iterations in the template, such as TXA.9 from ^^^~^^^~^^^~^^^ to just one iteration ^^^.

          Input Message OBR Segment

          PV1|1|O|DS||||123458^SMITH^TIM^^^^^ALL_PP_MASTER|| |||||||||||||||||||||||||||||||||||||||||||123456^ SMITH^JOE^^^^^ALL_PP_MASTER~123457^SMITH^FRED^^^^^ ALL_PP_MASTER~123458^SMITH^TIM^^^^^ALL_PP_MASTER~1 23459^SMITH^ZEEK^^^^^ALL_PP_MASTER|
          OBR|1||991751^ALL_TRANS_C^991751|TN^Endoscopy Report^D4D^GI-ENDO^Transcription^ALL_TRANS_C||202109240841|20210 9240810||||||||||||||||||F||^^^^^|||||123458^SMITH ^TIM^^^^^ALL_PP_MASTER|||||||^|

          Outbound Message Template
          PV1|1||||||^^^|^^^~^^^~^^^~^^^|^^^||||||||^^^~^^^~ ^^^~^^^|||||||||||||||||||||||||||||||||||^^^~^^^~ ^^^~^^^|
          TXA|1||||||||^^^~^^^~^^^~^^^||||||||F||||||^^^~^^^ ~^^^~^^^~^^^~^^^~^^^~^^^|

          Expected output TXA Segment
          TXA|1|Diagnostics||202109240810|||202109240810||12 3456^SMITH^JOE^~123457^SMITH^FRED^~123458^SMITH^TI M^~123459^SMITH^ZEEK^|||991751||||Endoscopy Report|F|||||||
          Last edited by rkMC; 10-13-2021, 07:32 AM.


          • #6
            I probably would not iterate like that if just "moving" providers around.

            e.g. up PV1.7 into PV1.9. You need the renameField function from

            tmp['TXA']['TXA.9'] = renameField(msg['PV1']['PV1.7'], 'TXA.9')

            and so on.
            Last edited by pacmano; 10-14-2021, 02:42 PM.
            Diridium Technologies, Inc.


            • #7
              Pacmano, Thanks for your assistance. This worked very well.
              I now have a small issue. The field I am renaming, PV1.52, has 4 iterations. All of them are "moved" to TXA.9, but each iteration contains 8 components. The receiver of the message only wants the first 4 components. I have the following code in place to cut back to just the first 4 components, but it is not working. Do you see a flaw in the code? I have a version of this code that works nicely applied to the msg. Is the issue related to working with the tmp?
              // map the Originator PV1-52.1-8 to TXA-9.1-8
              tmp['TXA']['TXA.9'] = renameField(msg['PV1']['PV1.52'], 'TXA.9');

              // Loop through TXA.9 to clear out unwanted subcomponents
              for (i=0;i<msg['TXA']['TXA.9'].length();i++)
              // save txa 9 field values to reload later
              var txa9_1 = tmp['TXA']['TXA.9'][i]['TXA.9.1'].toString();
              var txa9_2 = tmp['TXA']['TXA.9'][i]['TXA.9.2'].toString();
              var txa9_3 = tmp['TXA']['TXA.9'][i]['TXA.9.3'].toString();
              var txa9_4 = tmp['TXA']['TXA.9'][i]['TXA.9.4'].toString();
              // remove the subcomponents not wanted on output - per Goshen Physicians
              for each (var txa9 in tmp.TXA['TXA.9'][i]) {
              var keepers = new XMLList();
              for (var k = 1; k <= 4 ; k++) {
              keepers += txa9['TXA.9.' + k];
              // reload values for TXA.9
              tmp['TXA']['TXA.9'][i]['TXA.9.1'] = txa9_1;
              tmp['TXA']['TXA.9'][i]['TXA.9.2'] = txa9_2;
              tmp['TXA']['TXA.9'][i]['TXA.9.3'] = txa9_3;
              tmp['TXA']['TXA.9'][i]['TXA.9.4'] = txa9_4;


              • #8
                tmp['TXA']['TXA.9'] = renameField(msg['PV1']['PV1.52'], 'TXA.9');

                Do check that though, I am sort of half paying attention to stuff today
                Last edited by pacmano; 10-14-2021, 02:42 PM.
                Diridium Technologies, Inc.


                • #9
                  That worked perfectly. Thanks for all your help.