Sidebar

Can I get files with "patient" in the name but skip files with "inpatient" from a FTP source?

0 votes
379 views
asked Sep 12, 2017 by brandon-w-8204 (33,170 points)
edited Sep 13, 2017 by brandon-w-8204
I need to retrieve files with "patient" in the name and skip the files with 'inpatient' in the name from an FTP server. Can this be done on an FTP or Local Directory source?

2 Answers

0 votes

The FTP source type does not support this type of filtering. You'll need a custom script for the receiver using QIE FTP functions to filter out the file names.

Here is a sample script for plain ftp:

var host = 'localhost';
var port = '21';
var username = 'qie';
var password = 'qie';

var files = qie.listFTPEndpointNoEncryption(host, port, '\\', true, true, '', username, password);
qie.debug('files: ' + files.length);
for (var i = 0; i < files.length; i++) {
   qie.debug('fileName: ' + files[i]);
   if (StringUtils.containsIgnoreCase(files[i], 'patient') && !StringUtils.containsIgnoreCase(files[i], 'inpatient')) {
      var file = qie.readFTPFileNoEncryption(host, port, '\\'+files[i], true, '', true, true, '', username, password, 120000);
      qie.debug('file: ' + file);
      qie.addInboundMessage(qie.base64Decode(file.getNode('/ftpFile/encodedBytes')), file.getNode('/ftpFile/fileName'));
   }
}

answered Sep 12, 2017 by brandon-w-8204 (33,170 points)
0 votes

The file source does not support this. However, you can use a script to filter out the files. Here is the script for a local file directory:

var directory = new java.io.File("C:\\temp\\filterTest\\");
var files = directory.listFiles();
for (var i = 0; i < files.length; i++) {
   var fileEntry = files[i];
   var fileName = fileEntry.getAbsolutePath();
   var shortFileName = fileEntry.getName();
   qie.debug('fileName: ' + fileName + '\nshortFileName: ' + shortFileName);
   if (StringUtils.containsIgnoreCase(shortFileName, 'patient') && !StringUtils.containsIgnoreCase(shortFileName, 'inpatient')) {
      qie.addInboundMessage(qie.readFile(fileName), shortFileName);
      qie.deleteFile(fileName);
   }
}

answered Sep 13, 2017 by brandon-w-8204 (33,170 points)
...