Announcement

Collapse
No announcement yet.

Channel receiving both XML and PDF message Like to bypass transformer

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

  • Channel receiving both XML and PDF message Like to bypass transformer

    Hi, I have one Channel receiving both XML and PDF and like to bypass the transformer that I am using for mapping the XML to HL7 fields. I have created a file extension filter in the source but I am not sure if I can bypass the transformer using router.routeMessage function. is there a better way to do this other then creating a new channel?


    Code:
    logger.info('FileName');
    var FileUtil = new org.apache.commons.io.FilenameUtils;
    var strFileExtenstion = FileUtil.getExtension(sourceMap.get('originalFilename').toString())
    logger.info(strFileExtenstion);
    
    switch(strFileExtenstion + '') {
        case 'pdf':
            logger.info('FileName PDF');
    		router.routeMessage("PDF Destination",${message.raw});
            break;
        case 'xml':
            logger.info('FileName XML');
    		router.routeMessage("HL7 Destination",${message.raw});
            break;
     default:
     logger.info('GRRR');
            break;
    }

  • #2
    I may be completely misunderstanding what you are looking for but this seems to be quite straightforward

    Couple of points to begin with
    1. Correct me if am wrong. As far as I know routing does not work for specific destinations within a channel. Routers exist to route messages to other channels.

    2. You haven't indicated whether your transformer is at the source or destination.

    Here is what I would suggest

    1. Create a channel map variable to detect whether source in pdf or xml
    2. Move the transformer that maps XML to HL7 to the XML Destination and not have it at the source.
    3. Put a filter in PDF destination such that it will work only when the input is PDF, likewise for XML. This way the XML to HL7 transformer will only execute when the input in XML

    Let me know if I haven't understood your requirement accurately.

    Rig

    Comment


    • #3
      Like rigved, I'm not sure I understand 100% either, but I've run into a similar situation. I have a channel that is a File Reader that reads a folder with both .hl7 and .pdf files. I set the source as RAW, then setup two destination connectors. One with a filter to only accept .pdf and the second to only accept .hl7. The files still get moved/deleted in the source like normal regardless of file type, and you can process each as needed. There is also the added benefit that if you (for example) process the .PDF destination first, you can base64-encode the PDF for inclusion into the HL7 that you process second.

      Hope it helps...
      Last edited by jackwhaines; 03-11-2016, 08:52 AM.

      -= 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


      • #4
        I need to name the PDF and HL7 message base off of the value in MSH3. I was thinking that if the source transformer did the XML to HL7 then in the destination transformer I can pull the msh3 and name the HL7 message. I am not sure how to name the PDF any ideas? I been playing around with the globalMap but its not working.

        Comment


        • #5
          I guess it would depend on how you built your channel/channels. If you do it with a single channel with multiple destinations, you can use a normal channelMap. If it goes across multiple channels, you would HAVE to use a globalMap. Decide on how you are going to make your channels work, and then let me know. We'll go from there!

          -= 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


          • #6
            I guess we need some more information here. Am still not certain what you are ultimately looking for.

            Your original question was around bypassing a certain transformer when processing PDF which could be a simple if condition based on whether the extension is pdf or not. Not sure if that is answered yet.

            If I understand correctly, actually based on Jack's response, your pdf and xml inputs are related and that you are looking to embed the pdf as Base64 in your xml. So basically you have two inputs for a single output. Let me know if that is correct.

            In that case I would simply just read the XMLs in the source (using *.xml as filter) and not the PDFs and then have a transformer in the same channel that will read the corresponding PDF using FileUtil as Base64 and embed that data in the outbound. This is assuming that you have a way to match the xml and pdf either using the filename or the content of the xml. You can put some special handling in case the corresponding PDF is not found.

            Within that same transformer or Post Processor you can either delete or move the pdf to some other location based on the same pattern you are following for xml archival or deletion.

            One additional note, you need not always have to use globalMap to pass data among channels. If your channels are channel readers you can pass metadata and read them using source map. Similar concept for http listeners. You can also smartly embed metadata in your message and delete it in the receiving channel after consuming that data.

            Comment


            • #7
              I would like to use single channel with multiple destinations. Below is the code I been testing with. But in the source filter do I need it to send the HL7 or PDF to the correct Destination ?

              HL7 Destination transformer:
              var MSH5 =(msg['MSH']['MSH.5']['MSH.5.1'].toString());
              var FileUtil = new org.apache.commons.io.FilenameUtils;
              var strFileName = FileUtil.getBaseName(sourceMap.get('originalFilena me').toString())
              globalMap.put(strFileName,MSH5)

              PDF Destination transformer:
              var FileUtil = new org.apache.commons.io.FilenameUtils;
              var strFileName = FileUtil.getBaseName(sourceMap.get('originalFilena me').toString())
              var MSH5 = globalMap.get(strFileName)
              logger.info(String.format("MSH 5 %s",MSH5));
              //Need to Change PDF File Name

              Comment


              • #8
                Yes I have two inputs XML and PDF, they both have the same file name just different extensions. The output needs to be two files HL7 and PDF. The HL7 is using the message builder base on values in the XML file. Then there is HL7 message formatting(fixing dates). The HL7 file name needs to be in the format 1_MSH5_Datetimestamp.hl7. For the PDF that will need to match with the HL7 message so its file name will be 1_MSH5_Datetimestamp.pdf

                Comment


                • #9
                  Tell me this, will the PDF always be there when the XML is processed? If so, what I might do is only process the .xml files using the channel (use the filename filter in the source) but then use the transformers to encode, move/delete the PDFs from the folder when the HL7 is processed. Basically, you don't want the channel processing the PDF file like you would the XML. I do this exact scenario in a production environment. Basically, the folder contains both, but the channel only grabs the XML.

                  If it's possible that the PDF will come in AFTER the XML (but it always will eventually) you could use a filter to not process the XML until both files were there.
                  Last edited by jackwhaines; 03-14-2016, 08:08 AM.

                  -= 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


                  • #10
                    Yes the PDF will always be there with the XML processed. But how would you sent the file name of the PDF file name?

                    Comment


                    • #11
                      See if this helps. Might get you close...

                      Code:
                      var fileId = msg['MSH']['MSH.5']['MSH.5.1'].toString();
                      
                      var origPath = "D:/WhereMyFilesAre/";
                      var origFilename = sourceMap.get('originalFilename').toString();
                      
                      var newPath = "D:/WhereMyFilesShouldBe/";
                      var newFilename = fileId + ".pdf";
                      
                      var file1 = new Packages.java.io.File(origPath + origFilename);
                      var file2 = new Packages.java.io.File(newPath + newFilename);
                      
                      file1.renameTo(file2);

                      -= 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


                      • #12
                        Thanks Jake for the help with this one question, how do I set the file name for both the PDF and XML to be the same time stamp?

                        Comment


                        • #13
                          Originally posted by tmcdevitt View Post
                          Thanks Jake for the help with this one question, how do I set the file name for both the PDF and XML to be the same time stamp?
                          The same timestamp in the filename or like the modified time of the file?

                          -= 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


                          • #14
                            Last question and I should be all set. In my testing when I drop the files some times the XML writes faster then the PDF message can you please explain what you mean by using a filter to not process XML until the PDF is in the folder. Is it in the filter I will look in the folder for the PDF and then process if not I will write the XML file again to the input folder?

                            Comment


                            • #15
                              Originally posted by tmcdevitt View Post
                              Last question and I should be all set. In my testing when I drop the files some times the XML writes faster then the PDF message can you please explain what you mean by using a filter to not process XML until the PDF is in the folder. Is it in the filter I will look in the folder for the PDF and then process if not I will write the XML file again to the input folder?
                              Option 1) You could add an age timer to the Source of the channel. There is an option called "File Age (ms)" that if you set to say, 60 seconds, it won't pick up that XML file until the xml is at least 60 seconds old. Plenty of time to get your PDF written.

                              Option 2) If that's not always the case, you could add another filter to the XML processing, to check for the existence of the PDF file and set the message as queued or something until the PDF exists. If it doesn't, keep the message queued and retry every 60 seconds or something.

                              -= 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