diff --git a/app/allergy/edit/controller.js b/app/allergy/edit/controller.js
new file mode 100644
index 0000000000..6f2b51bb38
--- /dev/null
+++ b/app/allergy/edit/controller.js
@@ -0,0 +1,70 @@
+import Ember from 'ember';
+import AbstractEditController from 'hospitalrun/controllers/abstract-edit-controller';
+
+const {
+ computed,
+ computed: {
+ alias
+ },
+ get,
+ inject,
+ set
+} = Ember;
+
+export default AbstractEditController.extend({
+ i18n: inject.service(),
+ editController: alias('model.editController'),
+ newAllergy: false,
+
+ additionalButtons: computed('model.isNew', function() {
+ let model = get(this, 'model');
+ let btn = get(this, 'i18n').t('buttons.delete');
+ let isNew = get(model, 'isNew');
+ if (!isNew) {
+ return [{
+ class: 'btn btn-default warning',
+ buttonAction: 'deleteAllergy',
+ buttonIcon: 'octicon octicon-x',
+ buttonText: btn
+ }];
+ }
+ }),
+
+ title: Ember.computed('model', function() {
+ let model = get(this, 'model');
+ let i18n = get(this, 'i18n');
+ let isNew = get(model, 'isNew');
+ if (!isNew) {
+ return i18n.t('allergies.titles.editAllergy');
+ } else {
+ return i18n.t('allergies.titles.addAllergy');
+ }
+ }),
+
+ beforeUpdate() {
+ let allergy = get(this, 'model');
+ set(this, 'newAllergy', get(allergy, 'isNew'));
+ return Ember.RSVP.Promise.resolve();
+ },
+
+ afterUpdate(allergy) {
+ let newAllergy = get(this, 'newAllergy');
+ if (newAllergy) {
+ get(this, 'editController').send('addAllergy', allergy);
+ set(this, 'name', '');
+ } else {
+ this.send('closeModal');
+ }
+ },
+
+ actions: {
+ cancel() {
+ this.send('closeModal');
+ },
+
+ deleteAllergy() {
+ let allergy = get(this, 'model');
+ get(this, 'editController').send('deleteAllergy', allergy);
+ }
+ }
+});
diff --git a/app/allergy/edit/template.hbs b/app/allergy/edit/template.hbs
new file mode 100644
index 0000000000..11be41972c
--- /dev/null
+++ b/app/allergy/edit/template.hbs
@@ -0,0 +1,16 @@
+{{#modal-dialog
+ title=title
+ updateButtonText=updateButtonText
+ hideCancelButton=true
+ isUpdateDisabled=isUpdateDisabled
+ updateButtonAction=updateButtonAction
+ additionalButtons=additionalButtons
+}}
+
+ {{#em-form model=model submitButton=false }}
+
+ {{em-input class="col-xs-12 form-group required test-allergy" label=(t 'allergies.labels.allergyName') property="name"}}
+
+ {{/em-form}}
+
+{{/modal-dialog}}
\ No newline at end of file
diff --git a/app/components/medication-allergy.js b/app/components/medication-allergy.js
index c79197df32..e11ef65a5e 100644
--- a/app/components/medication-allergy.js
+++ b/app/components/medication-allergy.js
@@ -8,34 +8,11 @@ const {
export default Ember.Component.extend({
classNames: 'ps-info-group long-form',
- store: Ember.inject.service(),
- i18n: Ember.inject.service(),
- patient: null,
- displayModal: false,
- currentAllergy: false,
- buttonConfirmText: computed('currentAllergy', function() {
- let i18n = this.get('i18n');
- let currentAllergy = this.get('currentAllergy');
- if (currentAllergy) {
- return i18n.t('buttons.update');
- } else {
- return i18n.t('buttons.add');
- }
- }),
-
- additionalButtons: computed('currentAllergy', function() {
- let currentAllergy = this.get('currentAllergy');
- let btn = this.get('i18n').t('buttons.delete');
- if (currentAllergy) {
- return [{
- class: 'btn btn-default warning',
- buttonAction: 'deleteAllergy',
- buttonIcon: 'octicon octicon-x',
- buttonText: btn
- }];
- }
- }),
+ canAddAllergy: null,
+ patient: null,
+ editAllergyAction: 'editAllergy',
+ showAddAllergyAction: 'showAddAllergy',
showAllergies: computed('canAddAllergy', 'patient.allergies.[]', {
get() {
@@ -45,70 +22,13 @@ export default Ember.Component.extend({
}
}),
- modalTitle: Ember.computed('currentAllergy', function() {
- let currentAllergy = this.get('currentAllergy');
- let i18n = this.get('i18n');
- if (currentAllergy) {
- return i18n.t('allergies.titles.editAllergy');
- } else {
- return i18n.t('allergies.titles.addAllergy');
- }
- }),
-
- closeAllergyModal() {
- this.set('currentAllergy', false);
- this.set('displayModal', false);
- },
-
actions: {
-
- cancel() {
- this.closeAllergyModal();
- },
-
- closeModal() {
- this.closeAllergyModal();
- },
-
editAllergy(allergy) {
- this.set('currentAllergy', allergy);
- this.set('displayModal', true);
+ this.sendAction('editAllergyAction', allergy);
},
createNewAllergy() {
- this.set('displayModal', true);
- },
-
- updateAllergy() {
- let model = this.get('patient');
- let allergyModel = this.get('currentAllergy');
- if (!allergyModel) {
- allergyModel = this.get('store').createRecord('allergy', {
- name: this.get('name')
- });
- allergyModel.save().then(() => {
- model.get('allergies').pushObject(allergyModel);
- model.save().then(() => {
- this.set('name', '');
- this.closeAllergyModal();
- });
- });
- } else {
- allergyModel.save().then(() => {
- this.closeAllergyModal();
- });
- }
- },
- deleteAllergy() {
- let allergy = this.get('currentAllergy');
- let patient = this.get('patient');
- let patientAllergies = patient.get('allergies');
- allergy.destroyRecord().then(() => {
- patientAllergies.removeObject(allergy);
- patient.save().then(() => {
- this.closeAllergyModal();
- });
- });
+ this.sendAction('showAddAllergyAction');
}
}
});
diff --git a/app/components/patient-summary.js b/app/components/patient-summary.js
index b62e6db11f..70713279f3 100644
--- a/app/components/patient-summary.js
+++ b/app/components/patient-summary.js
@@ -16,6 +16,7 @@ export default Ember.Component.extend(UserSession, {
diagnosisContainer: null,
diagnosisList: null,
disablePatientLink: false,
+ editAllergyAction: 'editAllergy',
editDiagnosisAction: 'editDiagnosis',
editOperativePlanAction: 'editOperativePlan',
editOperationReportAction: 'editOperationReport',
@@ -23,6 +24,7 @@ export default Ember.Component.extend(UserSession, {
hideInActiveDiagnoses: true,
patient: null,
patientProcedures: null,
+ showAddAllergyAction: 'showAddAllergy',
showAddDiagnosisAction: 'showAddDiagnosis',
showPatientAction: 'showPatient',
@@ -86,6 +88,10 @@ export default Ember.Component.extend(UserSession, {
}
},
+ editAllergy(allergy) {
+ this.sendAction('editAllergyAction', allergy);
+ },
+
editDiagnosis(diagnosis) {
this.sendAction('editDiagnosisAction', diagnosis);
},
@@ -99,6 +105,10 @@ export default Ember.Component.extend(UserSession, {
}
},
+ showAddAllergy() {
+ this.sendAction('showAddAllergyAction');
+ },
+
showAddDiagnosis() {
this.sendAction('showAddDiagnosisAction');
}
diff --git a/app/mixins/allergy-actions.js b/app/mixins/allergy-actions.js
new file mode 100644
index 0000000000..8ee09c61fb
--- /dev/null
+++ b/app/mixins/allergy-actions.js
@@ -0,0 +1,41 @@
+import Ember from 'ember';
+
+const {
+ get,
+ set
+} = Ember;
+
+export default Ember.Mixin.create({
+ openAllergyModal(allergy) {
+ set(allergy, 'editController', this);
+ this.send('openModal', 'allergy.edit', allergy);
+ },
+
+ savePatientAllergy(patient, allergy) {
+ get(patient, 'allergies').pushObject(allergy);
+ patient.save().then(() => {
+ this.silentUpdate('closeModal');
+ });
+ },
+
+ deletePatientAllergy(patient, allergy) {
+ let patientAllergies = get(patient, 'allergies');
+ allergy.destroyRecord().then(() => {
+ patientAllergies.removeObject(allergy);
+ patient.save().then(() => {
+ this.send('closeModal');
+ });
+ });
+ },
+
+ actions: {
+ editAllergy(allergy) {
+ this.openAllergyModal(allergy);
+ },
+
+ showAddAllergy() {
+ let newAllergy = get(this, 'store').createRecord('allergy');
+ this.openAllergyModal(newAllergy);
+ }
+ }
+});
diff --git a/app/models/allergy.js b/app/models/allergy.js
index 92b2e2e928..caa69fbec6 100644
--- a/app/models/allergy.js
+++ b/app/models/allergy.js
@@ -7,5 +7,11 @@ export default AbstractModel.extend({
icd9CMCode: DS.attr('string'),
icd10Code: DS.attr('string'),
// Associations
- patient: DS.belongsTo('patient')
+ patient: DS.belongsTo('patient'),
+
+ validations: {
+ name: {
+ presence: true
+ }
+ }
});
diff --git a/app/patients/edit/controller.js b/app/patients/edit/controller.js
index 584a77b267..44cdd6d014 100644
--- a/app/patients/edit/controller.js
+++ b/app/patients/edit/controller.js
@@ -1,4 +1,5 @@
import AbstractEditController from 'hospitalrun/controllers/abstract-edit-controller';
+import AllergyActions from 'hospitalrun/mixins/allergy-actions';
import BloodTypes from 'hospitalrun/mixins/blood-types';
import DiagnosisActions from 'hospitalrun/mixins/diagnosis-actions';
import Ember from 'ember';
@@ -15,7 +16,7 @@ const {
isEmpty
} = Ember;
-export default AbstractEditController.extend(BloodTypes, DiagnosisActions, ReturnTo, UserSession, PatientId, PatientNotes, PatientVisits, {
+export default AbstractEditController.extend(AllergyActions, BloodTypes, DiagnosisActions, ReturnTo, UserSession, PatientId, PatientNotes, PatientVisits, {
canAddAppointment: function() {
return this.currentUserCan('add_appointment');
@@ -182,6 +183,11 @@ export default AbstractEditController.extend(BloodTypes, DiagnosisActions, Retur
updateCapability: 'add_patient',
actions: {
+ addAllergy(newAllergy) {
+ let patient = get(this, 'model');
+ this.savePatientAllergy(patient, newAllergy);
+ },
+
addContact(newContact) {
let additionalContacts = this.getWithDefault('model.additionalContacts', []);
let model = this.get('model');
@@ -216,6 +222,11 @@ export default AbstractEditController.extend(BloodTypes, DiagnosisActions, Retur
this.send('closeModal');
},
+ deleteAllergy(allergy) {
+ let patient = get(this, 'model');
+ this.deletePatientAllergy(patient, allergy);
+ },
+
deleteContact(model) {
let contact = model.get('contactToDelete');
let additionalContacts = this.get('model.additionalContacts');
diff --git a/app/templates/components/medication-allergy.hbs b/app/templates/components/medication-allergy.hbs
index 2e12c1bc2b..f8510228a9 100644
--- a/app/templates/components/medication-allergy.hbs
+++ b/app/templates/components/medication-allergy.hbs
@@ -2,38 +2,17 @@
{{#if canAddAllergy}}
- {{t 'allergies.buttons.addAllergy'}}
+ {{t 'allergies.buttons.addAllergy'}}
{{/if}}
{{#each patient.allergies as |allergy index|}}
{{#unless (eq index 0)}}, {{/unless}}
{{#if canAddAllergy}}
-
{{allergy.name}}
+
{{allergy.name}}
{{else}}
{{allergy.name}}
{{/if}}
{{/each}}
{{/if}}
-
-{{#if displayModal}}
- {{#modal-dialog
- title=modalTitle
- updateButtonText=buttonConfirmText
- hideCancelButton=true
- updateButtonAction='updateAllergy'
- additionalButtons=additionalButtons
- }}
-
-
-
- {{#if currentAllergy}}
- {{input class="form-control" value=currentAllergy.name}}
- {{else}}
- {{input class="form-control" value=name}}
- {{/if}}
-
-
- {{/modal-dialog}}
-{{/if}}
diff --git a/app/visits/edit/controller.js b/app/visits/edit/controller.js
index 86dbe4de9b..6a93cffa92 100644
--- a/app/visits/edit/controller.js
+++ b/app/visits/edit/controller.js
@@ -1,5 +1,6 @@
import AbstractEditController from 'hospitalrun/controllers/abstract-edit-controller';
import AddNewPatient from 'hospitalrun/mixins/add-new-patient';
+import AllergyActions from 'hospitalrun/mixins/allergy-actions';
import ChargeActions from 'hospitalrun/mixins/charge-actions';
import DiagnosisActions from 'hospitalrun/mixins/diagnosis-actions';
import Ember from 'ember';
@@ -17,7 +18,7 @@ const {
set
} = Ember;
-export default AbstractEditController.extend(AddNewPatient, ChargeActions, DiagnosisActions, PatientSubmodule, PatientNotes, UserSession, VisitTypes, {
+export default AbstractEditController.extend(AddNewPatient, AllergyActions, ChargeActions, DiagnosisActions, PatientSubmodule, PatientNotes, UserSession, VisitTypes, {
visitsController: Ember.inject.controller('visits'),
additionalButtons: computed('model.status', function() {
let buttonProps = {
@@ -340,6 +341,11 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
},
actions: {
+ addAllergy(newAllergy) {
+ let patient = get(this, 'model.patient');
+ this.savePatientAllergy(patient, newAllergy);
+ },
+
addDiagnosis(newDiagnosis) {
this.addDiagnosisToModelAndPatient(newDiagnosis);
},
@@ -362,6 +368,11 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
this.checkoutPatient(VisitStatus.CHECKED_OUT);
},
+ deleteAllergy(allergy) {
+ let patient = get(this, 'model.patient');
+ this.deletePatientAllergy(patient, allergy);
+ },
+
deleteProcedure(procedure) {
this.updateList('procedures', procedure, true);
},
diff --git a/tests/acceptance/visit-test.js b/tests/acceptance/visit-test.js
index 10990f4ae8..107357ff00 100644
--- a/tests/acceptance/visit-test.js
+++ b/tests/acceptance/visit-test.js
@@ -80,6 +80,17 @@ test('Edit visit', function(assert) {
});
andThen(function() {
assert.equal(currentURL(), '/visits/edit/03C7BF8B-04E0-DD9E-9469-96A5604F5340', 'Visit url is correct');
+ click('a:contains(Add Allergy)');
+ waitToAppear('.modal-dialog');
+ });
+ andThen(function() {
+ assert.equal(find('.modal-title').text(), 'Add Allergy', 'Add Allergy dialog displays');
+ fillIn('.test-allergy input', 'Oatmeal');
+ click('.modal-footer button:contains(Add)');
+ waitToDisappear('.modal-dialog');
+ });
+ andThen(function() {
+ assert.equal(find('a.allergy-button:contains(Oatmeal)').length, 1, 'New allergy appears');
click('a:contains(Add Diagnosis)');
waitToAppear('.modal-dialog');
});