Sidebar

FIleNotFoundException when using netFile with FileOutputStream

0 votes
661 views
asked Aug 20, 2018 by jonathan-l-4690 (210 points)
edited Nov 2, 2018 by brandon-w-8204

Hello,

I am attempting to write a PDF to a network drive, but keep running into issues. I have researched it a bit, and also have sucessfully wrote it to a local drive plenty of times, but keep running into the error below when attempting the network route.

I have reviewed the permissions of the service account I am using with new NetFile, and ensured the parent directory already exists.


Below is the code I am using. It is converting a Base64, then writing that PDF to file and including the network path in the HL7 that continues to Centricity:

//get the encoded OBX5 where the type is Base64
var obx5Decoded = qie.base64DecodeToBytes(message.getNode('OBX-5[3]'));
// + qie.formatDate('MMddYYYY', qie.getSystemDate()) + '
var mrn = message.getNode('PID-2');
var evntdt = message.getNode('EVN-2');
var path = '\\centtjsdmt2\\g$\\Path Group Reports\\' + mrn + ' - ' + evntdt + '.pdf';
//var newFile = new java.io.File(path);
var newFile = new NetFile(path, 'USERNAME', 'PASSWORD');
newFile.createNewFile();
qie.info(newFile);

// stream the bytes to the file
var out = new java.io.FileOutputStream(newFile, false);
out.write(obx5Decoded);
out.close();

message.setNode('MSH-10', StringUtils.substring(message.getNode('MSH-10'), 0, 20));
message.setNode('OBX-2', 'ST');
message.setNode('OBX-3', 'IMAGE_REF');
message.setNode('OBX-5', path + '^External Document');

Thanks,

Jonathan

commented Mar 30, 2020 by rich-c-2789 (16,180 points)
edited Mar 30, 2020 by rich-c-2789
NOTE: As of version .47 the code wizard option "New NetFile" generates this code "qie.newNetFile('filepath', 'domainUsername', 'password', 'parameters', 'autoClose');"  Due to a memory leak the autoClose optional parameter has been added.  Also a close() method has been added to the NetFile object.   If you would like to manage closing the NetFile your self set this new parameter to false and call close on the netfile manually.  Example: myNetFile.close().  The old api 'new NetFile' is still supported and also has the additional optional parameter 'autClose'.  Both apis return the same NetFile object.

1 Answer

0 votes

The issue is the qie netFile is not compatible with the java FileOutputStream. You can use qie.writeFile to do this.

Script:

//get the encoded OBX5 where the type is Base64
var obx5Decoded = qie.base64DecodeToBytes(message.getNode('OBX-5[3]'));
// + qie.formatDate('MMddYYYY', qie.getSystemDate()) + '
var mrn = message.getNode('PID-2');
var evntdt = message.getNode('EVN-2');
var path = '\\centtjsdmt2\\g$\\Path Group Reports\\' + mrn + ' - ' + evntdt + '.pdf';
//var newFile = new java.io.File(path);
var newFile = new NetFile(path, 'USERNAME', 'PASSWORD');

// newFile.createNewFile();
// // qie.info(newFile);

// // stream the bytes to the file
// var out = new java.io.FileOutputStream(newFile, false);
// out.write(obx5Decoded);
// out.close();

// Use qie.writeFile when using a NetFile qie java object. FileOutputStream is not compatable.
qie.writeFile(newFile, obx5Decoded);

message.setNode('MSH-10', StringUtils.substring(message.getNode('MSH-10'), 0, 20));
message.setNode('OBX-2', 'ST');
message.setNode('OBX-3', 'IMAGE_REF');
message.setNode('OBX-5', path + '^External Document');

answered Aug 20, 2018 by brandon-w-8204 (33,270 points)
commented Aug 20, 2018 by jonathan-l-4690 (210 points)
Will qie.writeFile be able to handle writing the bytes? We had to set up the FileOutputSteam in order to handle the bytes that were being wrote from the Base64 conversion.

I also went ahead and tried the qie.writeFile, but ran into an issue where it can't create the file on the network drive. I have verified the user has full access to do so, but I am wondering if somehow it isn't using the credentials specified in NetFile.
commented Aug 20, 2018 by brandon-w-8204 (33,270 points)
Yes the writeFile does use the username and password from the netFile and does accept the bytes in the .45 build or later. The 45 build is now available and I did test this in the .45 build.
...