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

Commit

Permalink
Added filters to outpatient screen
Browse files Browse the repository at this point in the history
Resolves #860
Also, fixed outpatient screen to no longer display admission type
visits.
  • Loading branch information
jkleinsc committed Dec 19, 2016
1 parent 502ed85 commit 1db6309
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 18 deletions.
3 changes: 2 additions & 1 deletion app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,8 @@ export default {
totalPatientDays: 'Total Patient Days',
totalPatientDaysDetailed: 'Total Patient Days (Detailed)',
visit: 'Visit',
deletePatientRecord: 'Delete Patient Record'
deletePatientRecord: 'Delete Patient Record',
outpatientsForDate: 'Outpatients for {{visitDate}}'
},
messages: {
areYouSureDelete: 'Are you sure you want to delete this {{object}}?',
Expand Down
22 changes: 16 additions & 6 deletions app/mixins/filter-list.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import Ember from 'ember';

const {
isEmpty,
String: {
isHTMLSafe
}
} = Ember;

export default Ember.Mixin.create({
filteredBy: new Ember.Map(),

filterList(list, filterBy, filterValue) {
if (Ember.isEmpty(filterBy)) {
let filteredBy = this.get('filteredBy');
if (isEmpty(filterBy) && isEmpty(filteredBy)) {
return list;
}
let filteredBy = this.get('filteredBy');
filteredBy.set(filterBy, filterValue);
if (!isEmpty(filterBy)) {
filteredBy.set(filterBy, filterValue);
}
this.set('filteredBy', filteredBy);
let filteredList = list.filter((order) => {
let includeRecord = true;
filteredBy.forEach((filterValue, filterBy) => {
let orderValue = order.get(filterBy);
if (!Ember.isEmpty(filterValue)) {
if (Ember.String.isHTMLSafe(filterValue)) {
if (!isEmpty(filterValue)) {
if (isHTMLSafe(filterValue)) {
filterValue = filterValue.toString();
}
if (Ember.String.isHTMLSafe(orderValue)) {
if (isHTMLSafe(orderValue)) {
orderValue = orderValue.toString();
}
if (orderValue !== filterValue) {
Expand Down
37 changes: 33 additions & 4 deletions app/patients/outpatient/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ import Ember from 'ember';
import FilterList from 'hospitalrun/mixins/filter-list';
import ModalHelper from 'hospitalrun/mixins/modal-helper';
import PatientVisits from 'hospitalrun/mixins/patient-visits';
import SelectValues from 'hospitalrun/utils/select-values';
import UserSession from 'hospitalrun/mixins/user-session';
import VisitTypes from 'hospitalrun/mixins/visit-types';

const { computed } = Ember;
const {
computed,
isEmpty
} = Ember;

export default Ember.Controller.extend(FilterList, ModalHelper, PatientVisits, UserSession, VisitTypes, {
export default Ember.Controller.extend(FilterList, ModalHelper, PatientVisits, SelectValues, UserSession, VisitTypes, {
addPermission: 'add_patient',
deletePermission: 'delete_patient',
filterValue: null,
filterBy: null,
queryParams: ['visitDate', 'visitLocation'],
sortByDesc: null,
sortByKey: null,
visitLocation: null,
visitDate: null,
canAddVisit: computed(function() {
return this.currentUserCan('add_visit');
}),
Expand All @@ -31,6 +38,7 @@ export default Ember.Controller.extend(FilterList, ModalHelper, PatientVisits,
i18n.t('visits.labels.haveDoneOrders')
];
}),
locationList: Ember.computed.map('patientController.locationList.value', SelectValues.selectValuesMap),
patientNames: computed.map('model', function(visit) {
return visit.get('patient.shortDisplayName');
}),
Expand All @@ -42,13 +50,20 @@ export default Ember.Controller.extend(FilterList, ModalHelper, PatientVisits,
}),

checkedInVisits: computed.filter('[email protected]', function(visit) {
return visit.get('status') !== 'checkedOut';
return visit.get('visitType') !== 'Admission' && visit.get('status') !== 'checkedOut';
}),

filteredVisits: computed('checkedInVisits', 'filterBy', 'filterValue', function() {
filteredVisits: computed('checkedInVisits', 'filterBy', 'filterValue', 'visitLocation', function() {
let filterBy = this.get('filterBy');
let filterValue = this.get('filterValue');
let filteredBy = this.get('filteredBy');
let visitLocation = this.get('visitLocation');
let visits = this.get('checkedInVisits');
if (isEmpty(visitLocation)) {
filteredBy.delete('location');
} else {
filteredBy.set('location', visitLocation);
}
return this.filterList(visits, filterBy, filterValue);
}),

Expand Down Expand Up @@ -107,6 +122,20 @@ export default Ember.Controller.extend(FilterList, ModalHelper, PatientVisits,
});
},

search() {
let visitDate = this.get('model.selectedVisitDate');
let visitLocation = this.get('model.selectedLocation');
if (!isEmpty(visitDate)) {
this.set('visitDate', visitDate.getTime());
}
if (isEmpty(visitLocation)) {
this.set('visitLocation', null);
} else {
this.set('visitLocation', visitLocation);
}

},

sortByKey(sortKey, sortDesc) {
this.setProperties({
sortByDesc: sortDesc,
Expand Down
67 changes: 60 additions & 7 deletions app/patients/outpatient/route.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,82 @@
import AbstractIndexRoute from 'hospitalrun/routes/abstract-index-route';
import DateFormat from 'hospitalrun/mixins/date-format';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';

export default AbstractIndexRoute.extend({
const {
computed,
isEmpty
} = Ember;

export default AbstractIndexRoute.extend(DateFormat, {
database: Ember.inject.service(),
modelName: 'visit',
newButtonAction: 'patientCheckIn',
newButtonText: t('patients.buttons.patientCheckIn'),
pageTitle: t('patients.titles.todaysOutpatients'),
selectedVisitDate: null,
showingTodaysPatients: true,
pageTitle: computed('showingTodaysPatients', 'selectedVisitDate', function() {
let i18n = this.get('i18n');
let showingTodaysPatients = this.get('showingTodaysPatients');
if (showingTodaysPatients) {
return i18n.t('patients.titles.todaysOutpatients');
} else {
let selectedVisitDate = this._dateFormat(this.get('selectedVisitDate'));
return i18n.t('patients.titles.outpatientsForDate', { visitDate: selectedVisitDate });
}
}),

queryParams: {
visitDate: { refreshModel: true },
visitLocation: { refreshModel: false }
},

_getStartKeyFromItem(item) {
let displayPatientId = item.get('displayPatientId');
return [displayPatientId, `patient_${item.get('id')}`];
},

_modelQueryParams() {
let endOfDay = moment().endOf('day').valueOf();
let startOfDay = moment().startOf('day').valueOf();
_modelQueryParams(params) {
let database = this.get('database');
let maxId = database.getMaxPouchId('visit');
let minId = database.getMaxPouchId('visit');
let { visitDate } = params;
if (isEmpty(visitDate)) {
visitDate = moment();
} else {
visitDate = moment(parseInt(visitDate));
}
if (visitDate.isSame(moment(), 'day')) {
this.set('showingTodaysPatients', true);
} else {
this.set('showingTodaysPatients', false);
this.set('selectedVisitDate', visitDate.toDate());
}
let endOfDay = visitDate.endOf('day').valueOf();
let startOfDay = visitDate.startOf('day').valueOf();

return {
mapReduce: 'visit_by_date',
options: {
endkey: [endOfDay, endOfDay, this._getMaxPouchId()],
startkey: [startOfDay, null, this._getMinPouchId()]
endkey: [endOfDay, endOfDay, maxId],
startkey: [startOfDay, null, minId]
}
};
},

model(params) {
return this._super(params).then((model) => {
let visitDate = new Date();
if (!isEmpty(params.visitDate)) {
visitDate.setTime(params.visitDate);
}
model.set('selectedVisitDate', visitDate);
model.set('display_selectedVisitDate', this._dateFormat(visitDate));
model.set('selectedLocation', params.visitLocation);
return model;
});
},

actions: {
finishCheckOut(visit) {
this.controller.send('finishCheckOut', visit);
Expand Down
15 changes: 15 additions & 0 deletions app/patients/outpatient/template.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
{{#item-listing paginationProps=paginationProps }}
<div class="panel panel-info">
<div class="panel-body">
{{#em-form model=model submitButton=false }}
<div class="row">
{{date-picker property="selectedVisitDate" label=(t "visits.labels.visitDate")class="col-sm-3"}}
{{em-select class="col-sm-3 form-input-group" property="selectedLocation"
label=(t "labels.location") content=locationList prompt=" "
}}
</div>
{{/em-form}}
</div>
<div class="panel-footer">
<button class="btn btn-default" {{action 'search'}}>{{t 'buttons.search'}}</button>
</div>
</div>
<table class="table">
<thead>
<tr class="table-header">
Expand Down

0 comments on commit 1db6309

Please sign in to comment.