Announcement

Collapse
No announcement yet.

Pulling TIFF file from path in ORM and writing it to another directory.

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

  • Pulling TIFF file from path in ORM and writing it to another directory.

    Hi All,

    Looking for some guidance if possible.

    I am receiving the following ORM which has a file path to a .tiff which I would like to pull out and write to another folder (or if I could convert the TIFF to a PDF and write to a folder, even better).

    Would anyone be able to give some guidance on how to go about this?

    Code:
    MSH|^~\&|QDOC|HL7V1.1|AGFA|AGFA|20190611153915||ORM^O01|00115535|P|2.3.1||||||8859/1
    PID|||000106722^^^AUT^PI||ZZZRISTEST^Pacs||19350202|M|||Test Test^^^Kilkenny^K^IRL
    ORC|XO|QPREQUESTTOPIC_25935^IPLAN|QPREQUEST_25291^RAD|QPREQUEST_25291^IPLAN|SC||^^^^^R|||SNAUGHTON||RA68717^NaughtonTest^StephenTest|||||AUT^Aut Even Hospital||||Aut Even Hospital^^AUT
    OBR||QPREQUESTTOPIC_25935^IPLAN|QPREQUEST_25291^RAD|MSKUH^MRI BRAIN^RAD^^^QUADRAT||20190611153915|20190611220000|||||||||RA68717^NaughtonTest^StephenTest||AUT29650|AUT29650|AUT29650||||||||||||||^^^RAD^MRI||20190611220006
    OBX|1|TX|PATSTATUS||Outpatient
    OBX|1|RP|SCANNED_REQUEST^Referral Note||\E\\E\192.168.9.22\E\Scanned_attachements\E\79DB69C2-1B7C-4107-8F62-8330B0C5A9FF.tiff
    ZDS|1.3.51.0.1.1.172.16.20.234.29650.29575^Agfa^Application^DICOM
    I have tried adding the following into the Destination Transformed but I think I am way off:

    Code:
    var fileName = "msg['OBX'][1]['OBX.5']['OBX.5.1'].toString()"
    
    var directory = "E:\Inbound" 
    var outFileName = "test.tiff";
    var destination = directory +"\\" + outFileName
    
    importPackage(java.io);
    importPackage(org.apache.commons.io);
    //var file = new java.io.File(directory);
    var inputFile = new File(fileName);
    var outputFile = new File(destination);
    FileUtils.copyFile(inputFile,outputFile);
    Thanks,
    Stephen Naughton
    Stephen Naughton
    Clinical Systems Manager

    Mirth 3.7.0

  • #2
    I would channelMap the variables so you can verify the contents. Or use logger.info()
    Best,

    Kirby

    Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

    Appliance Version 3.11.4
    Mirth Connect Version 3.8.0
    Java Version 1.6.0_45-b06
    Java (64 bit) Version 1.6.0_45-b06
    Java 7 (64 bit) Version 1.7.0_151-b15
    Java 8 (64 bit) Version 1.8.0_181-b13
    PostgreSQL Version 9.6.8

    Comment


    • #3
      Hi,
      your message indicates that you have to pull the file from a SMB-Share
      So you have to use the CIFS-library.

      Code:
      var fn=msg['OBX'][i]['OBX.5']['OBX.5.1'].toString().replace(/\\E\\/g,"/").replace(/\/\//,"smb://youtusername:[email protected]");
      var file=new Packages.jcifs.smb.SmbFile(fn);
      var inputStream=file.getInputStream();
      var byteArray = IOUtils.toByteArray(inputStream);
      inputStream.close();
      Don't forget to change yourusername and yourpassword to your appropriate credentials :-)

      You now have a Java byte array representing your TIFF-File

      As for converting this to PDF:

      Code:
      importPackage(com.sun.media.jai.codec);
      importPackage(org.apache.commons.io);
      var doc = new org.apache.pdfbox.pdmodel.PDDocument();
      
      var seekableStream = new Packages.com.sun.media.jai.codec.ByteArraySeekableStream(byteArray);
      var imageDecoder = ImageCodec.createImageDecoder("tiff", seekableStream, null);
      for (var i=0; i < imageDecoder.getNumPages(); i++) {
      	var renderedImage = imageDecoder.decodeAsRenderedImage(i);
      	doc.setAllSecurityToBeRemoved(true);
      	var page = new Packages.org.apache.pdfbox.pdmodel.PDPage();
      	doc.addPage(page);
      	var contentStream = new Packages.org.apache.pdfbox.pdmodel.PDPageContentStream(doc, page);
      	var image = Packages.org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory.createFromImage(doc, javax.media.jai.PlanarImage.wrapRenderedImage(renderedImage).getAsBufferedImage());
           	contentStream.drawImage(image, 1, 1, 600, 750);
           	contentStream.close();
      } 
      var ba = new java.io.ByteArrayOutputStream();
      doc.save(ba);
      var att=addAttachment(Packages.org.apache.commons.codec.binary.Base64.encodeBase64(ba.toByteArray(),false),"PDF");
      All this results in an attachment containing your converted PDF-File, which you can even view with Mirth's PDF-Viewer
      It looks a bit streched - but not being a graphics person I have no idea what these parameters in drawImage mean.
      I just want to show you one possible way and this was the first one I found in stackoverflow.

      You have to put sun-jai_codec.jar and sun-jai_core.jar into your resources directory.

      Comment

      Working...
      X