Skip to content

Commit

Permalink
Merge pull request #20 from eHealthAfrica/fix-new-route
Browse files Browse the repository at this point in the history
URL Navigation Fix
  • Loading branch information
Chima Alaebo authored Feb 27, 2017
2 parents 74f1819 + 67670f6 commit 4de70c2
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 42 deletions.
19 changes: 15 additions & 4 deletions app/appointments/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatient from 'hospitalrun/mixins/add-to-patient-route';
import Ember from 'ember';
import moment from 'moment';
import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
import { translationMacro as t } from 'ember-i18n';

const {
get,
isEmpty,
RSVP: {
resolve
}
} = Ember;

export default AbstractEditRoute.extend(PatientListRoute, {
export default AbstractEditRoute.extend(AddToPatient, PatientListRoute, {
editTitle: t('appointments.editTitle'),
modelName: 'appointment',
newButtonText: t('appointments.buttons.newButton'),
Expand All @@ -26,7 +28,7 @@ export default AbstractEditRoute.extend(PatientListRoute, {
selectPatient: true,
startDate: new Date()
};
if (!Ember.isEmpty(idParam) && params[idParam] === 'newsurgery') {
if (!isEmpty(idParam) && params[idParam] === 'newsurgery') {
newData.appointmentType = 'Surgery';
newData.allDay = false;
newData.endDate = moment().add('1', 'hours').toDate();
Expand All @@ -53,10 +55,19 @@ export default AbstractEditRoute.extend(PatientListRoute, {
model(params) {
let idParam = this.get('idParam');
let modelId = params[idParam];
if (!Ember.isEmpty(idParam) && (modelId.indexOf('new') === 0)) {
return this._createNewRecord(params);
if (!isEmpty(idParam) && (modelId.indexOf('new') === 0)) {
if (!isEmpty(params.forPatientId)) {
let modelPromise = this._super(params);
return this._setPatientOnModel(modelPromise, params.forPatientId);
} else if (!isEmpty(params.forVisitId)) {
let modelPromise = this._super(params);
return this._setVisitOnModel(modelPromise, params.forVisitId);
} else {
return this._createNewRecord(params);
}
} else {
return this._super(params);
}
}

});
3 changes: 2 additions & 1 deletion app/imaging/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { translationMacro as t } from 'ember-i18n';
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import ChargeRoute from 'hospitalrun/mixins/charge-route';
import Ember from 'ember';
import moment from 'moment';
import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, {
export default AbstractEditRoute.extend(AddToPatientRoute, ChargeRoute, PatientListRoute, {
editTitle: t('imaging.titles.editTitle'),
modelName: 'imaging',
newTitle: t('imaging.titles.editTitle'),
Expand Down
5 changes: 3 additions & 2 deletions app/labs/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Ember from 'ember';
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import ChargeRoute from 'hospitalrun/mixins/charge-route';
import Ember from 'ember';
import moment from 'moment';
import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
import { translationMacro as t } from 'ember-i18n';

export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, {
export default AbstractEditRoute.extend(AddToPatientRoute, ChargeRoute, PatientListRoute, {
editTitle: t('labs.editTitle'),
modelName: 'lab',
newTitle: t('labs.newTitle'),
Expand Down
15 changes: 13 additions & 2 deletions app/medication/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { translationMacro as t } from 'ember-i18n';
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import Ember from 'ember';
import FulfillRequest from 'hospitalrun/mixins/fulfill-request';
import InventoryLocations from 'hospitalrun/mixins/inventory-locations'; // inventory-locations mixin is needed for fulfill-request mixin!
import moment from 'moment';
import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
import uuid from 'npm:uuid';
export default AbstractEditRoute.extend(FulfillRequest, InventoryLocations, PatientListRoute, {

const { isEmpty } = Ember;

export default AbstractEditRoute.extend(AddToPatientRoute, FulfillRequest, InventoryLocations, PatientListRoute, {
editTitle: t('medication.titles.editMedicationRequest'),
modelName: 'medication',
newTitle: t('medication.titles.newMedicationRequest'),
Expand All @@ -27,8 +31,15 @@ export default AbstractEditRoute.extend(FulfillRequest, InventoryLocations, Pati

model(params) {
let idParam = this.get('idParam');
let modelPromise = this._super(params);
if (!Ember.isEmpty(idParam) && params[idParam] === 'new' || params[idParam] === 'dispense') {
return this._createNewRecord(params);
if (!isEmpty(params.forPatientId)) {
return this._setPatientOnModel(modelPromise, params.forPatientId);
} else if (!isEmpty(params.forVisitId)) {
return this._setVisitOnModel(modelPromise, params.forVisitId);
} else {
return this._createNewRecord(params);
}
} else {
return this._super(params);
}
Expand Down
61 changes: 61 additions & 0 deletions app/mixins/add-to-patient-route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Ember from 'ember';

const { get, isEmpty, Mixin } = Ember;

export default Mixin.create({
queryParams: {
forPatientId: {
refreshModel: false
},
forVisitId: {
refreshModel: false
}
},

model(params) {
let idParam = get(this, 'idParam');
let modelPromise = this._super(params);
if (params[idParam] === 'new') {
if (!isEmpty(params.forPatientId)) {
return this._setPatientOnModel(modelPromise, params.forPatientId);
} else if (!isEmpty(params.forVisitId)) {
return this._setVisitOnModel(modelPromise, params.forVisitId);
} else {
return this._createNewRecord(params);
}
} else {
return modelPromise;
}
},

/**
* Resolves the model promise and then sets the patient information on the model.
*/
_setPatientOnModel(modelPromise, patientId) {
let store = get(this, 'store');
return modelPromise.then((model) => {
return store.find('patient', patientId).then((patient) => {
model.set('patient', patient);
model.set('returnToPatient', patientId);
model.set('selectPatient', false);
return model;
});
});
},

/**
* Resolves the model promise and then sets the visit information on the model.
*/
_setVisitOnModel(modelPromise, visitId) {
let store = get(this, 'store');
return modelPromise.then((model) => {
return store.find('visit', visitId).then((visit) => {
model.set('visit', visit);
model.set('returnToVisit', visitId);
model.set('selectPatient', false);
model.set('patient', visit.get('patient'));
return model;
});
});
}
});
14 changes: 7 additions & 7 deletions app/patients/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,16 @@ export default AbstractEditController.extend(BloodTypes, DiagnosisActions, Retur
},

_addChildObject(route, afterTransition) {
this.transitionToRoute(route, 'new').then(function(newRoute) {
newRoute.currentModel.setProperties({
patient: this.get('model'),
returnToPatient: this.get('model.id'),
selectPatient: false
});
let options = {
queryParams: {
forPatientId: this.get('model.id')
}
};
this.transitionToRoute(route, 'new', options).then((newRoute) => {
if (afterTransition) {
afterTransition(newRoute);
}
}.bind(this));
});
},

_showEditSocial(editAttributes, modelName, route) {
Expand Down
3 changes: 2 additions & 1 deletion app/patients/operative-plan/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import Ember from 'ember';
import moment from 'moment';
import { translationMacro as t } from 'ember-i18n';
Expand All @@ -8,7 +9,7 @@ const {
inject
} = Ember;

export default AbstractEditRoute.extend({
export default AbstractEditRoute.extend(AddToPatientRoute, {
editTitle: t('operativePlan.titles.editTitle'),
modelName: 'operative-plan',
newTitle: t('operativePlan.titles.newTitle'),
Expand Down
3 changes: 2 additions & 1 deletion app/procedures/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatient from 'hospitalrun/mixins/add-to-patient-route';
import ChargeRoute from 'hospitalrun/mixins/charge-route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';

export default AbstractEditRoute.extend(ChargeRoute, {
export default AbstractEditRoute.extend(AddToPatient, ChargeRoute, {
editTitle: t('procedures.titles.edit'),
modelName: 'procedure',
newTitle: t('procedures.titles.new'),
Expand Down
20 changes: 8 additions & 12 deletions app/reports/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';

export default AbstractEditRoute.extend({
export default AbstractEditRoute.extend(AddToPatientRoute, {
modelName: 'report',
customForms: Ember.inject.service(),

Expand All @@ -15,23 +16,18 @@ export default AbstractEditRoute.extend({
return customForms.setDefaultCustomForms(['opdReport', 'dischargeReport'], newReportData);
},

afterModel(model) {
if (model.get('isNew')) {
let visit = this.modelFor('visits.edit');
if (!visit) {
return this.transitionTo('patients');
}
model.set('visit', visit);
}
model.setProperties({ returnToVisit: model.get('visit.id') });
},

getScreenTitle(model) {
let state = model.get('isNew') ? 'new' : 'edit';
let type = model.get('visit.outPatient') ? 'opd' : 'discharge';
return t(`reports.${type}.titles.${state}`);
},

afterModel(model) {
if (!model.get('visit')) {
return this.transitionTo('patients');
}
},

setupController(controller, model) {
this._super(controller, model);
}
Expand Down
15 changes: 7 additions & 8 deletions app/visits/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,16 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
}.property('visitTypes', 'model.outPatient'),

_addChildObject(route, afterTransition) {
this.transitionToRoute(route, 'new').then(function(newRoute) {
newRoute.currentModel.setProperties({
patient: this.get('model.patient'),
visit: this.get('model'),
selectPatient: false,
returnToVisit: this.get('model.id')
});
let options = {
queryParams: {
forVisitId: this.get('model.id')
}
};
this.transitionToRoute(route, 'new', options).then((newRoute) => {
if (afterTransition) {
afterTransition(newRoute);
}
}.bind(this));
});
},

_finishAfterUpdate() {
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/operative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('Plan and report creation', function(assert) {
waitToAppear('span.secondary-diagnosis:contains(Tennis Elbow)');
});
andThen(() =>{
assert.equal(currentURL(), '/patients/operative-plan/new', 'New operative plan URL is correct');
assert.equal(currentURL(), '/patients/operative-plan/new?forPatientId=C87BFCB2-F772-7A7B-8FC7-AD00C018C32A', 'New operative plan URL is correct');
assert.equal(find('.patient-name .ps-info-data').text(), 'Joe Bagadonuts', 'Joe Bagadonuts patient header displays');
assert.equal(find('.view-current-title').text(), 'New Operative Plan', 'New operative plan title is correct');
assert.equal(find('span.primary-diagnosis:contains(Broken Arm)').length, 1, 'Primary diagnosis appears as read only');
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/visit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ test('Edit visit', function(assert) {
click('button:contains(New Medication)');
});
andThen(function() {
assert.equal(currentURL(), '/medication/edit/new', 'New medication url is correct');
assert.equal(currentURL(), '/medication/edit/new?forVisitId=03C7BF8B-04E0-DD9E-9469-96A5604F5340', 'New medication url is correct');
assert.equal(find('.patient-name .ps-info-data').text(), 'Joe Bagadonuts', 'New medication prepopulates with patient');
click('button:contains(Cancel)');
});
andThen(function() {
click('button:contains(New Lab)');
});
andThen(function() {
assert.equal(currentURL(), '/labs/edit/new', 'New lab url is correct');
assert.equal(currentURL(), '/labs/edit/new?forVisitId=03C7BF8B-04E0-DD9E-9469-96A5604F5340', 'New lab url is correct');
assert.equal(find('.patient-name .ps-info-data').text(), 'Joe Bagadonuts', 'New lab prepopulates with patient');
click('button:contains(Cancel)');
});
andThen(function() {
click('button:contains(New Imaging)');
});
andThen(function() {
assert.equal(currentURL(), '/imaging/edit/new', 'New imaging url is correct');
assert.equal(currentURL(), '/imaging/edit/new?forVisitId=03C7BF8B-04E0-DD9E-9469-96A5604F5340', 'New imaging url is correct');
assert.equal(find('.patient-name .ps-info-data').text(), 'Joe Bagadonuts', 'New imaging prepopulates with patient');
click('button:contains(Cancel)');
});
Expand Down

0 comments on commit 4de70c2

Please sign in to comment.