Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/discharge report #19

Merged
merged 4 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app/services/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import createPouchViews from 'hospitalrun/utils/pouch-views';
import List from 'npm:pouchdb-list';
import PouchAdapterMemory from 'npm:pouchdb-adapter-memory';
import UnauthorizedError from 'hospitalrun/utils/unauthorized-error';
import enviroment from './../config/environment';

const {
isEmpty
Expand All @@ -20,9 +21,47 @@ export default Ember.Service.extend({
.then((db) => {
this.set('mainDB', db);
this.set('setMainDB', true);
})
.then(() => {
this.createSampleDocs([enviroment.hospitalInfoDoc]);
});
},

createSampleDocs(docs) {
return new Ember.RSVP.Promise((resolve, reject) => {
let mainDB = this.get('mainDB');
let ids = docs.map((doc) => {
return doc._id;
});
return mainDB.allDocs({ keys: ids })
.then((res) => {
if (res.rows) {
let docsToCreate = res.rows.filter((row) => {
return (row.error && row.error === 'not_found') || (row.value && row.value.deleted);
}).map((row) => {
return docs.find((doc) => {
if (doc._id === row.key) {
if (row.value && row.value.deleted && row.value.rev !== doc._rev) {
doc._rev = row.value.rev;
}
return true;
}
});
});
if (docsToCreate.length) {
return mainDB.bulkDocs(docsToCreate);
}
}
})
.then((res) => {
resolve(res);
})
.catch((err) => {
reject(err);
});
});
},

createDB(configs) {
return new Ember.RSVP.Promise((resolve, reject) => {
let pouchOptions = {};
Expand Down
13 changes: 13 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,18 @@ module.exports = function(environment) {
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source'
};

ENV.hospitalInfoDoc = {
"_id": "option_2_print_header",
"_rev": "1-4457555eacb405267c6d3b7a53d8521d",
"data": {
"value": {
"facilityName": "Beit CURE International Hospital",
"headerLine1": "PO Box 31236",
"headerLine2": "Blantyre 3",
"headerLine3": "+265 (0) 1 871 900 / +265 (0) 1 875 015 /+265 (0) 1 873 694 / +265 (0) 999 505 212",
"logoURL": "https://curehospital.mw/wp-content/uploads/4/2012/11/CURE-Malawi-Logo_rgb_280_89.jpg"
}
}
}
return ENV;
};