Skip to content

Commit

Permalink
Merge pull request #19 from eHealthAfrica/feat/discharge-report
Browse files Browse the repository at this point in the history
Feat/discharge report
  • Loading branch information
adeolabadmus authored Feb 27, 2017
2 parents 4de70c2 + 4a20709 commit 3314ee2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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;
};

0 comments on commit 3314ee2

Please # to comment.