diff --git a/app/mixins/charge-route.js b/app/mixins/charge-route.js index 4b55c5ce2d..04d9daa955 100644 --- a/app/mixins/charge-route.js +++ b/app/mixins/charge-route.js @@ -11,8 +11,8 @@ export default Ember.Mixin.create({ afterModel() { return new Ember.RSVP.Promise(function(resolve, reject) { let database = this.get('database'); - let maxId = database.getPouchId({}, 'pricing'); - let minId = database.getPouchId(null, 'pricing'); + let maxId = database.getMaxPouchId('pricing'); + let minId = database.getMinPouchId('pricing'); let pricingCategory = this.get('pricingCategory'); let pricingQuery = { startkey: [pricingCategory, null, null, minId], diff --git a/app/mixins/patient-id.js b/app/mixins/patient-id.js index 894acf0ab5..a89636a229 100644 --- a/app/mixins/patient-id.js +++ b/app/mixins/patient-id.js @@ -1,9 +1,8 @@ import Ember from 'ember'; -import PouchDbMixin from 'hospitalrun/mixins/pouchdb'; const { inject, isEmpty } = Ember; -export default Ember.Mixin.create(PouchDbMixin, { +export default Ember.Mixin.create({ idPrefix: null, database: inject.service(), config: inject.service(), @@ -16,8 +15,7 @@ export default Ember.Mixin.create(PouchDbMixin, { generateFriendlyId() { let config = this.get('config'); let database = this.get('database'); - let maxValue = this.get('maxValue'); - + let maxValue = database.getMaxPouchId('patient'); let findUnusedId = (sequence) => { let current, id; return config.getPatientPrefix() diff --git a/app/routes/abstract-index-route.js b/app/routes/abstract-index-route.js index c2297852c3..0dac21ffc8 100644 --- a/app/routes/abstract-index-route.js +++ b/app/routes/abstract-index-route.js @@ -31,11 +31,11 @@ export default Ember.Route.extend(PouchDbMixin, ProgressDialog, AuthenticatedRou }, _getMaxPouchId() { - return this.get('database').getPouchId({}, this.get('modelName').camelize()); + return this.get('database').getMaxPouchId(this.get('modelName').camelize()); }, _getMinPouchId() { - return this.get('database').getPouchId(null, this.get('modelName').camelize()); + return this.get('database').getMinPouchId(this.get('modelName').camelize()); }, _getPouchIdFromItem(item) { diff --git a/app/services/database.js b/app/services/database.js index 83854fe0d1..64383e489c 100644 --- a/app/services/database.js +++ b/app/services/database.js @@ -108,6 +108,24 @@ export default Ember.Service.extend(PouchAdapterUtils, { }); }, + /** + * Given an record type, return back the maximum pouchdb id. Useful for endkeys. + * @param {String} type the record type. + * @returns {String} the max pouch id for the type. + */ + getMaxPouchId(type) { + return this.getPouchId({}, type); + }, + + /** + * Given an record type, return back the minimum pouchdb id. Useful for startkeys. + * @param {String} type the record type. + * @returns {String} the min pouch id for the type. + */ + getMinPouchId(type) { + return this.getPouchId(null, type); + }, + /** * Given an Ember record id and type, return back the corresponding pouchDB id. * @param {String} emberId the ember record id.