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

File and Directory commands in Java

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

  • File and Directory commands in Java

    While in the transformer using Javascript what are the secrets to copying a file?
    How can you check if a file or Directory exists? (unc or dos paths)
    How can you create Directories?
    Is this possible?
    Mike Caldwell
    Alliance HealthCare - GE VAR
    Rocklin, CA
    Centricity PM/EMR Support - Developer - Network Engineer

  • #2
    Re:File and Directory commands in Java

    Hi Mike,

    You can use the regular java file commands:
    http://java.sun.com/j2se/1.4.2/docs/...a/io/File.html

    This is how you would read in a file (or create a new one):

    var file = new java.io.File('filenameOrDirectory');

    the rest is just java. Here is what I got from google:
    http://www.java2s.com/Code/Java/File...CopyinJava.htm

    Remember that you will need to use the full class name when you use a java class.
    Daniel Svanstedt
    Software Engineer
    Mirth Corporation

    Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
    Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

    Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

    Comment


    • #3
      Re:File and Directory commands in Java

      Thanks.
      First, still not sure how you apply the java class items as they have no examples of the commands like isDirectory. Do I use java.io.file.isDirectory? Tried it and exists, didnt do anything.

      I tried about 10 different variations of the example you gave me, dug around google, can't believe it is this hard to just to check if a directory exists, if not create it.

      var YearMonth = DateUtil.getCurrentDate("yyyyMM");
      // Create PDF External Path
      var Folder = "C:\\TEMP\\LABS_PDF\" + YearMonth ;
      // Letest test
      var file = new java.io.File("C:/TEMP/LABS_PDF");
      file.mkdir(yearmonth);

      You said "use the full class name when you use a java class" Does this mean I have to use java.xxx.xxx?

      again thanks, I am just frustrated as an old VB programmer and other languages, I like this Java stuff and want to get better at it.
      Mike Caldwell
      Alliance HealthCare - GE VAR
      Rocklin, CA
      Centricity PM/EMR Support - Developer - Network Engineer

      Comment


      • #4
        Re:File and Directory commands in Java

        Dup message.

        Post edited by: M56969, at: 06/29/2008 00:17
        Mike Caldwell
        Alliance HealthCare - GE VAR
        Rocklin, CA
        Centricity PM/EMR Support - Developer - Network Engineer

        Comment


        • #5
          Re:File and Directory commands in Java

          Hi Mike,

          Yes, you can use isDirectory to check if the java.io.File object is a directory or not.

          Here is some example code how to create a directory (actually multiple directories) and to check if is a directory:

          var YearMonth = DateUtil.getCurrentDate("yyyyMM");
          var folder = "C:/TEMP2/LABS_PDF/" +YearMonth;
          var file = new java.io.File(folder);


          // make multiple directories
          var success = file.mkdirs();

          if (success) {
          logger.error("Directories: " + folder + " created");
          }
          if(file.isDirectory()){
          logger.error("yes this is a directory");
          }
          Daniel Svanstedt
          Software Engineer
          Mirth Corporation

          Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
          Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

          Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

          Comment


          • #6
            Re:File and Directory commands in Java

            I will give that a try right now, THANKS so much. So one last item. How can I copy of move the PDF to the directories in the same transformer. THereby skipping a second channel and ensuring the path is available to the PDF to move or copy it to?
            Mike Caldwell
            Alliance HealthCare - GE VAR
            Rocklin, CA
            Centricity PM/EMR Support - Developer - Network Engineer

            Comment


            • #7
              Re:File and Directory commands in Java

              Yee Haa .. SO I got this far and the directory is being created, as I said I just need to do a MOVE on the PDF now? Any Examples on that? Where does the logger.error("xxx") messages go to? Thanks

              // MTC 06272007
              // Update MDM File - Create folder for PDF if they dont exist
              // then Copy PDF to correct folder with UNC Link in MDM

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

              // Update the OBX.5[1] segment with UNC + TXA.16
              var unc = "\\MLT001" + Yr + "" + YrMnth;
              if (msg['OBX']['OBX.3'][1] = "IMAGE_REF")
              {
              msg['OBX']['OBX.5'][1] = unc + "" + msg['TXA']['TXA.16']['TXA.16.1'].toString();
              }

              // make multiple directories
              var folder = "D://LABS_PDF//" + Yr + "//" + YrMnth;
              var file = new java.io.File(folder);
              var success = file.mkdirs();
              // success = true directories created else they existed
              if (success) {
              logger.error("Directories: " + folder + " created");
              } // success = false directories existed
              if(file.isDirectory()){
              logger.error("yes this is a directory");
              }

              // COPY PDF FILE Code Here!???
              //

              Post edited by: M56969, at: 06/30/2008 13:36
              Mike Caldwell
              Alliance HealthCare - GE VAR
              Rocklin, CA
              Centricity PM/EMR Support - Developer - Network Engineer

              Comment


              • #8
                Re:File and Directory commands in Java

                Never mind on the logger.error question, I see them, that is cool ...

                >>> Where do the logger.error("xxx") messages go to?
                Mike Caldwell
                Alliance HealthCare - GE VAR
                Rocklin, CA
                Centricity PM/EMR Support - Developer - Network Engineer

                Comment


                • #9
                  Re:File and Directory commands in Java

                  Where is the pdf coming from? Is it from another file?

                  If it is, you could do something like this:

                  FileUtil.write(folder + "pdffile.pdf", false, FileUtil.read('c:\pdffile.pdf'));
                  Daniel Svanstedt
                  Software Engineer
                  Mirth Corporation

                  Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
                  Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

                  Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

                  Comment


                  • #10
                    Re:File and Directory commands in Java

                    I included the variables and I am copying PDF's from one location to another, I would like to issue an *.PDF versus a filename. It is creating directories now, but errors when the copy part is executed, this is what I have tried now:

                    // COPY PDF FILE Code Here!???
                    var srcpath = "C:\TEMP\IN";
                    var destpath = "D:\LABS_PDF" + Yr + "" + YrMnth;
                    var srcmsg = msg['TXA']['TXA.16']['TXA.16.1'].toString();
                    logger.error("PDF Files Copied From " + srcpath + "" + srcmsg + " -to- " + destpath + "" + srcmsg);
                    FileUtil.write(destpath + "" + srcmsg, false, FileUtil.read(srcpath + "" + srcmsg));

                    I thought I had it working at one oint with this type of code:
                    var myObject, f;
                    myObject = new ActiveXObject("Scripting.FileSystemObject");
                    f = myObject.file.copy("c:\test.txt", "c:\mytest.txt");
                    but it doesnt seem to work now. Very Close I can smell it ;-)
                    I get this:
                    LINE NUMBER:
                    35
                    DETAILS:
                    ReferenceError: "ActiveXObject" is not defined

                    In the end, one channel will then handle both the *.ht and *.pdf files.

                    Post edited by: M56969, at: 06/30/2008 17:28
                    Mike Caldwell
                    Alliance HealthCare - GE VAR
                    Rocklin, CA
                    Centricity PM/EMR Support - Developer - Network Engineer

                    Comment


                    • #11
                      Re:File and Directory commands in Java

                      Did anyone find a resolution to this? I am getting the same "ActiveXObject" is not defined error.

                      Comment


                      • #12
                        Re:File and Directory commands in Java

                        I never did figure out the activeX error, but I did figure out how to delete a file (which is what my actual goal was).


                        Code:
                        var DeleteThisFile = Packages.java.io.File('C:/Documents and Settings/Administrator/Desktop/Mirth/RTF IN/329577128.rtf');
                        DeleteThisFile['delete']();

                        Comment


                        • #13
                          Re:File and Directory commands in Java

                          Thanks for the code above, it got me out of a bind where .delete() would not work.

                          Post edited by: MikeCaldwell, at: 08/14/2008 14:43
                          Mike Caldwell
                          Alliance HealthCare - GE VAR
                          Rocklin, CA
                          Centricity PM/EMR Support - Developer - Network Engineer

                          Comment


                          • #14
                            Re:File and Directory commands in Java

                            Again, thanks Dan. I got the copy to work for the PDF files and for it to create dirs, I posted the channel here earlier.

                            Ideas Here? I have 18 Quest Channels inbound using 18 different directories to 1 directory outbound, then a Channel to Filter the outbound contents.

                            Poor Mirth is dragging along with 18 channels where it could be 1. I wonder how I could write JavaScript in the Source Transformer (Like I did with the PDF) and create a routine that would do the same this (kinda, a move not copy) DOS: COPY C:LABSIN*.* C:LABSOUT /S But, basically MOVing all files and contents from 18 dirs (All under LABSIN) to another Directory (LABSOUT). Is there a Java Move that supports SubDirs?
                            Mike Caldwell
                            Alliance HealthCare - GE VAR
                            Rocklin, CA
                            Centricity PM/EMR Support - Developer - Network Engineer

                            Comment

                            Working...
                            X