Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/opd-report
Browse files Browse the repository at this point in the history
  • Loading branch information
Chima1707 committed Feb 6, 2017
2 parents bf614b5 + 1107c53 commit 63f5571
Show file tree
Hide file tree
Showing 57 changed files with 709 additions and 180 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
'dymo': true,
'Filer': true,
'logDebug': true,
'moment': true,
'Pikaday': true,
'PouchDB': true,
'Promise': true,
Expand Down
43 changes: 39 additions & 4 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ember from 'ember';
import { Adapter } from 'ember-pouch';
import UnauthorizedError from 'hospitalrun/utils/unauthorized-error';
import PouchAdapterUtils from 'hospitalrun/mixins/pouch-adapter-utils';
import uuid from 'npm:uuid';

Expand Down Expand Up @@ -203,7 +204,7 @@ export default Adapter.extend(PouchAdapterUtils, {
};
db.list(`${mapReduce}/sort/${mapReduce}`, listParams, (err, response) => {
if (err) {
this._pouchError(reject)(err);
reject(this._handleErrorResponse(err));
} else {
let responseJSON = JSON.parse(response.body);
this._handleQueryResponse(responseJSON, store, type).then(resolve, reject);
Expand All @@ -212,7 +213,7 @@ export default Adapter.extend(PouchAdapterUtils, {
} else {
db.query(mapReduce, queryParams, (err, response) => {
if (err) {
this._pouchError(reject)(err);
reject(this._handleErrorResponse(err));
} else {
this._handleQueryResponse(response, store, type).then(resolve, reject);
}
Expand All @@ -221,16 +222,50 @@ export default Adapter.extend(PouchAdapterUtils, {
} else {
db.allDocs(queryParams, (err, response) => {
if (err) {
this._pouchError(reject)(err);
reject(this._handleErrorResponse(err));
} else {
this._handleQueryResponse(response, store, type).then(resolve, reject);
}
});
}
} catch(err) {
this._pouchError(reject)(err);
reject(this._handleErrorResponse(err));
}
}, 'findQuery in application-pouchdb-adapter');
}
},

createRecord(store, type, record) {
return new Ember.RSVP.Promise((resolve, reject) => {
this._super(store, type, record).then(resolve, (err) => {
reject(this._handleErrorResponse(err));
});
});
},

updateRecord(store, type, record) {
return new Ember.RSVP.Promise((resolve, reject) => {
this._super(store, type, record).then(resolve, (err) => {
reject(this._handleErrorResponse(err));
});
});
},

deleteRecord(store, type, record) {
return new Ember.RSVP.Promise((resolve, reject) => {
this._super(store, type, record).then(resolve, (err) => {
reject(this._handleErrorResponse(err));
});
});
},

_handleErrorResponse(err) {
if (err.status) {
let detailedMessage = JSON.stringify(err, null, 2);
return new UnauthorizedError(err, detailedMessage);
} else {
return err;
}
}

});
112 changes: 112 additions & 0 deletions app/appointments/calendar/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import AppointmentIndexController from 'hospitalrun/appointments/index/controller';
import AppointmentStatuses from 'hospitalrun/mixins/appointment-statuses';
import moment from 'moment';
import VisitTypes from 'hospitalrun/mixins/visit-types';
import SelectValues from 'hospitalrun/utils/select-values';
import Ember from 'ember';

const {
computed,
computed: {
alias
},
get,
inject,
isEmpty,
set
} = Ember;

export default AppointmentIndexController.extend(AppointmentStatuses, VisitTypes, {
appointmentType: null,
endDate: null,
location: null,
provider: null,
queryParams: ['appointmentType', 'endDate', 'provider', 'status', 'startDate', 'location', 'viewType'],
startDate: null,
status: null,
viewType: 'agendaWeek',

appointmentsController: inject.controller('appointments'),
locations: alias('appointmentsController.locationList.value'),
physicians: alias('appointmentsController.physicianList.value'),

calendarDate: computed('startDate', function() {
let startDate = get(this, 'startDate');
if (!isEmpty(startDate)) {
return moment(parseInt(startDate));
}
}),

locationList: computed('locations', function() {
return SelectValues.selectValues(get(this, 'locations'), true);
}),

physicianList: computed('physicians', function() {
return SelectValues.selectValues(get(this, 'physicians'), true);
}),

_getSelectedFilteringCriteria() {
let rawCriteria = {
status: get(this, 'model.selectedStatus'),
type: get(this, 'model.selectedAppointmentType'),
provider: get(this, 'model.selectedProvider'),
location: get(this, 'model.selectedLocation')
};

return {
status: isEmpty(rawCriteria.status) ? null : rawCriteria.status,
type: isEmpty(rawCriteria.type) ? null : rawCriteria.type,
provider: isEmpty(rawCriteria.provider) ? null : rawCriteria.provider,
location: isEmpty(rawCriteria.location) ? null : rawCriteria.location
};
},

actions: {
clearFilteringCriteria() {
set(this, 'model.selectedStatus', null);
set(this, 'model.selectedAppointmentType', null);
set(this, 'model.selectedProvider', null);
set(this, 'model.selectedLocation', null);
this.send('filter');
},

createNewAppointment(dateClicked) {
let newAppointment = this.store.createRecord('appointment', {
appointmentType: 'Admission',
allDay: false,
selectPatient: true,
startDate: dateClicked.local().toDate()
});
this.send('editAppointment', newAppointment);
},

filter() {
let criteria = this._getSelectedFilteringCriteria();
this.setProperties({
appointmentType: criteria.type,
provider: criteria.provider,
status: criteria.status,
location: criteria.location
});
},

handleVisualConfigurationChanged(newConfiguration) {
this.setProperties(newConfiguration);
},

navigateToAppointment(calendarEvent) {
this.send('editAppointment', calendarEvent.referencedAppointment);
},

updateAppointment(calendarEvent) {
let appointmentToUpdate = calendarEvent.referencedAppointment;
let newEnd = calendarEvent.end.local().toDate();
let newStart = calendarEvent.start.local().toDate();
set(appointmentToUpdate, 'startDate', newStart);
set(appointmentToUpdate, 'endDate', newEnd);
appointmentToUpdate.save().catch((error) => {
this.send('error', error, 'appointments.calendar');
});
}
}
});
79 changes: 79 additions & 0 deletions app/appointments/calendar/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import AppointmentIndexRoute from 'hospitalrun/appointments/index/route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';

const {
get,
isEmpty
} = Ember;

export default AppointmentIndexRoute.extend({

dateIntervalEnd: null,
dateIntervalStart: null,
editReturn: 'appointments.calendar',
filterParams: ['appointmentType', 'provider', 'status', 'location'],
modelName: 'appointment',
pageTitle: t('appointments.calendarTitle'),

queryParams: {
appointmentType: { refreshModel: true },
endDate: { refreshModel: true },
provider: { refreshModel: true },
status: { refreshModel: true },
startDate: { refreshModel: true },
location: { refreshModel: true },
viewType: { refreshModel: false }
},

model(params) {
function createCalendarEvent(appointment) {
let title = get(appointment, 'patient.displayName');
let provider = get(appointment, 'provider');
if (!isEmpty(provider)) {
title = `${title}\n${provider}`;
}
return {
allDay: get(appointment, 'allDay'),
title,
start: get(appointment, 'startDate'),
end: get(appointment, 'endDate'),
referencedAppointment: appointment
};
}

function createCalendarEvents(appointments) {
return appointments.map(createCalendarEvent);
}

return this._super(params)
.then(createCalendarEvents)
.then(function(calendarEvents) {
return {
events: calendarEvents,
selectedAppointmentType: params.appointmentType,
selectedProvider: params.provider,
selectedStatus: params.status,
selectedLocation: params.location
};
});
},

_modelQueryParams(params) {
let { endDate, startDate } = params;

if (endDate === null || startDate === null) {
return this._super(params);
}
let maxValue = get(this, 'maxValue');
let searchOptions = {
startkey: [parseInt(startDate), null, this._getMinPouchId()],
endkey: [parseInt(endDate), maxValue, this._getMaxPouchId()]
};

return {
options: searchOptions,
mapReduce: 'appointments_by_date'
};
}
});
42 changes: 42 additions & 0 deletions app/appointments/calendar/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="panel panel-info">
<div class="panel-body">
{{#em-form model=model submitButton=false}}
<div class="row">
{{em-select class="col-sm-3 form-input-group"
label=(t "labels.status")
property="selectedStatus"
content=appointmentStatusesWithEmpty
}}
{{em-select class="col-sm-3 form-input-group"
label=(t "labels.type")
property="selectedAppointmentType"
content=visitTypesWithEmpty
}}
{{em-select class="col-sm-3 form-input-group"
label=(t 'labels.with')
property="selectedProvider"
content=physicianList
}}
{{em-select class="col-sm-3 form-input-group"
label=(t 'labels.location')
property="selectedLocation"
content=locationList
}}
</div>
{{/em-form}}
<div class="panel-footer">
<button class="btn btn-default warning" {{action 'clearFilteringCriteria'}}>{{t 'buttons.clear'}}</button>
<button class="btn btn-default" {{action 'filter'}}>{{t 'buttons.filter'}}</button>
</div>
{{calendar-control events=model.events
defaultDate=calendarDate
defaultView=viewType
onDayClick=(action "createNewAppointment")
onEventClick=(action "navigateToAppointment")
onEventDrop=(action "updateAppointment")
onEventResize=(action "updateAppointment")
onVisualConfigurationChanged=(action "handleVisualConfigurationChanged")
userCanEdit=canEdit
}}
</div>
</div>
2 changes: 1 addition & 1 deletion app/appointments/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{else}}
{{date-time-picker datePickerClass="required test-appointment-date" label=(t 'labels.date') model=model}}
{{/if}}
{{em-checkbox label=(t 'labels.allDay') property="allDay" class="col-sm-2"}}
{{em-checkbox label=(t 'labels.allDay') property="allDay" class="col-sm-2 appointment-all-day"}}
</div>
<div class="row">
<div class="form-input-group col-sm-6 required test-appointment-type">
Expand Down
1 change: 1 addition & 0 deletions app/appointments/index/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AbstractIndexRoute from 'hospitalrun/routes/abstract-index-route';
import moment from 'moment';
import { translationMacro as t } from 'ember-i18n';

export default AbstractIndexRoute.extend({
Expand Down
1 change: 1 addition & 0 deletions app/appointments/search/route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AppointmentIndexRoute from 'hospitalrun/appointments/index/route';
import DateFormat from 'hospitalrun/mixins/date-format';
import Ember from 'ember';
import moment from 'moment';
import { translationMacro as t } from 'ember-i18n';

export default AppointmentIndexRoute.extend(DateFormat, {
Expand Down
8 changes: 3 additions & 5 deletions app/appointments/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
{{#em-form model=model submitButton=false }}
<div class="row">
{{date-picker property="selectedStartingDate" label=(t "appointments.labels.selectedStartingDate")class="col-sm-3"}}
{{em-select class="col-sm-3" property="selectedStatus"
{{em-select class="col-sm-3 form-input-group" property="selectedStatus"
label=(t "labels.status") content=appointmentStatusesWithEmpty
}}
</div>
<div class="row">
{{em-select class="col-sm-3" label=(t "labels.type")
{{em-select class="col-sm-3 form-input-group" label=(t "labels.type")
property="selectedAppointmentType" content=visitTypesWithEmpty
}}
{{em-select class="col-sm-3" property="selectedProvider"
{{em-select class="col-sm-3 form-input-group" property="selectedProvider"
label=(t 'labels.with') content=physicianList
}}
</div>
Expand Down
1 change: 1 addition & 0 deletions app/appointments/today/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppointmentIndexRoute from 'hospitalrun/appointments/index/route';
import moment from 'moment';
import { translationMacro as t } from 'ember-i18n';
export default AppointmentIndexRoute.extend({
editReturn: 'appointments.today',
Expand Down
Loading

0 comments on commit 63f5571

Please sign in to comment.