server/lib/storage/index.js
//Refactored out so can use internally.
Refactored out so can use internally.
Refactored out so can use internally .
function storeFile(fileRequest, username, callback) {
  db = app.get("db_conn");
  grid = app.get("grid_conn");
  var source = '';
  var details = '';
  if (fileRequest.source) {
    source = fileRequest.source;
  }
  if (fileRequest.details) {
    details = fileRequest.details;
  }
  console.log("Storage PUT call");
  if (fileRequest.filename === undefined || fileRequest.filename.length < 1 || fileRequest.filename === null) {
    callback('Error, filname bad.');
  }
  if (fileRequest.file === undefined || fileRequest.file.length < 1 || fileRequest.file === null) {
    callback('Error, file bad.');
  }
  var fileType = 'binary/octet-stream';
  if (fileRequest.filename && fileRequest.filename.length > 3) {
    var extension = fileRequest.filename.substring(fileRequest.filename.lastIndexOf(".") + 1, fileRequest.filename.length);
    if (extension.toLowerCase() === 'xml') {
      fileType = 'text/xml';
    }
  }
  try {
    var bb = blueButton(fileRequest.file);
    var bbMeta = bb.document();
    if (bbMeta.type === 'ccda') {
      fileType = "CCDA";
    }
  } catch (e) {
    console.log(e);
  }
  var buffer = new Buffer(fileRequest.file);
  grid.put(buffer, {
    metadata: {
      source: source,
      details: details,
      owner: username,
      parsedFlag: false
    },
    'filename': fileRequest.filename,
    'content_type': fileType
  }, function(err, fileInfo) {
    if (err) {
      throw err;
    }
    var recordId = fileInfo._id;
    callback(err, fileInfo);
  });
}
function storeFile ( fileRequest , username , callback ) { db = app . get ( "db_conn" ) ; grid = app . get ( "grid_conn" ) ; var source = '' ; var details = '' ; if ( fileRequest . source ) { source = fileRequest . source ; } if ( fileRequest . details ) { details = fileRequest . details ; } console . log ( "Storage PUT call" ) ; if ( fileRequest . filename === undefined || fileRequest . filename . length < 1 || fileRequest . filename === null ) { callback ( 'Error, filname bad.' ) ; } if ( fileRequest . file === undefined || fileRequest . file . length < 1 || fileRequest . file === null ) { callback ( 'Error, file bad.' ) ; } var fileType = 'binary/octet-stream' ; if ( fileRequest . filename && fileRequest . filename . length > 3 ) { var extension = fileRequest . filename . substring ( fileRequest . filename . lastIndexOf ( "." ) + 1 , fileRequest . filename . length ) ; if ( extension . toLowerCase ( ) === 'xml' ) { fileType = 'text/xml' ; } } try { var bb = blueButton ( fileRequest . file ) ; var bbMeta = bb . document ( ) ; if ( bbMeta . type === 'ccda' ) { fileType = "CCDA" ; } } catch ( e ) { console . log ( e ) ; } var buffer = new Buffer ( fileRequest . file ) ; grid . put ( buffer , { metadata : { source : source , details : details , owner : username , parsedFlag : false } , 'filename' : fileRequest . filename , 'content_type' : fileType } , function ( err , fileInfo ) { if ( err ) { throw err ; } var recordId = fileInfo . _id ; callback ( err , fileInfo ) ; } ) ; }
Refactored out so can use internally.
Refactored out so can use internally .
// source - Inbox/Outbox/Upload // details - Some details about the file (doctor name (sender )for Inbox, user comments for Upload, doctor name (to whom it was sent) for Outbox) //console.log(fileRequest); //console.log("---"); //console.log(fileRequest.file); //console.log("---"); //do nothing, keep original fileType //TODO:  Fix once auth is implemented. //console.log("Record Stored in Gridfs: " + recordId);