Announcement

Collapse
No announcement yet.

Remove Files once confirmed sent to destination

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

  • Remove Files once confirmed sent to destination

    Hello,

    I'm trying remove individual files once they have a confirmed Sent status to a destination.

    I have a set of files written to a folder that I have a File Reader monitor, the files have certain DICOM tag that need to be sent to different destinations. I'm using a filter on the destination to 3 separate AETitles with that Dicom Tag. (Working)

    in the process however these files early at some stage don't necessarily have the tags written yet, and the Dicom sender tries to process but filters them. which is fine as they won’t be sent, problem occurs when the files do have the Dicom tag they then get Queued and Sent.

    The files will remain in the folder and keep getting processed so, for example I could have 100 files, but end up with 1000's queued in a couple of minutes as the sent files are not recorded and dropped from the queue or deleted from the source. Ideally each confirmed sent file will be removed one by one from the folder or the queue so they won’t be sent twice Using a combination of the originalfilename + PID (tag00100020) as to identify from other files or set of files.

    I've looked at prevous posts for post processing once confirmed sent then delete a with known path, but nothing has worked so far.

    Is this even possible or am I way off?

    https://www.mirthcorp.com/community/...ad.php?p=50019

    http://http://www.mirthproject.org/c...ad.php?t=10591


    Thanks.


    Ruffdraft
    Last edited by Ruffdraft; 03-09-2020, 04:12 AM.

  • #2
    Ater Process/Action set to delete.

    Comment


    • #3
      Thanks, cory_cole,

      Issue with this is the files are being filtered before they are edited so are considered as processed, and then being deleted before the next poll cycle where they have the DICOM tags.

      The files in my scenario are created before the first poll and amended after with DICOM tags. The filter will use these to send to the AETitles.

      It could/would work if the polling schedule was increased to say 5 minutes, but it needs to be around 5 to 20 seconds.

      Comment


      • #4
        Thanks, cory_cole,

        Issue with this is the files are being filtered before they are edited so are considered as processed, and then being deleted before the next poll cycle where they have the DICOM tags.

        The files in my scenario are created before the first poll and amended after with DICOM tags. The filter will use these to send to the AETitles.

        It could/would work if the polling schedule was increased to say 5 minutes, but it needs to be around 5 to 20 seconds.

        Comment


        • #5
          Put this in the post processor

          var originalFile = new File (file_name);//file_name should be complete path
          originalFile.delete();

          Comment


          • #6
            Added

            Code:
            var originalFile = new File (file_name);//file_name should be complete path
            originalFile.delete();
            in postprocessing but getting the following error;
            [2020-03-09 10:46:55,081] ERROR (com.mirth.connect.server.util.javascript.JavaScri ptUtil:522): Error executing Postprocessor script from channel: 35fb35b7-7096-4061-b38d-3464b4d2f052
            com.mirth.connect.server.MirthJavascriptTransforme rException: SOURCE CODE:
            96: }97: }98: function doScript() {99: // This script executes once after a message has been processed100: // Responses returned from here will be stored as "Postprocessor" in the response map101: var originalFile = new File ("C:\Scans\test.txt");//file_name should be complete path102: originalFile.delete(); 103: }LINE NUMBER:
            101DETAILS:
            ReferenceError: "File" is not defined.
            at 35fb35b7-7096-4061-b38d-3464b4d2f052_Postprocessor:101 (doScript)
            at 35fb35b7-7096-4061-b38d-3464b4d2f052_Postprocessor:104
            at com.mirth.connect.server.util.javascript.JavaScrip tUtil.executeScript(JavaScriptUtil.java:547)
            at com.mirth.connect.server.util.javascript.JavaScrip tUtil.executePostprocessorScripts(JavaScriptUtil.j ava:275)
            at com.mirth.connect.server.transformers.JavaScriptPo stprocessor$JavaScriptPostProcessorTask.doCall(Jav aScriptPostprocessor.java:104)
            at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
            at java.util.concurrent.FutureTask.run(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
            at java.lang.Thread.run(Unknown Source)
            Last edited by Ruffdraft; 05-12-2020, 04:09 AM.

            Comment


            • #7
              importPackage(java.io);

              Comment


              • #8
                Post process for deleting file

                Thanks, for you response. It led me to try below which now works in post process;
                Code:
                var originalFile = new java.io.File ("C:\\Scans\\test.txt");//file_name should be complete path originalFile.delete();
                Tried this though and have yet to get this working, do you know if this will work with dynamic file dir and file name?
                Code:
                var originalFile = new java.io.File ("${fileDirectory}\\${originalFilename}");//file_name should be complete path originalFile.delete();
                cheers.
                Last edited by Ruffdraft; 05-12-2020, 04:09 AM.

                Comment


                • #9
                  Have you looked at the File Age setting on the File Reader? It checks that it's been at least that amount of time since the file was last modified before reading it in and defaults to only 1 second. How long does it take for the tag to get added after the rest of the file has already been written? Would increasing the File Age value take care of the problem and allow to you get rid of your filters and delete on successful read?

                  If it works 99.9% of the time, you could always return an ERROR if something unusual happens and it's still not set, and then change your Error in Response Action on the File Reader to move it to the same directory to prevent it from being deleted. Or you can move it to another directory if you don't want it to continuously retry knowing that conditions are already out of the ordinary.

                  Comment


                  • #10
                    Originally posted by Ruffdraft View Post
                    Tried this though and have yet to get this working, do you know if this will work with dynamic file dir and file name?
                    var originalFile = new java.io.File ("${fileDirectory}\\${originalFilename}");//file_name should be complete path
                    originalFile.delete();
                    Those are velocity tokens, and they don't work automatically in javascript like they do in the connector fields.

                    The closest translation to what you are trying to do is:
                    Code:
                    var originalFile = new java.io.File($('fileDirectory') + '\\' + $('originalFilename'));

                    Comment


                    • #11
                      Thanks Agermana,

                      Both have been helpful and for now I'm happy using delete and post processing with the file age (file age settings was an oversight if im honest...).

                      I'll be working on a slicker approach so there isn't a delay on filtering and processing the files (currently 5 minutes for the File age is acceptable), as well if Queue'd only queue once not continuesly and then once sent delete not before as Queued messages were kicking off the postprocess.

                      Comment


                      • #12
                        Thanks Agetmano, sorry fo the late reply.

                        This worked perfectly I use it with a transformer in channel so it only deletes files postprosess with matches of a Dicom certain dicom header tag.


                        Code:
                        if ($('DCMheaderTag') == "Example1" || $('DCMheaderTag') == "Example2") {
                        var originalFile = new java.io.File($('fileDirectory') + '\\' + $('originalFilename'));
                        originalFile.delete();
                        }
                        return false;
                        Last edited by Ruffdraft; 05-12-2020, 04:09 AM.

                        Comment


                        • #13
                          Now looking at trying to delete files postpreocess from a SMB source, was hopeing the following will do this however this is only working for local drives;

                          Any ideas?

                          Code:
                          if ($('DCMheaderTag') == "Example1" || $('DCMheaderTag') == "Example2") {
                          var originalFile = new java.io.File($('fileDirectory') + '\\' + $('originalFilename')); originalFile.delete();
                          }
                          return false;

                          Comment


                          • #14
                            You might want to take a look at my suggestion in post #9 on this thread.

                            Comment

                            Working...
                            X