From 7fdc9d3972489b8cea88d6732e222dcc71cb2def Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Wed, 6 May 2015 09:56:59 -0400 Subject: [PATCH] Changed Visit Types to be editable list. Resolves HospitalRun/frontend#46 --- app/admin/lookup/controller.js | 64 ++++++++++++++++++++++++----- app/appointments/edit/controller.js | 1 + app/appointments/route.js | 3 ++ app/mixins/visit-types.js | 18 ++++++-- app/patients/reports/controller.js | 1 + app/patients/route.js | 3 ++ app/visits/route.js | 3 ++ 7 files changed, 79 insertions(+), 14 deletions(-) diff --git a/app/admin/lookup/controller.js b/app/admin/lookup/controller.js index 46c4c47af2..7ca70066a9 100644 --- a/app/admin/lookup/controller.js +++ b/app/admin/lookup/controller.js @@ -4,8 +4,9 @@ import LabPricingTypes from 'hospitalrun/mixins/lab-pricing-types'; import ModalHelper from 'hospitalrun/mixins/modal-helper'; import ImagingPricingTypes from 'hospitalrun/mixins/imaging-pricing-types'; import InventoryTypeList from 'hospitalrun/mixins/inventory-type-list'; +import VisitTypes from 'hospitalrun/mixins/visit-types'; export default Ember.ArrayController.extend(BillingCategories, LabPricingTypes, - ModalHelper, ImagingPricingTypes, InventoryTypeList, { + ModalHelper, ImagingPricingTypes, InventoryTypeList, VisitTypes, { lookupType: null, lookupTypes: [{ name: 'Anesthesia Types', @@ -157,6 +158,13 @@ export default Ember.ArrayController.extend(BillingCategories, LabPricingTypes, appointment: 'location', visit: 'location', } + }, { + defaultValues: 'defaultVisitTypes', + name: 'Visit Types', + value: 'visit_types', + models: { + visit: 'visitType', + } }, { name: 'Ward Pricing Types', value: 'ward_pricing_types', @@ -218,6 +226,49 @@ export default Ember.ArrayController.extend(BillingCategories, LabPricingTypes, userCanAdd: Ember.computed.alias('lookupTypeList.userCanAdd'), + _canDeleteValue: function(value) { + var lookupType = this.get('lookupType'); + switch (lookupType) { + case 'inventory_types': { + if (value === 'Medication') { + this.displayAlert('Cannot Delete Medication', 'The Medication inventory type cannot be deleted because it is needed for the Medication module.'); + return false; + } + break; + } + case 'lab_pricing_types': { + if (value === 'Lab Procedure') { + this.displayAlert('Cannot Delete Lab Pricing Type', 'The Lab Procedure pricing type cannot be deleted because it is needed for the Labs module.'); + return false; + } + break; + } + case 'imaging_pricing_types': { + if (value === 'Imaging Procedure') { + this.displayAlert('Cannot Delete Imaging Pricing Type', 'The Imaging Procedure pricing type cannot be deleted because it is needed for the Imaging module.'); + return false; + } + break; + } + case 'visit_types': { + if (value === 'Admission') { + this.displayAlert('Cannot Delete Admmission Visit Type', 'The Admission Visit type cannot be deleted because it is needed for the Visits module.'); + return false; + } else if (value === 'Imaging') { + this.displayAlert('Cannot Delete Imaging Visit Type', 'The Imaging Visit type cannot be deleted because it is needed for the Imaging module.'); + return false; + } else if (value === 'Lab') { + this.displayAlert('Cannot Delete Lab Visit Type', 'The Lab Visit type cannot be deleted because it is needed for the Lab module.'); + return false; + } else if (value === 'Pharmacy') { + this.displayAlert('Cannot Delete Pharmacy Visit Type', 'The Lab Visit type cannot be deleted because it is needed for the Medication module.'); + return false; + } + } + } + return true; + }, + _sortValues: function(a, b) { return Ember.compare(a.toLowerCase(), b.toLowerCase()); }, @@ -229,16 +280,9 @@ export default Ember.ArrayController.extend(BillingCategories, LabPricingTypes, })); }, deleteValue: function(value) { - var lookupType = this.get('lookupType'), - lookupTypeList = this.get('lookupTypeList'), + var lookupTypeList = this.get('lookupTypeList'), lookupTypeValues = lookupTypeList.get('value'); - if (lookupType === 'inventory_types' && value === 'Medication') { - this.displayAlert('Cannot Delete Medication', 'The Medication inventory type cannot be deleted because it is needed for the Medication module.'); - } else if (lookupType === 'lab_pricing_types' && value === 'Lab Procedure') { - this.displayAlert('Cannot Delete Lab Pricing Type', 'The Lab Procedure pricing type cannot be deleted because it is needed for the Labs module.'); - } else if (lookupType === 'imaging_pricing_types' && value === 'Imaging Procedure') { - this.displayAlert('Cannot Delete Imaging Pricing Type', 'The Imaging Procedure pricing type cannot be deleted because it is needed for the Imaging module.'); - } else { + if (this._canDeleteValue(value)) { lookupTypeValues.removeObject(value.toString()); lookupTypeList.save(); } diff --git a/app/appointments/edit/controller.js b/app/appointments/edit/controller.js index 82f13432fc..2691cf421b 100644 --- a/app/appointments/edit/controller.js +++ b/app/appointments/edit/controller.js @@ -23,6 +23,7 @@ export default AbstractEditController.extend(PatientSubmodule, ReturnTo, VisitTy physicianList: Ember.computed.alias('controllers.appointments.physicianList'), showTime: true, + visitTypesList: Ember.computed.alias('controllers.appointments.visitTypeList'), cancelAction: function() { var returnTo = this.get('returnTo'); diff --git a/app/appointments/route.js b/app/appointments/route.js index 0cc47abc8b..77325211f2 100644 --- a/app/appointments/route.js +++ b/app/appointments/route.js @@ -27,6 +27,9 @@ export default AbstractModuleRoute.extend(UserSession,{ }, { name: 'locationList', findArgs: ['lookup','visit_location_list'] + }, { + name: 'visitTypesList', + findArgs: ['lookup','visit_types'] }], subActions: [{ diff --git a/app/mixins/visit-types.js b/app/mixins/visit-types.js index 1b8a14f901..67e5618dff 100644 --- a/app/mixins/visit-types.js +++ b/app/mixins/visit-types.js @@ -1,11 +1,21 @@ import Ember from "ember"; export default Ember.Mixin.create({ - visitTypes: [ + defaultVisitTypes: [ + 'Admission', 'Clinic', 'Followup', 'Imaging', 'Lab', - 'Pharmacy', - 'Surgery' - ] + 'Pharmacy' + ], + + visitTypes: function() { + var defaultVisitTypes = this.get('defaultVisitTypes'), + visitTypesList = this.get('visitTypesList'); + if (Ember.isEmpty(visitTypesList)) { + return defaultVisitTypes; + } else { + return visitTypesList.get('value'); + } + }.property('visitTypesList', 'defaultVisitTypes'), }); \ No newline at end of file diff --git a/app/patients/reports/controller.js b/app/patients/reports/controller.js index cccf4bdff1..9d59943bb4 100644 --- a/app/patients/reports/controller.js +++ b/app/patients/reports/controller.js @@ -7,6 +7,7 @@ export default AbstractReportController.extend(VisitTypes, { clinicList: Ember.computed.alias('controllers.patients.clinicList'), physicianList: Ember.computed.alias('controllers.patients.physicianList'), locationList: Ember.computed.alias('controllers.patients.locationList'), + visitTypesList: Ember.computed.alias('controllers.patients.visitTypeList'), admissionReportColumns: { gender: { diff --git a/app/patients/route.js b/app/patients/route.js index 3138d81757..e9da2df041 100644 --- a/app/patients/route.js +++ b/app/patients/route.js @@ -23,6 +23,9 @@ export default AbstractModuleRoute.extend(PatientId, { }, { name: 'statusList', findArgs: ['lookup','patient_status_list'] + }, { + name: 'visitTypesList', + findArgs: ['lookup','visit_types'] }], moduleName: 'patients', newButtonText: '+ new patient', diff --git a/app/visits/route.js b/app/visits/route.js index 88a5c913b8..94aeecf4a2 100644 --- a/app/visits/route.js +++ b/app/visits/route.js @@ -28,6 +28,9 @@ export default AbstractModuleRoute.extend({ }, { name: 'procedurePricingTypes', findArgs: ['lookup','procedure_pricing_types'] + }, { + name: 'visitTypesList', + findArgs: ['lookup','visit_types'] }, { name: 'wardPricingTypes', findArgs: ['lookup','ward_pricing_types']