Announcement

Collapse
No announcement yet.

File Reader delete file takes so long or wont delete.

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

  • File Reader delete file takes so long or wont delete.

    hi all,

    I created a channel that checks each PDF in a special folder every 5 seconds. When a PDF is converted to text then that PDF is moved to another folder relative to the text in the PDF file. But I also want the PDF in the root folder to be deleted, but when I set in File Reader to delete the file, I get an error or the file is deleted after a very long time or not at all. One problem is that I cant delete the file because the file is open in mcservice.exe. Why still?

  • #2
    What kind of file reader? Post a screenshot of your source tab.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      I attach the screenshot of source tab and also error log for deleting. I assume that Mirth services keep for for herself as you see on image 3 i cant delete even from Windows and i get error that file is open in mcservice.exe. What can be wrong? Or difrent question is this normal that Mirth take so long time to delete file?

      Source Screenshot:
      1.jpg

      Error log in Mirth about deleting file:
      2.jpg

      Error on deleting file from Windows:
      3.jpg

      KR. Toni

      Comment


      • #4
        How are you converting the file to text? Perhaps post your full channel export or the part that converts to text? Perhaps the conversion process is not exiting cleanly?
        pacmano
        Mirth Guru
        Last edited by pacmano; 11-28-2021, 10:24 AM.
        Diridium Technologies, Inc.
        https://diridium.com

        Comment


        • #5
          Yes problem is with Transformer code not with Mirth. If i disable this Transformer it working great. But why is in this code which i attach problematich? At the end i close the PDF file with "reader.close();".

          SharedScreenshot.jpg

          Comment


          • #6
            Seriously, post the raw code, not just a screenshot of it.
            Diridium Technologies, Inc.
            https://diridium.com

            Comment


            • #7
              Ok i attach channel XML and also code of transformer


              PHP Code:
              var file sourceMap.get('fileDirectory') + "/" sourceMap.get('originalFilename'); // File path + file name

              var reader = new Packages.com.itextpdf.text.pdf.PdfReader(file); // Read the PDF file

              channelMap.put("Original Path + File"file); // Put file name to Map

              for (i=1;i<=reader.getNumberOfPages();i++) {

                   var 
              contents Packages.com.itextpdf.text.pdf.parser.PdfTextExtra ctor.getTextFromPage(readeri); // Extract text from PDF file

                   
              var SerialNumber contents.match(/(SN:FN-\d{8})/); //Regex match
                   
              var SecondID contents.match(/(Second ID: \d{3})/); //Regex match

                   
              if (!SerialNumber) {
                        
              logger.info("V PDF datoteki ni zapisane serijske ┼ítevilke aparata.");
                   } else {
                       
              logger.info("Serijska stevilka EKG: " SerialNumber[0].substring(3));

                       switch (
              SerialNumber[0].substring(3)) {

                            case 
              'FN-17028982':
                           var 
              oddelek "Pediatrija";
                           break;

                           case 
              'FN-17028977':
                           var 
              oddelek "Urgenca";
                       }

                       
              channelMap.put("oddelek",oddelek); // Put "oddelek" to Map

                   
              }

                   if (!
              SecondID) {
                       
              logger.info("V PDF datoteki ni zapisane Second ID ┼ítevilke.");
                   } else {
                       
              logger.info("Second ID: " SecondID[0].substring(11));
                   }
              }

              reader.close(); // Close PDF file 
              Attached Files
              toniojst
              Mirth Newb
              Last edited by toniojst; 11-29-2021, 07:06 AM.

              Comment


              • #8
                Your are re-inventing the wheel.

                See https://github.com/nextgenhealthcare...t%20From%20PDF.

                Add or import that as a code template.

                Then in your source transformer something like the below is fine. I had 2 files in /tmp/pdfs named "test1.pdf" and "test2.pdf" with the corresponding word in each file.

                PHP Code:

                var pdfBytes getAttachments(true).get(0).getContent();
                var 
                pdfText extractTextFromPDF(pdfBytes);
                if (
                pdfText.indexOf('test2') != -1) {
                    
                $c('found_test2'true)

                Note on the summary tab for your channel:

                2021-11-29_16-00.png

                But on your original problem - it always deletes for me - but ain't gonna lie, I am in Linux.
                pacmano
                Mirth Guru
                Last edited by pacmano; 11-29-2021, 08:26 PM.
                Diridium Technologies, Inc.
                https://diridium.com

                Comment


                • #9
                  Do learn to use attachments! See https://forums.mirthproject.io/artic...ng-attachments
                  Diridium Technologies, Inc.
                  https://diridium.com

                  Comment


                  • #10
                    Can you please crate for me channel and sen to me as XML. Becuse i try but it look that i'm not doing right. So i please for example channel.

                    EDIT: Ok i update code that working like must do. So thanks for all help and your time =)
                    toniojst
                    Mirth Newb
                    Last edited by toniojst; 11-29-2021, 11:45 PM.

                    Comment

                    Working...
                    X