Skip to content

Commit

Permalink
Merge efc25c2 into 595ee1e
Browse files Browse the repository at this point in the history
  • Loading branch information
martzcodes committed Apr 25, 2015
2 parents 595ee1e + efc25c2 commit 1fedb56
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 33 deletions.
8 changes: 6 additions & 2 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ exports.connect = function connectDatabase(server, inputOptions, callback) {

var dbName = options.dbName;
//console.log("DB Name in Blue-Button-Record db.js: "+dbName);
mongo.Db.connect('mongodb://' + server + '/' + dbName, function (err, dbase) {
var db = new mongo.Db(dbName, new mongo.Server('localhost', 27017));
//mongo.Db.connect('mongodb://' + server + '/' + dbName, function (err, dbase) {
db.open(function (err, dbase) {
if (err) {
callback(err);
} else {
var dbinfo = {};
dbinfo.db = dbase;
dbinfo.grid = new mongo.Grid(dbase, 'storage');
dbinfo.GridStore = mongo.GridStore;
dbinfo.ObjectID = mongo.ObjectID;
//dbinfo.grid = new mongo.Grid(dbase, 'storage');
var c = mongoose.createConnection('mongodb://' + server + '/' + dbName);
dbinfo.connection = c;

Expand Down
71 changes: 57 additions & 14 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,49 @@ exports.saveSource = function (dbinfo, ptKey, content, sourceInfo, contentType,

fileMetadata.source = source;

dbinfo.grid.put(buffer, {
var gridStore = new dbinfo.GridStore(dbinfo.db, new dbinfo.ObjectID(), sourceInfo.name, 'w', {
root: 'storage',
metadata: fileMetadata,
filename: sourceInfo.name,
content_type: sourceInfo.type,
}, function (err, fileInfo) {
//console.log("fileInfo", fileInfo);
});

gridStore.open(function (err, gridStore) {
if (err) {
callback(err);
} else {
/*Relax for now pending further investigation, seems to be chunking overhead.*/
//if (fileInfo.length !== sourceInfo.size) {
// callback('file size mismatch');
//} else {
callback(null, fileInfo._id);
//}
}
gridStore.write(buffer, function (err, gridStore) {
if (err) {
callback(err);
}
gridStore.close(function (err, fileData) {
if (err) {
callback(err);
} else {
callback(null, fileData._id);
}

});
});
});
/*
dbinfo.grid.put(buffer, {
metadata: fileMetadata,
filename: sourceInfo.name,
content_type: sourceInfo.type,
}, function (err, fileInfo) {
//console.log("fileInfo", fileInfo);
if (err) {
callback(err);
} else {
//Relax for now pending further investigation, seems to be chunking overhead.
//if (fileInfo.length !== sourceInfo.size) {
// callback('file size mismatch');
//} else {
callback(null, fileInfo._id);
//}
}
});
*/
};

exports.getSourceList = function (dbinfo, ptKey, callback) {
Expand Down Expand Up @@ -129,12 +155,29 @@ exports.getSource = function (dbinfo, ptKey, sourceId, callback) {
if (err) {
callback(err);
} else if (results) {
dbinfo.grid.get(sourceId, function (err, data) {
console.log("martz results", JSON.stringify(results, null, 4));
dbinfo.GridStore.list(dbinfo.db, 'storage', {
id: true
}, function (err, items) {
items.forEach(function (filename) {
console.log("martz file" + JSON.stringify(filename), null, 4);
});
});
var gridStore = new dbinfo.GridStore(dbinfo.db, results._id, 'r', {
root: 'storage'
});
gridStore.open(function (err, gridStore) {
if (err) {
callback(err);
} else {
var returnFile = data.toString();
callback(null, results.filename, returnFile);
gridStore.read(function (err2, data) {
if (err2) {
callback(err2);
} else {
var returnFile = data.toString();
callback(null, results.filename, returnFile);
}
});
}
});
} else {
Expand Down
38 changes: 24 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
{
"author": "Dmitry Kachaev, Matthew McCall and Afsin Ustundag",
"author": "Dmitry Kachaev",
"contributors": [{
"name": "Matthew McCall",
"email": "matt@amida-tech.com"
}, {
"name": "Afsin Ustundag",
"email": "afsin.ustundag@us.pwc.com"
}, {
"name": "Matt Martz",
"email": "matt.martz@amida-tech.com"
}],
"name": "blue-button-record",
"description": "Master Health Record and Data Reconciliation Engine Persistance Layer",
"version": "1.5.0-beta.2",
"version": "1.5.0-beta.3a",
"repository": {
"type": "git",
"url": "git@github.com:amida-tech/blue-button-record.git"
Expand All @@ -18,27 +28,27 @@
],
"dependencies": {
"async": "0.9.x",
"blue-button-meta": "^1.1.0",
"blue-button-meta": "^1.5.0-beta",
"blue-button-pim": "~1.0.0",
"doublemetaphone": "^0.1.2",
"mongodb": "1.4.x",
"mongoose": "3.8.x",
"underscore": "1.6.x"
"mongodb": "2.0.x",
"mongoose": "4.0.x",
"underscore": "1.8.x"
},
"devDependencies": {
"grunt": "0.4.x",
"grunt-contrib-jshint": "0.8.x",
"grunt-contrib-jshint": "0.11.x",
"grunt-contrib-watch": "0.6.x",
"grunt-mocha-test": "0.10.x",
"grunt-jsbeautifier": "^0.2.7",
"mocha": "1.18.x",
"chai": "1.9.x",
"grunt-mocha-test": "0.12.x",
"grunt-jsbeautifier": "^0.2.10",
"mocha": "2.2.x",
"chai": "2.2.x",
"chai-datetime": "1.3.x",
"grunt-coveralls": "*",
"grunt-istanbul-coverage": "*",
"coveralls": "~2.10.0",
"mocha-lcov-reporter": "0.0.1",
"blue-button": "^1.1.0"
"coveralls": "~2.11.2",
"mocha-lcov-reporter": "0.0.2",
"blue-button": "^1.5.0-beta"
},
"engines": {
"node": "0.10.x"
Expand Down
3 changes: 2 additions & 1 deletion test/unit/refmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ exports.prepareConnection = function (dbname, context) {
it('check connection and models', function (done) {
expect(context.dbinfo).to.exist;
expect(context.dbinfo.db).to.exist;
expect(context.dbinfo.grid).to.exist;
expect(context.dbinfo.GridStore).to.exist;
expect(context.dbinfo.ObjectID).to.exist;
expect(context.dbinfo.models).to.exist;
expect(context.dbinfo.models.testallergies).to.exist;
expect(context.dbinfo.models.testprocedures).to.exist;
Expand Down
6 changes: 4 additions & 2 deletions test/unit/test-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ describe('storage.js methods', function () {
it('check connection and models', function (done) {
expect(dbinfo).to.exist;
expect(dbinfo.db).to.exist;
expect(dbinfo.grid).to.exist;
expect(dbinfo.GridStore).to.exist;
expect(dbinfo.ObjectID).to.exist;
expect(dbinfo.storageModel).to.exist;
done();
});
Expand All @@ -79,7 +80,8 @@ describe('storage.js methods', function () {
var f = function (index, callback) {
var fileinfo = {
name: getFileName(index),
type: getContentType(index)
type: getContentType(index),
source: "test file"
};
storage.saveSource(dbinfo, pats[index], contents[index], fileinfo, classes[index], callback);
};
Expand Down

0 comments on commit 1fedb56

Please sign in to comment.