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

Binary File Copy needed badly

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

  • Binary File Copy needed badly

    Does anyone know of code I can use to simply copy a PDF from one location to another. This is rediculous that it is such a hassle.

    I used the command

    FileUtil.write(PDFDestPath + PDFName, true, FileUtil.read(PDFSrcPath + PDFName));
    true or false, doesn't matter, it's copying the file as ASCII. The destination PDF
    is blank. If found other FileCopys in Java and they won't work for some reason.
    Mike Caldwell
    Alliance HealthCare - GE VAR
    Rocklin, CA
    Centricity PM/EMR Support - Developer - Network Engineer

  • #2
    Re:Binary File Copy needed badly

    Why are you doing it in JS instead of having a file reader source and a file writer destination?

    If the reader/writer combo won't work, it might not handle binary, then you can use the standard Java file classes from a JS step.
    Jon Bartels

    Zen is hiring!!!!
    http://consultzen.com/careers/
    Talented healthcare IT professionals wanted. Engineers to sales to management.
    Good benefits, great working environment, genuinely interesting work.

    Comment


    • #3
      Re:Binary File Copy needed badly

      I would BUT, in this day and age it has been several clients sending us PDF/XML. The PDF's all gather up in 1 directory, after only 10,000 (thats a small number) of them in 1 directory, if you open the directory in windows its really slow. SO, I have the Java read in the XML Convert to MDM files, update the PDF link in the MDM OBX 5. Then create a directory as YEAR\YEARMONTH, move the PDF to YEAR\YEARMMONTH rerferenced in the OBX 5, all in a single channel, clean. Basically I need a replacement for a filecopy routine that can do binary? how many Java programmers does it take to copy a binary file ;-) What a joke... I do love this Mirth program..

      // THIS IS WHAT I NEED REPLACED FOR BINARY COPIES
      FileUtil.write(PDFDestPath + PDFName, false, FileUtil.read(PDFSrcPath + PDFName));

      At this time I am now tring a second channel called 'Dynamically CreateDirs Copy Cardio PDF' with a destination path (Not sure you can do this? still testing..

      D:/CPS_2006_Staging/CPS_2006_BioZ/BIOZ_PDFS/${date.get('yyyy')}/${date.get('yyyyM')}

      and source Xformer on this channel so it doesnt error with Path don't exist:


      // Set Year(Yr) and YearMonth(YrMnth) variables
      var YrMnth = DateUtil.getCurrentDate("yyyyMM");
      var Yr = DateUtil.getCurrentDate("yyyy");

      // Set Source and Dest Path
      var PDFSrcPath = "//" + ServerName + "//CPS_2006_BioZ//PDF//";
      var PDFDestPath = "//" + ServerName + "//CPS_2006_BioZ//BIOZ_PDFS//" + Yr + "//" + YrMnth + "//";
      channelMap.put('PDFSrcPath',PDFSrcPath);
      channelMap.put('PDFDestPath',PDFDestPath);

      // Make needed directories for my PDF destination: YEARMONTH (200808)
      // This is done to prevent a single directory having around 80,000+ files
      // which isnt fun when you try to open the folder in Windows
      //
      var NewFolder = PDFDestPath ;
      var jiofolder = new java.io.File(NewFolder);
      var Success = jiofolder.mkdirs();
      channelMap.put('NewDirLoc(PDFDestPath)',NewFolder) ;
      channelMap.put('CreatedNewDir?',Success);

      // Success = True directories created Else False they existed
      if (Success)
      {
      // Click DASHBOARD, Double click CHANNEL (CHANNEL MESSAGES)
      // Select A ROW, Click on Mapper below to see the following
      // logger.info Messages
      logger.info("Directory Created : " + NewFolder);
      }
      else
      {
      // Success = False directories existed
      if(jiofolder.isDirectory())
      {
      // Click DASHBOARD then look a bottom at SERVER LOG
      // this is where logger.error writes to
      logger.error("logger.error - Directory Existed!");
      }
      }
      Mike Caldwell
      Alliance HealthCare - GE VAR
      Rocklin, CA
      Centricity PM/EMR Support - Developer - Network Engineer

      Comment


      • #4
        Re:Binary File Copy needed badly

        I had a quick scrounge through the FileUtil class* thinking maybe there was a built-in copy routine. No such luck although it'd be dead nuts simple to write one and send in a patch.

        Since you're copying binary files, I think you may want to be using the readBytes methodsinstead of plain read which is dealing with Strings instead of raw Bytes.

        I haven't tested this, but it should work:
        Code:
        FileUtil.write(dest_file, false, FileUtil.readBytes(src_file));
        * - http://www.mirthproject.org/fisheye/...l.java?r=trunk

        PS - Regarding the number of Java dev's to copy a file: http://www.zazzle.com/java_programme...74910364957006

        Post edited by: jbartels, at: 10/03/2008 11:03
        Jon Bartels

        Zen is hiring!!!!
        http://consultzen.com/careers/
        Talented healthcare IT professionals wanted. Engineers to sales to management.
        Good benefits, great working environment, genuinely interesting work.

        Comment


        • #5
          Re:Binary File Copy needed badly

          Why are you doing it in JS instead of having a file reader source and a file writer destination?

          If the reader/writer combo won't work, it might not handle binary, then you can use the standard Java file classes from a JS step.
          I would LOVE to see a generic text/binary reader/writer. That would blow Mirth wide open.

          We are in a situation now that requires us to retrieve a non-xml non-hl7 non-X12 non-EDI non-NCPDP non-DICOM text and/or binary file and send to a service provider. I am trying to keep everything in Mirth rather than having to use external services to do this.

          We don't have the expertise on hand (or time) to develop a plug in. Not sure where this leaves us. Any suggestions?

          -CF

          Comment


          • #6
            Re:Binary File Copy needed badly

            OK. I got really bored* this evening and tossed a channel together that does binary file copy.

            Without more details it should work for chronofish.

            Mike, I think you'd be able to get similar functionality to your JS if you use the ${DATE} variable. You would certainly get a new path for each day, I'm not sure if you're after keeping the file count in a directory down or if you have specific requirements to mesh up with another app.

            Please note this was done in 1.8.


            *really, really, really bored Binary_File_Copy.xml (4228 bytes)

            Post edited by: jbartels, at: 10/08/2008 18:55
            Jon Bartels

            Zen is hiring!!!!
            http://consultzen.com/careers/
            Talented healthcare IT professionals wanted. Engineers to sales to management.
            Good benefits, great working environment, genuinely interesting work.

            Comment


            • #7
              Re:Binary File Copy needed badly

              I got really bored* this evening and tossed a channel together that does binary file copy.



              Without more details it should work for chronofish.

              Thank you so much for taking the time to do this. We've gotten this far already however. The problem is that Mirth defaults the "incoming data" under the summary tab to "HL7 v2.x". And this screws with the formatting even though we are asking for the "raw" data.


              Please note this was done in 1.8.
              Maybe this is the crux of the problem. We are running on a January 8th 1.7 build. Are there more incoming data options in 1.8? (And is the 1.8 available for general consumption?)

              To add complexity to the problem, we are reading from an SFTP server - not the local file system.

              Thanks again for your help - very much appreciated even if it only confirms that our approach was correct.

              Comment


              • #8
                File Transfer the simple way?

                I tried the file transfer channel provided above. It will read and save a copy of a PDF no problem. Then I put in a empty JavaScript transformer step on the destination and it fails with:
                Code:
                function validate(mapping, defaultValue, replacement) {var result = mapping;if~~~
                TypeError: The content of elements must consist of well-formed character data or markup.
                I have a file drop, one HL7 formatted txt file with a PDF file name stored in OBX.5.1 and then the PDF itself, and I can pick up the HL7, move the PDF, and send the HL7 using a LLP destination and a javascript transformer step to move the file something like:
                Code:
                var origFileName = msg['OBX']['OBX.5']['OBX.5.1'].toString();
                var sourceFolder = "/temp/GMEDtest/";
                var destFolder = "/temp/GMEDtest/test/";
                var sourceFile = new java.io.File(sourceFolder + origFileName);
                
                if (sourceFile.exists()) {
                
                	FileUtil.write(destFolder + origFileName, false , FileUtil.readBytes(sourceFolder + origFileName));
                	FileUtil.deleteFile(sourceFile);
                
                } else {
                
                	logger.error('Source File ' + sourceFolder + origFileName + ' does not exist');
                	FileUtil.write(sourceFolder + 'error_' + $('originalFilename') + '.txt', false, messageObject.getRawData());
                }
                Is there a better way to do that?
                .

                Comment


                • #9
                  Built in error control

                  It still processed the HL7 when the PDF move failed. I found the built in error control worked better cause it stopped the message process exactly where the error occured which prevented the HL7 from being sent. Also moved my PDF moving to the Source Transformer

                  Code:
                  // set directories here
                  //*********************************************************************
                   //I'm pulling the sourceFolder from this Channel's Source Connector directory setting
                   //Can't get destination as there is no file out destination
                   var sourceFolder = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getSourceConnector().getProperties().getProperty('host');
                  	//var sourceFolder = "/temp/MEDtest/";
                   var destFolder = "/temp/MEDtest/test/";
                  
                  
                  // get file name and create file objects for operations
                  //*********************************************************************
                   var pdfFileName = msg['OBX']['OBX.5']['OBX.5.1'].toString();
                   var sourceFile = new java.io.File(sourceFolder + pdfFileName);
                   var sourceHL7File = new java.io.File(sourceFolder + $('originalFilename'));
                  
                  
                  
                  
                  //*********************************************************************
                  // if source or dest doesn't not exist, msg process stops with error
                  //*********************************************************************
                   FileUtil.write(destFolder + pdfFileName, false , FileUtil.readBytes(sourceFolder + pdfFileName));
                  
                  
                  
                  
                  
                   //if we got this far then the move must have been successful
                   FileUtil.deleteFile(sourceFile);
                   FileUtil.deleteFile(sourceHL7File);
                  
                   //log some info in the channel maps
                   channelMap.put('MovedFileTo', destFolder + pdfFileName);

                  Comment


                  • #10
                    I just want to say that this works very well. a simple solution. Thank you

                    FileUtil.write(targetfileName, false, FileUtil.readBytes(sourcefileName));

                    Comment

                    Working...
                    X