Announcement

Collapse
No announcement yet.

Unzip Messages in Source and pass it files to destination

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

  • Unzip Messages in Source and pass it files to destination

    Hi, There anyway I can Unzip Messages in Source and pass each files to destination in one channel. I can do it in two channels but I like to keep it all in one
    Last edited by tmcdevitt; 03-14-2016, 09:26 AM.

  • #2
    What files are in the zip?

    -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
    -= [email protected]
    -= Mirth Connect (Advanced)-certified
    -= Gold member of HL7.org
    -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

    Comment


    • #3
      Just HL7 messages

      Comment


      • #4
        If you want to keep it in one channel, I would create a File Reader to read the ZIP. Destination 1 would be to open the zip and foreach file in the zip, use router.route to send the contents of each HL7 back to the same channel. Destination 1 would have a filter to only process .zip files. Destination 2 would be the HL7 processing, with a filter that only accepts HL7 files. Hypothetical, but should work... Two channels might be easier. =)

        -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
        -= [email protected]
        -= Mirth Connect (Advanced)-certified
        -= Gold member of HL7.org
        -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

        Comment


        • #5
          Is this the correct logic for the unzipping and sending the HL7 back to the same channel.

          var strBase64Data = connectorMessage.getRawData();
          var decodedBytes = FileUtil.decode(strBase64Data);

          // process all zipped files
          var is = new java.io.ByteArrayInputStream(decodedBytes);
          var zis = new java.util.zip.ZipInputStream(is);

          var entry;
          while((entry = zis.getNextEntry()) != null) {

          // save file
          var count;
          var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte .TYPE, BUFFER);

          // read byte content from zipped file
          while ((count = zis.read(buffer, 0, BUFFER)) != -1) {


          router.routeMessageByChannelId('bd8b83be-6d3d-4b4e-aab2-63aae318d2ed', buffer, true);

          }

          fos.close();
          }
          zis.close();

          Comment


          • #6
            I didn't load the code into my engine, but the logic looks sound! Try it, and if you get stuck, let me know!

            -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
            -= [email protected]
            -= Mirth Connect (Advanced)-certified
            -= Gold member of HL7.org
            -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

            Comment


            • #7
              I am not getting any .HL7 messages into the HL7 Message destination. do I have the correct syntax for router.routeMessageByChannelId should there be a file name?

              Code:
              var strBase64Data = connectorMessage.getRawData();
              var decodedBytes = FileUtil.decode(strBase64Data);
              
              
              var is = new java.io.ByteArrayInputStream(decodedBytes);
              var zis = new java.util.zip.ZipInputStream(is);
              
              var entry;
              while((entry = zis.getNextEntry()) != null) 
              	{
              	var count;
              	var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte .TYPE, BUFFER);
              		while ((count = zis.read(buffer, 0, BUFFER)) != -1) 
              		{
              			router.routeMessageByChannelId('bd8b83be-6d3d-4b4e-aab2-63aae318d2ed', buffer, true); 
              		}
              	}
              zis.close();

              Comment


              • #8
                The syntax is:

                router.routeMessageByChannelId('channelId', 'message');

                where channelId = the channelId (I think you have this)

                and

                message is the TEXT content of the message... I think that may be your problem. Looks like you may be pulling the binary file data.

                -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
                -= [email protected]
                -= Mirth Connect (Advanced)-certified
                -= Gold member of HL7.org
                -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

                Comment


                • #9
                  I dont think i am getting that far, my is.count is undefined I should get the some number

                  var strBase64Data = connectorMessage.getEncodedData();
                  var decodedBytes = FileUtil.decode(strBase64Data);
                  logger.info('Unzip Message');
                  var is = new java.io.ByteArrayInputStream(decodedBytes);
                  var zis = new java.util.zip.ZipInputStream(is);
                  logger.info(is.count);

                  Comment


                  • #10
                    I'm not used to zips in Mirth/Java, so you may have to Google that one. If you can't get it, let me know and I'll dig into it.

                    -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
                    -= [email protected]
                    -= Mirth Connect (Advanced)-certified
                    -= Gold member of HL7.org
                    -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

                    Comment


                    • #11
                      I am getting two errors now.

                      [2016-03-14 18:39:57,305] ERROR (com.mirth.connect.connectors.file.FileReceiver:19 2): Source connector is currently stopped for channel Source unZip (8226abc6-7166-49a2-86cd-8b1be30e1d12).
                      com.mirth.connect.donkey.server.channel.ChannelExc eption

                      [2016-03-14 18:39:57,302] ERROR (com.mirth.connect.server.userutil.VMRouter:124): The routeMessageByChannelId(channelId, message, useQueue) method is deprecated and will soon be removed. Please use routeMessageByChannelId(channelId, message) instead. The useQueue parameter will not be used. If you want the downstream channel to queue its message and return immediately upon receipt, enable the source queue on the source connector.

                      Code:
                      var strBase64Data = connectorMessage.getRawData();
                      var decodedBytes = FileUtil.decode(strBase64Data);
                      logger.info('Unzip Message');
                      var is = new java.io.ByteArrayInputStream(decodedBytes);
                      var zis = new java.util.zip.ZipInputStream(is);
                      logger.info(is.count);
                      var entries = 0;
                      var BUFFER = 512;
                      logger.info(zis.getNextEntry());
                      	while ((entry = zis.getNextEntry()) != null) 
                      	{
                      	logger.info(entry);
                      	logger.info('In Main While Loop');
                      	var count;
                      	var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte .TYPE, BUFFER);
                      		while ((count = zis.read(buffer, 0, BUFFER)) != -1) 
                      		{
                      			logger.info('In sub While Loop');
                      			router.routeMessageByChannelId('8226abc6-7166-49a2-86cd-8b1be30e1d12', buffer, true); 
                      		}
                      	}
                      zis.close();

                      Comment


                      • #12
                        1) Is your channel Deployed and Started?

                        2) remove the , true in

                        Code:
                        router.routeMessageByChannelId('8226abc6-7166-49a2-86cd-8b1be30e1d12', buffer, true);

                        -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
                        -= [email protected]
                        -= Mirth Connect (Advanced)-certified
                        -= Gold member of HL7.org
                        -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

                        Comment


                        • #13
                          Yes the channel is Deployed and Started and I removed the true but I am getting the same error messages.

                          Comment


                          • #14
                            its coming from this line of code:
                            router.routeMessageByChannelId('8226abc6-7166-49a2-86cd-8b1be30e1d12', buffer ); Do I need to send the message name?

                            Comment


                            • #15
                              No, but you need to make sure "buffer" contains the textual HL7 and not a binary file (if it's expecting HL7)

                              Maybe even try setting var buffer = "[insert generic HL7 text here]" just before the route just to see if it works sending generic HL7 text.

                              -= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
                              -= [email protected]
                              -= Mirth Connect (Advanced)-certified
                              -= Gold member of HL7.org
                              -= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines

                              Comment

                              Working...
                              X