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

Commit

Permalink
Fixed deleting orders/sorting/filtering
Browse files Browse the repository at this point in the history
Fixes #886
  • Loading branch information
jkleinsc committed Dec 19, 2016
1 parent de0f4d0 commit 502ed85
Showing 1 changed file with 58 additions and 49 deletions.
107 changes: 58 additions & 49 deletions app/components/patient-orders.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import Ember from 'ember';
import FilterList from 'hospitalrun/mixins/filter-list';
import UserSession from 'hospitalrun/mixins/user-session';

const {
computed
} = Ember;

export default Ember.Component.extend(FilterList, UserSession, {
editImagingAction: 'editImaging',
editLabAction: 'editLab',
editMedicationAction: 'editMedication',
filterBy: null,
filterValue: null,
newImagingAction: 'newImaging',
newLabAction: 'newLab',
newMedicationAction: 'newMedication',
showDeleteImagingAction: 'showDeleteImaging',
showDeleteLabAction: 'showDeleteLab',
showDeleteMedicationAction: 'showDeleteMedication',
sortBy: null,
sortKey: null,
sortDesc: false,
orderTypeFilters: Ember.computed(function() {
Expand Down Expand Up @@ -47,17 +53,57 @@ export default Ember.Component.extend(FilterList, UserSession, {
return this.currentUserCan('delete_medication');
}),

sortedOrders: Ember.computed('filteredList', 'sortBy', 'sortDesc', function() {
filteredList: computed('orderList.[]', 'filterBy', 'filterValue', function() {
let filterBy = this.get('filterBy');
let filterValue = this.get('filterValue');
let orderList = this.get('orderList');
orderList = this.filterList(orderList, filterBy, filterValue);
return orderList;
}),

orderList: computed('visit.imaging.[]', 'visit.labs.[]', 'visit.medication.[]', function() {
let i18n = this.get('i18n');
let imaging = this.get('visit.imaging');
let labs = this.get('visit.labs');
let medication = this.get('visit.medication');
let orderList = new Ember.A();
orderList.addObjects(imaging.map((item) => {
item.set('orderType', i18n.t('components.patientOrders.labels.imagingOrderType'));
item.set('name', item.get('imagingType.name'));
item.set('dateProcessed', item.get('imagingDate'));
this._setPermissions(item, 'canAddImaging', 'canDeleteImaging');
return item;
}));
orderList.addObjects(labs.map((item) => {
item.set('orderType', i18n.t('components.patientOrders.labels.labOrderType'));
item.set('name', item.get('labType.name'));
item.set('dateProcessed', item.get('labDate'));
this._setPermissions(item, 'canAddLab', 'canDeleteLab');
return item;
}));
orderList.addObjects(medication.map((item) => {
item.set('orderType', i18n.t('components.patientOrders.labels.medicationOrderType'));
item.set('name', item.get('medicationName'));
item.set('dateProcessed', item.get('prescriptionDate'));
item.set('result', '');
item.set('notes', item.get('prescription'));
this._setPermissions(item, 'canAddMedication', 'canDeleteMedication');
return item;
}));
return orderList;
}),

sortedOrders: Ember.computed('filteredList', 'sortKey', 'sortDesc', function() {
let filteredList = this.get('filteredList');
let sortDesc = this.get('sortDesc');
let sortBy = this.get('sortBy');
if (Ember.isEmpty(filteredList) || Ember.isEmpty(sortBy)) {
let sortKey = this.get('sortKey');
if (Ember.isEmpty(filteredList) || Ember.isEmpty(sortKey)) {
return filteredList;
}
filteredList = filteredList.sort(function(a, b) {
let compareA = a.get(sortBy);
let compareB = b.get(sortBy);
if (sortBy === 'orderType') {
let compareA = a.get(sortKey);
let compareB = b.get(sortKey);
if (sortKey === 'orderType') {
compareA = compareA.toString();
compareB = compareB.toString();
}
Expand All @@ -67,50 +113,12 @@ export default Ember.Component.extend(FilterList, UserSession, {
return Ember.compare(compareA, compareB);
}
});
this.set('sortKey', sortBy);
return filteredList;
}),

i18n: Ember.inject.service(),
visit: null,

didReceiveAttrs() {
this._super(...arguments);
Ember.RSVP.hash({
imaging: this.get('visit.imaging'),
labs: this.get('visit.labs'),
medication: this.get('visit.medication')
}).then((results) => {
let orderList = new Ember.A();
let i18n = this.get('i18n');
orderList.addObjects(results.imaging.map((item) => {
item.set('orderType', i18n.t('components.patientOrders.labels.imagingOrderType'));
item.set('name', item.get('imagingType.name'));
item.set('dateProcessed', item.get('imagingDate'));
this._setPermissions(item, 'canAddImaging', 'canDeleteImaging');
return item;
}));
orderList.addObjects(results.labs.map((item) => {
item.set('orderType', i18n.t('components.patientOrders.labels.labOrderType'));
item.set('name', item.get('labType.name'));
item.set('dateProcessed', item.get('labDate'));
this._setPermissions(item, 'canAddLab', 'canDeleteLab');
return item;
}));
orderList.addObjects(results.medication.map((item) => {
item.set('orderType', i18n.t('components.patientOrders.labels.medicationOrderType'));
item.set('name', item.get('medicationName'));
item.set('dateProcessed', item.get('prescriptionDate'));
item.set('result', '');
item.set('notes', item.get('prescription'));
this._setPermissions(item, 'canAddMedication', 'canDeleteMedication');
return item;
}));
this.set('orderList', orderList);
this.set('filteredList', orderList);
});
},

_setPermissions(item, editPerm, deletePerm) {
if (item.get('canEdit')) {
if (this.get(editPerm)) {
Expand All @@ -124,9 +132,10 @@ export default Ember.Component.extend(FilterList, UserSession, {

actions: {
filter(filterBy, filterValue) {
let orderList = this.get('orderList');
orderList = this.filterList(orderList, filterBy, filterValue);
this.set('filteredList', orderList);
this.setProperties({
filterBy,
filterValue
});
},

newImaging() {
Expand All @@ -153,7 +162,7 @@ export default Ember.Component.extend(FilterList, UserSession, {

sortByKey(sortBy, sortDesc) {
this.setProperties({
sortBy,
sortKey: sortBy,
sortDesc
});
}
Expand Down

0 comments on commit 502ed85

Please sign in to comment.