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

Commit

Permalink
Fixed paging on patients
Browse files Browse the repository at this point in the history
Fixes #628
  • Loading branch information
jkleinsc committed Aug 23, 2016
1 parent bbe0a13 commit 879d352
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
1 change: 1 addition & 0 deletions app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ export default {
socialWork: 'Social Work'
},
titles: {
admittedPatients: 'Admitted Patients',
expenses: 'Expenses',
additionalContacts: 'Additional Contacts',
familyInformation: 'Family Information',
Expand Down
16 changes: 4 additions & 12 deletions app/patients/admitted/route.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import AbstractIndexRoute from 'hospitalrun/routes/abstract-index-route';
export default AbstractIndexRoute.extend({
modelName: 'patient',
pageTitle: 'Admitted patients',

_getStartKeyFromItem: function(item) {
var displayPatientId = item.get('displayPatientId');
return [displayPatientId, 'patient_' + item.get('id')];
},
import { translationMacro as t } from 'ember-i18n';
import PatientsIndexRoute from 'hospitalrun/patients/index/route';
export default PatientsIndexRoute.extend({
pageTitle: t('patients.titles.admittedPatients'),

_modelQueryParams: function() {
return {
options: {
key: true
},
mapReduce: 'patient_by_admission'
};
}
Expand Down
3 changes: 2 additions & 1 deletion app/patients/index/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default AbstractIndexRoute.extend({

_getStartKeyFromItem: function(item) {
var displayPatientId = item.get('displayPatientId');
return [displayPatientId, 'patient_' + item.get('id')];
var id = this._getPouchIdFromItem(item);
return [displayPatientId, id];
},

_modelQueryParams: function() {
Expand Down
67 changes: 36 additions & 31 deletions app/utils/pouch-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,35 @@ function generateDateForView(date1) {

}

var patientListingKey = 'if (doc.data.friendlyId) {' +
'emit([doc.data.friendlyId, doc._id]);' +
'} else if (doc.data.externalPatientId) {' +
'emit([doc.data.externalPatientId, doc._id]);' +
'} else {' +
'emit([doc._id, doc._id]);' +
'}';

var patientListingSearch = generateSortFunction(function(a, b) {
var sortBy = '';
if (req.query && req.query.sortKey) {
sortBy = req.query.sortKey;
}
switch (sortBy) {
case 'firstName':
case 'sex':
case 'lastName':
case 'status': {
return compareStrings(a.doc.data[sortBy], b.doc.data[sortBy]);
}
case 'dateOfBirth': {
return getCompareDate(a.doc.data.dateOfBirth) - getCompareDate(b.doc.data.dateOfBirth);
}
default: {
return 0; // Don't sort
}
}
}.toString(), true);

var designDocs = [{
name: 'appointments_by_date',
function: generateView('appointment',
Expand Down Expand Up @@ -288,35 +317,8 @@ var designDocs = [{
version: 3
}, {
name: 'patient_by_display_id',
function: generateView('patient',
'if (doc.data.friendlyId) {' +
'emit([doc.data.friendlyId, doc._id]);' +
'} else if (doc.data.externalPatientId) {' +
'emit([doc.data.externalPatientId, doc._id]);' +
'} else {' +
'emit([doc._id, doc._id]);' +
'}'
),
sort: generateSortFunction(function(a, b) {
var sortBy = '';
if (req.query && req.query.sortKey) {
sortBy = req.query.sortKey;
}
switch (sortBy) {
case 'firstName':
case 'sex':
case 'lastName':
case 'status': {
return compareStrings(a.doc.data[sortBy], b.doc.data[sortBy]);
}
case 'dateOfBirth': {
return getCompareDate(a.doc.data.dateOfBirth) - getCompareDate(b.doc.data.dateOfBirth);
}
default: {
return 0; // Don't sort
}
}
}.toString(), true),
function: generateView('patient', patientListingKey),
sort: patientListingSearch,
version: 5
}, {
name: 'patient_by_status',
Expand All @@ -327,9 +329,12 @@ var designDocs = [{
},{
name: 'patient_by_admission',
function: generateView('patient',
'emit(doc.data.admitted);'
'if(doc.data.admitted === true) {' +
patientListingKey +
'}'
),
version: 1
sort: patientListingSearch,
version: 2
}, {
name: 'photo_by_patient',
function: generateView('photo',
Expand Down

0 comments on commit 879d352

Please sign in to comment.