Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fixed patient ids not sequencing properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkleinsc committed Dec 9, 2016
1 parent 48abb38 commit d2004bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/mixins/charge-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 2 additions & 4 deletions app/mixins/patient-id.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions app/routes/abstract-index-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions app/services/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d2004bf

Please sign in to comment.