Announcement

Collapse
No announcement yet.

reading smbfile and sending in OBX

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

  • reading smbfile and sending in OBX

    Hi All,

    One system sends us ORUs with a filename in OBX rather than the pdf embedded. I would like mirth to fetch the file using SmbFileConnection? and then encode the pdf into the message. Any tips on handling the inputStream to encode and stick back into OBX?

    What I have so far...
    Code:
    var client = new com.mirth.connect.connectors.file.filesystems.SmbFileConnection(smbshare, smbuser, smbpasswd, smbtimeout);
    
    var inputStream = client.readFile(smbfile, smbdir);
    
    // something here to read inputStream into memory and base64 encode  ??
    
    client.closeReadFile();

  • #2
    answering my own question... for others who are interested. I am missing error handling but otherwise it does work.
    Code:
    // remove path and just get filename from obx5
    var filename = msg['OBX'][0]['OBX.5']['OBX.5.1'].toString();
    var n = filename.lastIndexOf('\\');
    filename = filename.substring(n+1);
    
    // setup cifs share info
    var smbhost= "myserver.mydomain.com";
    var smbuser = "domain\\username";
    var smbpasswd = "mypass";
    var smbdir = "mysharename";
    var smbfile = filename;
    var smbtimeout = 10000;
    var smbSuccess = false;
    
    // connect to cifs server and get pdf file
    var client = new com.mirth.connect.connectors.file.filesystems.SmbFileConnection(smbhost, smbuser, smbpasswd, smbtimeout);
    var inputStream = client.readFile(smbfile, smbdir);
    var inputByteArr = org.apache.commons.io.IOUtils.toByteArray(inputStream);
    inputStream.close();
    
    // encode pdf file and store in OBX.5
    var doc = FileUtil.encode(inputByteArr);
    doc = doc.replaceAll('\r\n|\r|\n','');
    
    msg['OBX'][0]['OBX.5']['OBX.5.1'] = filename;
    msg['OBX'][0]['OBX.5']['OBX.5.2'] = "TEXT";
    msg['OBX'][0]['OBX.5']['OBX.5.3'] = "PDF";
    msg['OBX'][0]['OBX.5']['OBX.5.4'] = "BASE64";
    msg['OBX'][0]['OBX.5']['OBX.5.5'] = doc;
    Last edited by glenn71; 07-27-2015, 05:25 PM.

    Comment


    • #3
      updated solution for 3.3+

      There were changes made to connectors from mirth 3.3+ so here is the updated solution:

      Code:
      	var filename = msg['OBX']['OBX.5']['OBX.5.1'].toString();
      	var n = filename.lastIndexOf('\\');
      	filename = filename.substring(n+1);
      
      	var smbhost = "myserver.mydomain.com";
      	var smbuser = "domain\\username";
      	var smbpasswd = "mypass";
      	var smbdir = "mysharename";
      	var smbfile = filename;
      	var smbtimeout = 10000;
      	var smbSuccess = false;
      	try {
      		var fileConnOpt = new com.mirth.connect.connectors.file.FileSystemConnectionOptions(smbuser, smbpasswd, null);
      		var client = new com.mirth.connect.connectors.file.filesystems.SmbFileConnection(smbhost, fileConnOpt, smbtimeout);
      		var inputStream = client.readFile(smbfile, smbdir);
      		var inputByteArr = org.apache.commons.io.IOUtils.toByteArray(inputStream);
      		inputStream.close();
      		var doc = FileUtil.encode(inputByteArr);
      		doc = doc.replaceAll('\r\n|\r|\n','');
      		var pdf = addAttachment(doc, 'application/pdf');
      		msg['OBX'][0]['OBX.5']['OBX.5.1'] = filename;
      		msg['OBX'][0]['OBX.5']['OBX.5.2'] = "TEXT";
      		msg['OBX'][0]['OBX.5']['OBX.5.3'] = "PDF";
      		msg['OBX'][0]['OBX.5']['OBX.5.4'] = "BASE64";
      		msg['OBX'][0]['OBX.5']['OBX.5.5'] = "${ATTACH:" + pdf.getId() + "}";
      	} catch (err) {
      		throw 'failed to import pdf file' + filename + ' from server: ' + err.toString();
      	}

      Comment


      • #4
        updated solution for 3.6+

        and it was changed again in 3.6

        it now should be:

        var fileConnOpt = new com.mirth.connect.connectors.file.FileSystemConnec tionOptions(false, smbuser, smbpasswd, null);
        var client = new com.mirth.connect.connectors.file.filesystems.SmbF ileConnection(smbhost, fileConnOpt, smbtimeout);
        var inputStream = client.readFile(smbfile, smbdir, null);

        Comment

        Working...
        X