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

Problem with multiple OBX segments

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

  • Problem with multiple OBX segments

    I am trying to create multiple OBX segments for an outgoing HL7 message so I looked on this forum for an example of such. I have a debug message written to a file after the following code segment is run in a transformer, so I know that it is not failing on this. Also if I comment this block out, the error does not occur.

    Code:
    var c = 0;
    var o = 0;
    var obx = tmp['OBX'];
    while (typeof msg["line"][c] != "undefined"«») {
    	line = msg["line"][c++];
    	tmp['OBX'][o] = obx;
    	tmp['OBX'][o]['OBX.1']['OBX.1.1'] = c + 1;
    	tmp['OBX'][o]['OBX.2']['OBX.2.1'] = "ST";
    	tmp['OBX'][o]['OBX.3']['OBX.3.1'] = "1:RPT";
    	tmp['OBX'][o]['OBX.3']['OBX.3.2'] = "Radiology Report";
    	tmp['OBX'][o]['OBX.5']['OBX.5.1'] = line;
    	tmp['OBX'][o]['OBX.11']['OBX.11.1'] = "D";
    	o++;
    }
    I also have the following HL7 template in the outbound message area:
    Code:
    MSH|||||||||^|||
    EVN||
    PID|||||^|||||||||||||
    ORC||||||||||||^^^^^^^^^^^^
    OBR||||^||||||||||||^^^^^^^^^^^^||||^^^^^^^^^^^^|^|||||
    OBX|||^||||||||
    OBX|||^||||||||
    I figured that although I don't know how many OBX segments I will need I know that I will have more than 2, is this setup correctly?

    This is the error that I get:

    Code:
    ERROR-300: Transformer error
    ERROR MESSAGE:	Error evaluating transformer
    com.webreach.mirth.model.converters.SerializerException: java.lang.ArrayIndexOutOfBoundsException: 2
    	at com.webreach.mirth.model.converters.ER7Serializer.fromXML(ER7Serializer.java:168)
    	at com.webreach.mirth.model.converters.ER7Serializer.fromXML(ER7Serializer.java:50)
    	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.evaluateTransformerScript(JavaScriptTransformer.java:406)
    	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:286)
    	at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
    	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
    	at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251)
    	at com.webreach.mirth.server.controllers.MessageObjectController.getMessageObjectFromEvent(MessageObjectController.java:482)
    	at com.webreach.mirth.connectors.file.FileMessageDispatcher.doDispatch(FileMessageDispatcher.java:79)
    	at com.webreach.mirth.connectors.file.FileMessageDispatcher.doSend(FileMessageDispatcher.java:213)
    	at org.mule.providers.AbstractMessageDispatcher.send(AbstractMessageDispatcher.java:166)
    	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:191)
    	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:130)
    	at org.mule.routing.outbound.AbstractOutboundRouter.send(AbstractOutboundRouter.java:85)
    	at org.mule.routing.outbound.FilteringMulticastingRouter.route(FilteringMulticastingRouter.java:89)
    	at org.mule.routing.outbound.OutboundMessageRouter$1.doInTransaction(OutboundMessageRouter.java:78)
    	at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:48)
    	at org.mule.routing.outbound.OutboundMessageRouter.route(OutboundMessageRouter.java:82)
    	at org.mule.impl.model.DefaultMuleProxy.onCall(DefaultMuleProxy.java:247)
    	at org.mule.impl.model.seda.SedaComponent.doSend(SedaComponent.java:209)
    	at org.mule.impl.model.AbstractComponent.sendEvent(AbstractComponent.java:277)
    	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:201)
    	at org.mule.routing.inbound.InboundMessageRouter.send(InboundMessageRouter.java:161)
    	at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:128)
    	at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:492)
    	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:271)
    	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:230)
    	at com.webreach.mirth.connectors.file.FileMessageReceiver.processFile(FileMessageReceiver.java:223)
    	at com.webreach.mirth.connectors.file.FileMessageReceiver.poll(FileMessageReceiver.java:130)
    	at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:118)
    	at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
    	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
    	at com.webreach.mirth.model.converters.ER7XMLHandler.startElement(ER7XMLHandler.java:130)
    	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at com.webreach.mirth.model.converters.ER7Serializer.fromXML(ER7Serializer.java:163)
    	... 33 more
    Post edited by: dblodgett, at: 01/10/2008 07:58

  • #2
    Re:Problem with multiple OBX segments

    I'm not a javascript expert, so someone correct me if I'm incorrect, but see if this helps.

    Change this line: "line = msg["line"][c++];"
    To this: "line = msg["line"][c];"

    You are getting the next array value. If there are 2 values in a zero based array, and c = 1 (the second index), c++ gives you the array index of 2, which does not exist. I believe this is why you are getting the ArrayIndexOutOfBoundsException: 2 error.

    Code:
    var c = 0;
    var o = 0;
    var obx = tmp['OBX'];
    while (typeof msg["line"][c] != "undefined"«») {
        line = msg["line"][c++];   <-- I think your problem is here
        tmp['OBX'][o] = obx;
        tmp['OBX'][o]['OBX.1']['OBX.1.1'] = c + 1;
        tmp['OBX'][o]['OBX.2']['OBX.2.1'] = "ST";
        tmp['OBX'][o]['OBX.3']['OBX.3.1'] = "1:RPT";
        tmp['OBX'][o]['OBX.3']['OBX.3.2'] = "Radiology Report";
        tmp['OBX'][o]['OBX.5']['OBX.5.1'] = line;
        tmp['OBX'][o]['OBX.11']['OBX.11.1'] = "D";
        o++;
    }
    Post edited by: afterdark23, at: 01/10/2008 10:33
    Reid Hospital and Healthcare

    Comment


    • #3
      Re:Problem with multiple OBX segments

      Thanks for your reply, I made the change you suggested and it did not fix the issue. I think the problem is when Mirth takes the tmp variable and starts to convert it to the HL7. The reason I say this is because I have a write to file statement at the end of the transformer and this writes the file successfully. As such I don't think my code is syntactically incorrect, but I believe that I am doing something wrong as far as Mirth is concerned.

      Comment


      • #4
        Re:Problem with multiple OBX segments

        I'm not sure if this will help, but I've been researching the same scenario of mapping data outbound into multiple repeating segments. I found this topic to be helpful.

        Re:Generating multiple segments in outbound messages

        There are some samples of code here that may help you.

        Kerry

        Comment


        • #5
          Re:Problem with multiple OBX segments

          Perhaps this one could work

          Code:
          var c = 0;
          
          
          for(c=0;msg["line"].length()<c;c++) {
              if (c>0) tmp['OBX'][c] = tmp['OBX'][o-1];
              tmp['OBX'][c]['OBX.1']['OBX.1.1'] = c + 1;
              tmp['OBX'][c]['OBX.2']['OBX.2.1'] = "ST";
              tmp['OBX'][c]['OBX.3']['OBX.3.1'] = "1:RPT";
              tmp['OBX'][c]['OBX.3']['OBX.3.2'] = "Radiology Report";
              tmp['OBX'][c]['OBX.5']['OBX.5.1'] = line;
              tmp['OBX'][c]['OBX.11']['OBX.11.1'] = "D";
          }

          Comment


          • #6
            Re:Problem with multiple OBX segments

            Thanks everyone for responding, I found out why it was not working correctly. For some reason the msg['line'] was returning a the line element surrounding the text. So the output XML looked like:

            Code:
            <OBX.5.1>
              <line>text</line>
            </OBX.5.1>
            So I changed my code to make it work. Notice the regular expression, why that works, I have no idea, because it should be selecting all characters, but its not selecting the element tags.

            Code:
            var c = 0;
            var o = 0;
            var obx = tmp['OBX'];
            regex = new RegExp("(.*)", ""«»);
            while (typeof msg["line"][c] != "undefined"«») {
            	var line = regex.exec(msg["line"][c]);
            	tmp['OBX'][o] = obx;
            	tmp['OBX'][o]['OBX.1']['OBX.1.1'] = c;
            	tmp['OBX'][o]['OBX.2']['OBX.2.1'] = "ST";
            	tmp['OBX'][o]['OBX.3']['OBX.3.1'] = "1:RPT";
            	tmp['OBX'][o]['OBX.3']['OBX.3.2'] = "Radiology Report";
            	tmp['OBX'][o]['OBX.5']['OBX.5.1'] = line[1];
            	o++;
            	c++;
            }

            Comment


            • #7
              Re:Problem with multiple OBX segments

              1.7 includes a new JS function called "createSegment" I'm going to try to get a tutorial online that explains how to use createSegment/appendSegment but essentially you can add a new segment like this:

              (warning: this is off the top of my head and might have small mistakes - especially the re-assignment of "insertLocation")
              Code:
                 var insertLocation = tmp['OBR']; //We start one segment ABOVE where we want to add our new segments
                 var obx = tmp['OBX']; //grab the template into a variable
                 for (var i = 0; i < 10; i++){
                     //modify 'obx' directly here
                     obx['OBX.1']['OBX.1.1'] = "TEST"; //set all the values we will need against the var we choose above
                     insertLocation+=obx; //this actually inserts the segment into our template
                     insertLocation = obx; //update our current insert location to our last modified segment
                  }
              This will work in all versions of Mirth, but 1.7 includes a helper function that will let you do the insertion easier.

              Post edited by: chrisl, at: 01/10/2008 15:35
              Chris Lang

              Comment


              • #8
                Re:Problem with multiple OBX segments

                Hello chrisl,

                I wanted to ask you if the tutorial about the createSegment-functions is already somewhere on the site. Thanks

                Svetlomir

                Comment


                • #9
                  Re:Problem with multiple OBX segments

                  Hi Svetlomir!

                  If you discover something about createSegment Function let me know, I'm also running after that.

                  Also, I don't know if you've been throught that already, but I'm trying to control the result set after execute a SELECT statement. Like a looping (not while db.eof), something like this.

                  Thanks.

                  Alexander

                  Post edited by: Alexander, at: 05/11/2008 16:31

                  Comment


                  • #10
                    Re:Problem with multiple OBX segments

                    Hi Chris!

                    Have you posted somewhere the example on how to use createSegment functions?

                    Also, can you post an example about how to control looping from the SELECT result set ?

                    Thanks a lot.

                    Alexander

                    Comment


                    • #11
                      Re:Problem with multiple OBX segments

                      Hello Alexander,

                      I think I got a solution. Someone correkt me if he/she has a more simple solution please. Here is my code:

                      My Template:
                      Code:
                      MSH|^~&||||||DFT^P03||P|2.4|
                      
                      EVN|P03|null
                      
                      PID|||||^|||||||||||||||||||||||||||||||||
                      
                      PV1||||||||||||||||||||||||||||||||||||||||||||||||||||
                      
                      FT1|4|||20080428232142+0000|||05211^^Ebm|||1|||||||||||||117



                      My transformer: (Thanks to this thread: http://www.mirthproject.org/index.ph...1&catid=2#5751 for creating it)

                      Code:
                      ... (here I'm writing my quiery)
                      
                      var dbConn = DatabaseConnectionFactory.createDatabaseConnection(driver, address,username, password);
                      var result = dbConn.executeCachedQuery(sql); 
                      
                      result.next(); //going to the first row or the resultset
                      
                      ... (here I'm mapping my  PID, PV1 on so on segments)
                      
                      var ft1=createSegment('FT1'); //getting a sample FT1-segment from the template, we need this in order to create more FT1-segments as a copy from the first one
                      var count = 0; //Variable for indexing
                      var setID = 1; //Variable for putting some data on the message
                      
                      
                      count++; 
                      setID++; 
                      
                      //Here I loop through the resultset:
                      while (result.next()) {
                      
                      // Create next FT1 segments for Access Consent
                      createSegmentAfter('PV1', tmp['FT1']) //the segment should be created after PV1 and should be an FT1-segment
                      tmp['FT1'][count] = ft1; //copying from our template segment we created earlier 
                      tmp['FT1'][count]['FT1.1']['FT1.1.1'] = setID.toString(); //modifying our newly created segment...
                      tmp['FT1'][count]['FT1.2']['FT1.2.1'] = "110";
                      tmp['FT1'][count]['FT1.5']['FT1.5.1'] = "Access Consent";
                      count++;
                      setID++;
                      }
                      
                      delete tmp['FT1'][0]; //since we don't want our template segment to occur in our message we can delete it 
                      
                      dbConn.close(); //closing the database
                      The message I got:

                      Code:
                      ...
                      PID|1234||||^|||||||||||||||||||||||||||||||||
                      PV1|||||||||||||||||||F1234|||||||||||||||||||||||||||||||17||
                      FT1|2|110|||Access Consent
                      FT1|3|110|||Access Consent
                      FT1|4|110|||Access Consent
                      That was it.

                      I hope that helps you. Tell me if it works or if you found a better solution, especially without creating a template segment. Thank you!

                      About:looping through a dataset here is a good example:
                      http://www.mirthproject.org/index.ph...filter_example

                      I thing you should replace result.next() with a while(result.next())

                      You can get the needed values from the resultset this way:

                      Code:
                      tmp['PID']['PID.1']=result.getString("idNumber").trim();
                      where idNumber should be a column in the resultset

                      Post edited by: Svetlomir Kasabov, at: 05/12/2008 00:52

                      Post edited by: Svetlomir Kasabov, at: 05/12/2008 01:10

                      Comment


                      • #12
                        Re:Problem with multiple OBX segments



                        Post edited by: Alexander, at: 05/14/2008 00:28

                        Comment

                        Working...
                        X