export default AbstractEditController.extend(UnitTypes, { inventoryController: Ember.inject.controller('inventory'), cancelAction: 'closeModal', canEditQuantity: function() { var originalQuantity = this.get('model.originalQuantity'), currentQuantity = this.get('model.currentQuantity'); if (currentQuantity < originalQuantity) { return false; } return true; }.property('model.currentQuantity', 'model.originalQuantity'), warehouseList: Ember.computed.alias('inventoryController.warehouseList'), aisleLocationList: Ember.computed.alias('inventoryController.aisleLocationList'), inventoryUnitList: Ember.computed.alias('inventoryController.inventoryUnitList.value'), vendorList: Ember.computed.alias('inventoryController.vendorList'), lookupListsToUpdate: [{ name: 'aisleLocationList', // Name of property containing lookup list property: 'model.aisleLocation', // Corresponding property on model that potentially contains a new value to add to the list id: 'aisle_location_list' // Id of the lookup list to update }, { name: 'vendorList', // Name of property containing lookup list property: 'model.vendor', // Corresponding property on model that potentially contains a new value to add to the list id: 'vendor_list' // Id of the lookup list to update }, { name: 'warehouseList', // Name of property containing lookup list property: 'model.location', // Corresponding property on model that potentially contains a new value to add to the list id: 'warehouse_list' // Id of the lookup list to update }], newPurchase: false, updateQuantity: false, updateCapability: 'add_inventory_purchase', title: function() { let i18n = this.get('i18n'); var isNew = this.get('model.isNew'); if (isNew) { return i18n.t('inventory.titles.add_purchase'); } return i18n.t('inventory.titles.edit_purchase'); }.property('model.isNew'), beforeUpdate: function() { var isNew = this.get('model.isNew'), changedAttributes = this.get('model').changedAttributes(); if (changedAttributes.originalQuantity) { this.set('model.currentQuantity', this.get('model.originalQuantity')); if (!isNew) { this.set('updateQuantity', true); } } if (isNew) { this.set('newPurchase', true); } return Ember.RSVP.Promise.resolve(); }, afterUpdate: function(record) { if (this.get('newPurchase')) { this.send('addPurchase', record); } else { this.send('updatePurchase', record, true); } } });
import AbstractEditController from 'megd/controllers/abstract-edit-controller'; export default AbstractEditController.extend({ hideCancelButton: true, updateCapability: 'update_config', afterUpdate: function() { this.displayAlert(this.get('i18n').t('admin.address.titles.options_saved'), this.get('i18n').t('admin.address.messages.address_saved')); } });
export default AbstractEditController.extend(LabPricingTypes, ImagingPricingTypes, ReturnTo, { pricingController: Ember.inject.controller('pricing'), actions: { addOverride: function(override) { var pricingOverrides = this.get('model.pricingOverrides'); pricingOverrides.addObject(override); this.send('update', true); this.send('closeModal'); }, deleteOverride: function(model) { var overrideToDelete = model.overrideToDelete, pricingOverrides = this.get('model.pricingOverrides'); pricingOverrides.removeObject(overrideToDelete); overrideToDelete.destroyRecord().then(function() { this.send('update', true); this.send('closeModal'); }.bind(this)); }, editOverride: function(overrideToEdit) { if (Ember.isEmpty(overrideToEdit)) { overrideToEdit = this.store.createRecord('override-price'); } this.send('openModal', 'pricing.override', overrideToEdit); }, showDeleteOverride: function(overrideToDelete) { var message = 'Are you sure you want to delete this override?', model = Ember.Object.create({ overrideToDelete: overrideToDelete }), title = 'Delete Override'; this.displayConfirm(title, message, 'deleteOverride', model); } }, categories: [ 'Imaging', 'Lab', 'Procedure', 'Ward' ].map(SelectValues.selectValuesMap), expenseAccountList: Ember.computed.alias('pricingController.expenseAccountList'), imagingPricingTypes: Ember.computed.alias('pricingController.imagingPricingTypes'), labPricingTypes: Ember.computed.alias('pricingController.labPricingTypes'), procedurePricingTypes: Ember.computed.alias('pricingController.procedurePricingTypes'), wardPricingTypes: Ember.computed.alias('pricingController.wardPricingTypes'), lookupListsToUpdate: function() { var category = this.get('model.category').toLowerCase(), listsToUpdate = [{ name: 'expenseAccountList', property: 'model.expenseAccount', id: 'expense_account_list' }]; listsToUpdate.push({ name: category + 'PricingTypes', property: 'model.pricingType', id: category + '_pricing_types' }); return listsToUpdate; }.property('model.category'), pricingTypes: function() { var category = this.get('model.category'); if (!Ember.isEmpty(category)) { var typesList = this.get(category.toLowerCase() + 'PricingTypes'); if (Ember.isEmpty(typesList) || Ember.isEmpty(typesList.get('value'))) { if (category === 'Lab') { return Ember.Object.create({ value: this.defaultLabPricingTypes }); } else if (category === 'Imaging') { return Ember.Object.create({ value: this.defaultImagingPricingTypes }); } } return typesList; } }.property('model.category'), updateCapability: 'add_pricing', afterUpdate: function(record) { var message = `The pricing record for ${record.get('name')} has been saved.`; this.displayAlert('Pricing Item Saved', message); } });
export default AbstractEditController.extend(ChargeActions, PatientSubmodule, PatientNotes, UserSession, VisitTypes, { visitsController: Ember.inject.controller('visits'), canAddAppointment: function() { return this.currentUserCan('add_appointment'); }.property(), canAddImaging: function() { return this.currentUserCan('add_imaging'); }.property(), canAddLab: function() { return this.currentUserCan('add_lab'); }.property(), canAddMedication: function() { return this.currentUserCan('add_medication'); }.property(), canAddDiagnosis: function() { return this.currentUserCan('add_diagnosis'); }.property(), canAddProcedure: function() { return this.currentUserCan('add_procedure'); }.property(), canAddVitals: function() { return this.currentUserCan('add_vitals'); }.property(), canDeleteDiagnosis: function() { return this.currentUserCan('delete_diagnosis'); }.property(), canDeleteImaging: function() { return this.currentUserCan('delete_imaging'); }.property(), canDeleteLab: function() { return this.currentUserCan('delete_lab'); }.property(), canDeleteMedication: function() { return this.currentUserCan('delete_medication'); }.property(), canDeleteProcedure: function() { return this.currentUserCan('delete_procedure'); }.property(), canDeleteVitals: function() { return this.currentUserCan('delete_vitals'); }.property(), disabledAction: function() { this.get('model').validate().catch(Ember.K); this._super(); }.property('model.endDate', 'model.startDate', 'model.isValid'), isAdmissionVisit: function() { var visitType = this.get('model.visitType'), isAdmission = (visitType === 'Admission'), visit = this.get('model'); if (isAdmission) { visit.set('outPatient', false); } else { visit.set('status'); visit.set('outPatient', true); } return isAdmission; }.property('model.visitType'), startDateChanged: function() { var isAdmissionVisit = this.get('isAdmissionVisit'), startDate = this.get('model.startDate'), visit = this.get('model'); if (!isAdmissionVisit) { visit.set('endDate', startDate); } }.observes('isAdmissionVisit', 'model.startDate'), cancelAction: 'returnToPatient', chargePricingCategory: 'Ward', chargeRoute: 'visits.charge', diagnosisList: Ember.computed.alias('visitsController.diagnosisList'), findPatientVisits: false, patientImaging: Ember.computed.alias('model.imaging'), patientLabs: Ember.computed.alias('model.labs'), patientMedications: Ember.computed.alias('model.medication'), pricingList: null, // This gets filled in by the route pricingTypes: Ember.computed.alias('visitsController.wardPricingTypes'), physicianList: Ember.computed.alias('visitsController.physicianList'), locationList: Ember.computed.alias('visitsController.locationList'), visitTypesList: Ember.computed.alias('visitsController.visitTypeList'), lookupListsToUpdate: [{ name: 'diagnosisList', property: 'model.primaryBillingDiagnosis', id: 'diagnosis_list' }, { name: 'diagnosisList', property: 'model.primaryDiagnosis', id: 'diagnosis_list' }, { name: 'physicianList', property: 'model.examiner', id: 'physician_list' }, { name: 'locationList', property: 'model.location', id: 'visit_location_list' }], newVisit: false, visitStatuses: [ 'Admitted', 'Discharged' ].map(SelectValues.selectValuesMap), updateCapability: 'add_visit', _addChildObject: function(route) { this.transitionToRoute(route, 'new').then(function(newRoute) { newRoute.currentModel.setProperties({ patient: this.get('model.patient'), visit: this.get('model'), selectPatient: false, returnToVisit: true }); }.bind(this)); }, _finishAfterUpdate: function() { this.displayAlert('Visit Saved', 'The visit record has been saved.'); }, haveAdditionalDiagnoses: function() { return !Ember.isEmpty(this.get('model.additionalDiagnoses')); }.property('model.additionalDiagnoses.[]'), afterUpdate: function() { var patient = this.get('model.patient'), patientAdmitted = patient.get('admitted'), status = this.get('model.status'); if (status === 'Admitted' && !patientAdmitted) { patient.set('admitted', true); patient.save().then(this._finishAfterUpdate.bind(this)); } else if (status === 'Discharged' && patientAdmitted) { this.getPatientVisits(patient).then(function(visits) { if (Ember.isEmpty(visits.findBy('status', 'Admitted'))) { patient.set('admitted', false); patient.save().then(this._finishAfterUpdate.bind(this)); } else { this._finishAfterUpdate(); } }.bind(this)); } else { this._finishAfterUpdate(); } }, beforeUpdate: function() { if (this.get('model.isNew')) { this.set('newVisit', true); } return new Ember.RSVP.Promise(function(resolve, reject) { this.updateCharges().then(resolve, reject); }.bind(this)); }, /** * Adds or removes the specified object from the specified list. * @param {String} listName The name of the list to operate on. * @param {Object} listObject The object to add or removed from the * specified list. * @param {boolean} removeObject If true remove the object from the list; * otherwise add the specified object to the list. */ updateList: function(listName, listObject, removeObject) { var model = this.get('model'); model.get(listName).then(function(list) { if (removeObject) { list.removeObject(listObject); } else { list.addObject(listObject); } this.send('update', true); this.send('closeModal'); }.bind(this)); }, actions: { addDiagnosis: function(newDiagnosis) { var additionalDiagnoses = this.get('model.additionalDiagnoses'), visit = this.get('model'); if (!Ember.isArray(additionalDiagnoses)) { additionalDiagnoses = []; } additionalDiagnoses.addObject(newDiagnosis); visit.set('additionalDiagnoses', additionalDiagnoses); this.send('update', true); this.send('closeModal'); }, deleteDiagnosis: function(diagnosis) { var additionalDiagnoses = this.get('model.additionalDiagnoses'), visit = this.get('model'); additionalDiagnoses.removeObject(diagnosis); visit.set('additionalDiagnoses', additionalDiagnoses); this.send('update', true); }, addVitals: function(newVitals) { this.updateList('vitals', newVitals); }, cancel: function() { var cancelledItem = this.get('model'); if (this.get('model.isNew')) { cancelledItem.deleteRecord(); } else { cancelledItem.rollbackAttributes(); } this.send(this.get('cancelAction')); }, deleteProcedure: function(procedure) { this.updateList('procedures', procedure, true); }, deleteVitals: function(vitals) { this.updateList('vitals', vitals, true); }, editImaging: function(imaging) { if (imaging.get('canEdit')) { imaging.setProperties({ 'returnToVisit': true }); } this.transitionToRoute('imaging.edit', imaging); }, editLab: function(lab) { if (lab.get('canEdit')) { lab.setProperties({ 'returnToVisit': true }); this.transitionToRoute('labs.edit', lab); } }, editMedication: function(medication) { if (medication.get('canEdit')) { medication.set('returnToVisit', true); this.transitionToRoute('medication.edit', medication); } }, showAddVitals: function() { var newVitals = this.get('store').createRecord('vital', { dateRecorded: new Date() }); this.send('openModal', 'visits.vitals.edit', newVitals); }, showAddPatientNote: function(model) { if (Ember.isEmpty(model)) { model = this.get('store').createRecord('patient-note', { visit: this.get('model'), createdBy: this.getUserName(), patient: this.get('model').get('patient'), noteType: this._computeNoteType(this.get('model')) }); } this.send('openModal', 'patients.notes', model); }, newAppointment: function() { this._addChildObject('appointments.edit'); }, newImaging: function() { this._addChildObject('imaging.edit'); }, newLab: function() { this._addChildObject('labs.edit'); }, newMedication: function() { this._addChildObject('medication.edit'); }, showAddDiagnosis: function() { var newDiagnosis = this.get('store').createRecord('add-diagnosis'); this.send('openModal', 'visits.add-diagnosis', newDiagnosis); }, showAddProcedure: function() { this._addChildObject('procedures.edit'); }, showDeleteImaging: function(imaging) { this.send('openModal', 'imaging.delete', imaging); }, showDeleteLab: function(lab) { this.send('openModal', 'labs.delete', lab); }, showDeleteMedication: function(medication) { this.send('openModal', 'medication.delete', medication); }, showDeleteProcedure: function(procedure) { this.send('openModal', 'visits.procedures.delete', procedure); }, showDeleteVitals: function(vitals) { this.send('openModal', 'visits.vitals.delete', vitals); }, showEditProcedure: function(procedure) { if (Ember.isEmpty(procedure.get('visit'))) { procedure.set('visit', this.get('model')); } procedure.set('returnToVisit', true); procedure.set('returnToPatient', false); this.transitionToRoute('procedures.edit', procedure); }, showEditVitals: function(vitals) { this.send('openModal', 'visits.vitals.edit', vitals); }, showDeletePatientNote: function(note) { this.send('openModal', 'dialog', Ember.Object.create({ confirmAction: 'deletePatientNote', title: 'Delete Note', message: 'Are you sure you want to delete this note?', noteToDelete: note, updateButtonAction: 'confirm', updateButtonText: 'Ok' })); }, deletePatientNote: function(model) { var note = model.get('noteToDelete'); var patientNotes = this.get('model.patientNotes'); patientNotes.removeObject(note); this.send('update', true); } } });
export default AbstractEditController.extend(ChargeActions, PatientSubmodule, { imagingController: Ember.inject.controller('imaging'), chargePricingCategory: 'Imaging', chargeRoute: 'imaging.charge', selectedImagingType: null, canComplete: function() { var isNew = this.get('model.isNew'), imagingTypeName = this.get('model.imagingTypeName'), selectedImagingType = this.get('selectedImagingType'); if (isNew && (Ember.isEmpty(imagingTypeName) || Ember.isArray(selectedImagingType) && selectedImagingType.length > 1)) { return false; } else { return this.currentUserCan('complete_imaging'); } }.property('selectedImagingType.[]', 'model.imagingTypeName'), actions: { completeImaging: function() { this.set('model.status', 'Completed'); this.get('model').validate().then(function() { if (this.get('model.isValid')) { this.set('model.imagingDate', new Date()); this.send('update'); } }.bind(this)).catch(Ember.K); }, /** * Save the imaging request(s), creating multiples when user selects multiple imaging tests. */ update: function() { if (this.get('model.isNew')) { var newImaging = this.get('model'), selectedImagingType = this.get('selectedImagingType'); if (Ember.isEmpty(this.get('model.status'))) { this.set('model.status', 'Requested'); } this.set('model.requestedBy', newImaging.getUserName()); this.set('model.requestedDate', new Date()); if (Ember.isEmpty(selectedImagingType)) { this.saveNewPricing(this.get('model.imagingTypeName'), 'Imaging', 'model.imagingType').then(function() { this.addChildToVisit(newImaging, 'imaging', 'Imaging').then(function() { this.saveModel(); }.bind(this)); }.bind(this)); } else { this.getSelectedPricing('selectedImagingType').then(function(pricingRecords) { if (Ember.isArray(pricingRecords)) { this.createMultipleRequests(pricingRecords, 'imagingType', 'imaging', 'Imaging'); } else { this.set('model.imagingType', pricingRecords); this.addChildToVisit(newImaging, 'imaging', 'Imaging').then(function() { this.saveModel(); }.bind(this)); } }.bind(this)); } } else { this.saveModel(); } } }, additionalButtons: function() { let i18n = this.get('i18n'); var canComplete = this.get('canComplete'), isValid = this.get('model.isValid'); if (isValid && canComplete) { return [{ buttonAction: 'completeImaging', buttonIcon: 'glyphicon glyphicon-ok', class: 'btn btn-primary on-white', buttonText: i18n.t('buttons.complete') }]; } }.property('canComplete', 'model.isValid'), lookupListsToUpdate: [{ name: 'radiologistList', property: 'model.radiologist', id: 'radiologists' }], pricingTypeForObjectType: 'Imaging Procedure', pricingTypes: Ember.computed.alias('imagingController.imagingPricingTypes'), pricingList: null, // This gets filled in by the route radiologistList: Ember.computed.alias('imagingController.radiologistList'), updateCapability: 'add_imaging', afterUpdate: function(saveResponse, multipleRecords) { let i18n = this.get('i18n'); this.updateLookupLists(); var afterDialogAction, alertTitle, alertMessage; if (this.get('model.status') === 'Completed') { alertTitle = i18n.t('imaging.alerts.completed_title'); alertMessage = i18n.t('imaging.alerts.completed_message'); } else { alertTitle = i18n.t('imaging.alerts.saved_title'); alertMessage = i18n.t('imaging.alerts.saved_message'); } if (multipleRecords) { afterDialogAction = this.get('cancelAction'); } this.saveVisitIfNeeded(alertTitle, alertMessage, afterDialogAction); this.set('model.selectPatient', false); } });
export default AbstractEditController.extend({ cancelAction: 'closeModal', newCharge: false, newPricingItem: false, requestingController: Ember.inject.controller('procedures/edit'), database: Ember.inject.service(), pricingList: Ember.computed.alias('requestingController.pricingList'), selectedItem: null, updateCapability: 'add_charge', itemChanged: function() { var model = this.get('model'), selectedItem = this.get('selectedItem'); if (!Ember.isEmpty(selectedItem)) { this.store.find('pricing', selectedItem.id).then(function(item) { model.set('pricingItem', item); }.bind(this)); } }.observes('selectedItem'), pricingItemChanged: function() { var model = this.get('model'), itemName = model.get('itemName'), pricingItem = model.get('pricingItem'); if (!Ember.isEmpty(pricingItem)) { this.set('newPricingItem', false); if (pricingItem.get('name') !== itemName) { model.set('itemName', pricingItem.get('name')); } } else { this.set('newPricingItem', true); } }.observes('model.pricingItem'), title: function() { var isNew = this.get('model.isNew'); if (isNew) { return 'Add Charge Item'; } return 'Edit Charge Item'; }.property('model.isNew'), beforeUpdate: function() { var isNew = this.get('model.isNew'); if (isNew) { this.set('newCharge', true); } if (this.get('newPricingItem')) { return new Ember.RSVP.Promise(function(resolve, reject) { var model = this.get('model'), newPricing = this.store.createRecord('pricing', { name: model.get('itemName'), category: model.get('pricingCategory') }); newPricing.save().then(function() { this.get('pricingList').addObject({ id: newPricing.get('id'), name: newPricing.get('name') }); model.set('pricingItem', newPricing); resolve(); }.bind(this), reject); }.bind(this)); } else { return Ember.RSVP.Promise.resolve(); } }, afterUpdate: function(record) { if (this.get('newCharge')) { this.get('requestingController').send('addCharge', record); } else { this.send('closeModal'); } } });
import AbstractEditController from 'megd/controllers/abstract-edit-controller'; export default AbstractEditController.extend({ actions: { cancel: function() { this.send('closeModal'); } }, afterUpdate: function(record) { var message = `The pricing profile ${record.get('name')} has been saved.`; this.displayAlert('Pricing Profile Saved', message, 'refreshProfiles'); }, title: function() { var isNew = this.get('model.isNew'); if (isNew) { return 'New Pricing Profile'; } else { return 'Edit Pricing Profile'; } }.property('model.isNew') });
export default AbstractEditController.extend(NumberFormat, PatientSubmodule, PublishStatuses, { invoiceController: Ember.inject.controller('invoices'), expenseAccountList: Ember.computed.alias('invoiceController.expenseAccountList.value'), patientList: Ember.computed.alias('invoiceController.patientList'), pharmacyCharges: [], pricingProfiles: Ember.computed.map('invoiceController.pricingProfiles', SelectValues.selectObjectMap), supplyCharges: [], updateCapability: 'add_invoice', wardCharges: [], additionalButtons: function() { var buttons = [], isValid = this.get('model.isValid'), status = this.get('model.status'); if (isValid && status === 'Draft') { buttons.push({ class: 'btn btn-default default', buttonAction: 'finalizeInvoice', buttonIcon: 'glyphicon glyphicon-ok', buttonText: 'Invoice Ready' }); } buttons.push({ class: 'btn btn-default neutral', buttonAction: 'printInvoice', buttonIcon: 'glyphicon glyphicon-print', buttonText: 'Print' }); return buttons; }.property('model.isValid', 'model.status'), canAddCharge: function() { return this.currentUserCan('add_charge'); }.property(), canAddPayment: function() { return this.currentUserCan('add_payment'); }.property(), pharmacyExpenseAccount: function() { var expenseAccountList = this.get('expenseAccountList'); if (!Ember.isEmpty(expenseAccountList)) { var account = expenseAccountList.find(function(value) { if (value.toLowerCase().indexOf('pharmacy') > -1) { return true; } }); return account; } }.property('expenseAccountList.value'), actions: { addItemCharge: function(lineItem) { var details = lineItem.get('details'); var detail = this.store.createRecord('line-item-detail', { id: PouchDB.utils.uuid() }); details.addObject(detail); }, addLineItem: function(lineItem) { var lineItems = this.get('model.lineItems'); lineItems.addObject(lineItem); this.send('update', true); this.send('closeModal'); }, deleteCharge: function(deleteInfo) { this._deleteObject(deleteInfo.itemToDelete, deleteInfo.deleteFrom); }, deleteLineItem: function(deleteInfo) { this._deleteObject(deleteInfo.itemToDelete, this.get('model.lineItems')); }, finalizeInvoice: function() { var currentInvoice = this.get('model'), invoicePayments = currentInvoice.get('payments'), paymentsToSave = []; currentInvoice.get('patient.payments').then(function(patientPayments) { patientPayments.forEach(function(payment) { var invoice = payment.get('invoice'); if (Ember.isEmpty(invoice)) { payment.set('invoice', currentInvoice); paymentsToSave.push(payment.save()); invoicePayments.addObject(payment); } }.bind(this)); Ember.RSVP.all(paymentsToSave).then(function() { this.set('model.status', 'Billed'); this.send('update'); }.bind(this)); }.bind(this)); }, printInvoice: function() { this.transitionToRoute('print.invoice', this.get('model')); }, removePayment: function(removeInfo) { var payments = this.get('model.payments'), payment = removeInfo.itemToRemove; payment.set('invoice'); payments.removeObject(removeInfo.itemToRemove); this.send('update', true); this.send('closeModal'); }, showAddLineItem: function() { var newLineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid() }); this.send('openModal', 'invoices.add-line-item', newLineItem); }, showDeleteItem: function(itemToDelete, deleteFrom) { this.send('openModal', 'dialog', Ember.Object.create({ confirmAction: 'deleteCharge', deleteFrom: deleteFrom, title: 'Delete Charge', message: `Are you sure you want to delete ${itemToDelete.get('name')}?`, itemToDelete: itemToDelete, updateButtonAction: 'confirm', updateButtonText: 'Ok' })); }, showDeleteLineItem: function(item) { this.send('openModal', 'dialog', Ember.Object.create({ confirmAction: 'deleteLineItem', title: 'Delete Line Item', message: `Are you sure you want to delete ${item.get('name')}?`, itemToDelete: item, updateButtonAction: 'confirm', updateButtonText: 'Ok' })); }, showRemovePayment: function(payment) { var message = 'Are you sure you want to remove this payment from this invoice?', model = Ember.Object.create({ itemToRemove: payment }), title = 'Remove Payment'; this.displayConfirm(title, message, 'removePayment', model); }, toggleDetails: function(item) { item.toggleProperty('showDetails'); } }, changePaymentProfile: function() { var patient = this.get('model.patient'), paymentProfile = this.get('model.paymentProfile'); if (!Ember.isEmpty(patient) && Ember.isEmpty(paymentProfile)) { this.set('model.paymentProfile', patient.get('paymentProfile')); } }.observes('model.patient'), paymentProfileChanged: function() { var discountPercentage = this._getValidNumber(this.get('model.paymentProfile.discountPercentage')), originalPaymentProfileId = this.get('model.originalPaymentProfileId'), profileId = this.get('model.paymentProfile.id'); if (profileId !== originalPaymentProfileId) { var lineItems = this.get('model.lineItems'); lineItems.forEach(function(lineItem) { var details = lineItem.get('details'), lineDiscount = 0; details.forEach(function(detail) { var pricingOverrides = detail.get('pricingItem.pricingOverrides'); if (!Ember.isEmpty(pricingOverrides)) { var pricingOverride = pricingOverrides.findBy('profile.id', profileId); if (!Ember.isEmpty(pricingOverride)) { Ember.set(detail, 'price', pricingOverride.get('price')); } } }.bind(this)); if (discountPercentage > 0) { var lineTotal = lineItem.get('total'); lineDiscount = this._numberFormat((discountPercentage / 100) * (lineTotal), true); lineItem.set('discount', lineDiscount); } }.bind(this)); this.set('model.originalPaymentProfileId', profileId); } }.observes('model.paymentProfile'), visitChanged: function() { var visit = this.get('model.visit'), lineItems = this.get('model.lineItems'); if (!Ember.isEmpty(visit) && Ember.isEmpty(lineItems)) { this.set('model.originalPaymentProfileId'); var promises = this.resolveVisitChildren(); Ember.RSVP.allSettled(promises, 'Resolved visit children before generating invoice').then(function(results) { var chargePromises = this._resolveVisitDescendents(results, 'charges'); if (!Ember.isEmpty(chargePromises)) { var promiseLabel = 'Reloaded charges before generating invoice'; Ember.RSVP.allSettled(chargePromises, promiseLabel).then(function(chargeResults) { var pricingPromises = []; chargeResults.forEach(function(result) { if (!Ember.isEmpty(result.value)) { var pricingItem = result.value.get('pricingItem'); if (!Ember.isEmpty(pricingItem)) { pricingPromises.push(pricingItem.reload()); } } }); promiseLabel = 'Reloaded pricing items before generating invoice'; Ember.RSVP.allSettled(pricingPromises, promiseLabel).then(function() { this._generateLineItems(visit, results); this.paymentProfileChanged(); }.bind(this)); }.bind(this)); } else { this._generateLineItems(visit, results); this.paymentProfileChanged(); } }.bind(this), function(err) { console.log('Error resolving visit children', err); }); } }.observes('model.visit'), _addPharmacyCharge: function(charge, medicationItemName) { return charge.getMedicationDetails(medicationItemName).then((medicationDetails) => { let quantity = charge.get('quantity'); let pharmacyCharges = this.get('pharmacyCharges'); let pharmacyExpenseAccount = this.get('pharmacyExpenseAccount'); let pharmacyCharge = this.store.createRecord('line-item-detail', { id: PouchDB.utils.uuid(), name: medicationDetails.name, quantity: quantity, price: medicationDetails.price, department: 'Pharmacy', expenseAccount: pharmacyExpenseAccount }); pharmacyCharges.addObject(pharmacyCharge); }); }, _addSupplyCharge: function(charge, department) { var supplyCharges = this.get('supplyCharges'), supplyCharge = this._createChargeItem(charge, department); supplyCharges.addObject(supplyCharge); }, _createChargeItem: function(charge, department) { var chargeItem = this.store.createRecord('line-item-detail', { id: PouchDB.utils.uuid(), name: charge.get('pricingItem.name'), expenseAccount: charge.get('pricingItem.expenseAccount'), quantity: charge.get('quantity'), price: charge.get('pricingItem.price'), department: department, pricingItem: charge.get('pricingItem') }); return chargeItem; }, /** * Remove the specified object from the specified list, update the model and close the modal. * @param objectToDelete {object} - the object to remove * @param deleteFrom {Array} - the array to remove the object from. */ _deleteObject: function(objectToDelete, deleteFrom) { deleteFrom.removeObject(objectToDelete); if (!objectToDelete.get('isNew')) { objectToDelete.destroyRecord(); } this.send('update', true); this.send('closeModal'); }, _mapWardCharge: function(charge) { return this._createChargeItem(charge, 'Ward'); }, _completeBeforeUpdate: function(sequence, resolve, reject) { var invoiceId = 'inv', sequenceValue; sequence.incrementProperty('value', 1); sequenceValue = sequence.get('value'); if (sequenceValue < 100000) { invoiceId += String('00000' + sequenceValue).slice(-5); } else { invoiceId += sequenceValue; } this.set('model.id', invoiceId); sequence.save().then(resolve, reject); }, _generateLineItems: function(visit, visitChildren) { var endDate = visit.get('endDate'), imaging = visitChildren[0].value, labs = visitChildren[1].value, lineDetail, lineItem, lineItems = this.get('model.lineItems'), medication = visitChildren[2].value, procedures = visitChildren[3].value, startDate = visit.get('startDate'), visitCharges = visit.get('charges'); this.setProperties({ pharmacyCharges: [], supplyCharges: [], wardCharges: [] }); if (!Ember.isEmpty(endDate) && !Ember.isEmpty(startDate)) { endDate = moment(endDate); startDate = moment(startDate); var stayDays = endDate.diff(startDate, 'days'); if (stayDays > 1) { lineDetail = this.store.createRecord('line-item-detail', { id: PouchDB.utils.uuid(), name: 'Days', quantity: stayDays }); lineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid(), category: 'Hospital Charges', name: 'Room/Accomodation' }); lineItem.get('details').addObject(lineDetail); lineItems.addObject(lineItem); } } let pharmacyChargePromises = []; medication.forEach(function(medicationItem) { pharmacyChargePromises.push(this._addPharmacyCharge(medicationItem, 'inventoryItem')); }.bind(this)); this.set('wardCharges', visitCharges.map(this._mapWardCharge.bind(this))); procedures.forEach(function(procedure) { var charges = procedure.get('charges'); charges.forEach(function(charge) { if (charge.get('medicationCharge')) { pharmacyChargePromises.push(this._addPharmacyCharge(charge, 'medication')); } else { this._addSupplyCharge(charge, 'O.R.'); } }.bind(this)); }.bind(this)); labs.forEach(function(lab) { if (!Ember.isEmpty(imaging.get('labType'))) { this._addSupplyCharge(Ember.Object.create({ pricingItem: imaging.get('labType'), quantity: 1 }), 'Lab'); } lab.get('charges').forEach(function(charge) { this._addSupplyCharge(charge, 'Lab'); }.bind(this)); }.bind(this)); imaging.forEach(function(imaging) { if (!Ember.isEmpty(imaging.get('imagingType'))) { this._addSupplyCharge(Ember.Object.create({ pricingItem: imaging.get('imagingType'), quantity: 1 }), 'Imaging'); } imaging.get('charges').forEach(function(charge) { this._addSupplyCharge(charge, 'Imaging'); }.bind(this)); }.bind(this)); Ember.RSVP.all(pharmacyChargePromises).then(() => { lineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid(), name: 'Pharmacy', category: 'Hospital Charges' }); lineItem.get('details').addObjects(this.get('pharmacyCharges')); lineItems.addObject(lineItem); lineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid(), name: 'X-ray/Lab/Supplies', category: 'Hospital Charges' }); lineItem.get('details').addObjects(this.get('supplyCharges')); lineItems.addObject(lineItem); lineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid(), name: 'Ward Items', category: 'Hospital Charges' }); lineItem.get('details').addObjects(this.get('wardCharges')); lineItems.addObject(lineItem); lineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid(), name: 'Physical Therapy', category: 'Hospital Charges' }); lineItems.addObject(lineItem); lineItem = this.store.createRecord('billing-line-item', { id: PouchDB.utils.uuid(), name: 'Others/Misc', category: 'Hospital Charges' }); lineItems.addObject(lineItem); this.send('update', true); }); }, _resolveVisitDescendents: function(results, childNameToResolve) { var promises = []; results.forEach(function(result) { if (!Ember.isEmpty(result.value)) { result.value.forEach(function(record) { var children = record.get(childNameToResolve); if (!Ember.isEmpty(children)) { children.forEach(function(child) { // Make sure children are fully resolved promises.push(child.reload()); }); } }); } }); return promises; }, beforeUpdate: function() { return new Ember.RSVP.Promise(function(resolve, reject) { var lineItems = this.get('model.lineItems'), savePromises = []; lineItems.forEach(function(lineItem) { lineItem.get('details').forEach(function(detail) { savePromises.push(detail.save()); }.bind(this)); savePromises.push(lineItem.save()); }.bind(this)); Ember.RSVP.all(savePromises, 'Saved invoice children before saving invoice').then(function() { if (this.get('model.isNew')) { this.store.find('sequence', 'invoice').then(function(sequence) { this._completeBeforeUpdate(sequence, resolve, reject); }.bind(this), function() { var store = this.get('store'); var newSequence = store.push(store.normalize('sequence', { id: 'invoice', value: 0 })); this._completeBeforeUpdate(newSequence, resolve, reject); }.bind(this)); } else { resolve(); } }.bind(this), reject); }.bind(this)); }, afterUpdate: function() { var message = 'The invoice record has been saved.'; this.displayAlert('Invoice Saved', message); } });
export default AbstractEditController.extend(InventorySelection, FulfillRequest, InventoryLocations, PatientId, PatientSubmodule, UserSession, { medicationController: Ember.inject.controller('medication'), newPatientId: null, expenseAccountList: Ember.computed.alias('medicationController.expenseAccountList'), canFulfill: function() { return this.currentUserCan('fulfill_medication'); }.property(), isFulfilled: function() { var status = this.get('model.status'); return (status === 'Fulfilled'); }.property('model.status'), isFulfilling: function() { var canFulfill = this.get('canFulfill'), isRequested = this.get('model.isRequested'), fulfillRequest = this.get('model.shouldFulfillRequest'), isFulfilling = canFulfill && (isRequested || fulfillRequest); this.get('model').set('isFulfilling', isFulfilling); return isFulfilling; }.property('canFulfill', 'model.isRequested', 'model.shouldFulfillRequest'), isFulfilledOrRequested: function() { return (this.get('isFulfilled') || this.get('model.isRequested')); }.property('isFulfilled', 'model.isRequested'), prescriptionClass: function() { var quantity = this.get('model.quantity'); this.get('model').validate().catch(Ember.K); if (Ember.isEmpty(quantity)) { return 'required'; } }.property('model.quantity'), quantityClass: function() { var prescription = this.get('model.prescription'), returnClass = 'col-xs-3', isFulfilling = this.get('isFulfilling'); if (isFulfilling || Ember.isEmpty(prescription)) { returnClass += ' required'; } return `${returnClass} test-quantity-input`; }.property('isFulfilling', 'model.prescription'), quantityLabel: function() { let i18n = this.get('i18n'); var returnLabel = i18n.t('medication.labels.quantity_requested'), isFulfilled = this.get('isFulfilled'), isFulfilling = this.get('isFulfilling'); if (isFulfilling) { returnLabel = i18n.t('medication.labels.quantity_dispensed'); } else if (isFulfilled) { returnLabel = i18n.t('medication.labels.quantity_distributed'); } return returnLabel; }.property('isFulfilled'), medicationList: [], updateCapability: 'add_medication', afterUpdate: function() { let i18n = this.get('i18n'); var alertTitle, alertMessage, isFulfilled = this.get('isFulfilled'); if (isFulfilled) { alertTitle = i18n.t('medication.alerts.fulfilled_title'); alertMessage = 'The medication request has been fulfilled.'; this.set('model.selectPatient', false); } else { alertTitle = i18n.t('medication.alerts.saved_title'); alertMessage = i18n.t('medication.alerts.saved_message'); } this.saveVisitIfNeeded(alertTitle, alertMessage); }, _addNewPatient: function() { let i18n = this.get('i18n'); this.displayAlert(i18n.t('alerts.please_wait'), i18n.t('messages.new_patient_has_to_be_created')); this._getNewPatientId().then(function(friendlyId) { var patientTypeAhead = this.get('model.patientTypeAhead'), nameParts = patientTypeAhead.split(' '), patientDetails = { friendlyId: friendlyId, patientFullName: patientTypeAhead, requestingController: this }, patient; if (nameParts.length >= 3) { patientDetails.firstName = nameParts[0]; patientDetails.middleName = nameParts[1]; patientDetails.lastName = nameParts.splice(2, nameParts.length).join(' '); } else if (nameParts.length === 2) { patientDetails.firstName = nameParts[0]; patientDetails.lastName = nameParts[1]; } else { patientDetails.firstName = patientTypeAhead; } patient = this.store.createRecord('patient', patientDetails); this.send('openModal', 'patients.quick-add', patient); }.bind(this)); }, _getNewPatientId: function() { var newPatientId = this.get('newPatientId'); if (Ember.isEmpty(newPatientId)) { return new Ember.RSVP.Promise(function(resolve, reject) { this.generateFriendlyId().then(function(friendlyId) { this.set('newPatientId', friendlyId); resolve(friendlyId); }.bind(this), reject); }.bind(this)); } else { return Ember.RSVP.resolve(newPatientId); } }, beforeUpdate: function() { var isFulfilling = this.get('isFulfilling'), isNew = this.get('model.isNew'); if (isNew || isFulfilling) { return new Ember.RSVP.Promise(function(resolve, reject) { var newMedication = this.get('model'); newMedication.validate().then(function() { if (newMedication.get('isValid')) { if (isNew) { if (Ember.isEmpty(newMedication.get('patient'))) { this._addNewPatient(); reject({ ignore: true, message: 'creating new patient first' }); } else { newMedication.set('medicationTitle', newMedication.get('inventoryItem.name')); newMedication.set('priceOfMedication', newMedication.get('inventoryItem.price')); newMedication.set('status', 'Requested'); newMedication.set('requestedBy', newMedication.getUserName()); newMedication.set('requestedDate', new Date()); this.addChildToVisit(newMedication, 'medication', 'Pharmacy').then(function() { this.finishBeforeUpdate(isFulfilling, resolve); }.bind(this), reject); } } else { this.finishBeforeUpdate(isFulfilling, resolve); } } else { this.send('showDisabledDialog'); reject('invalid model'); } }.bind(this)).catch(function() { this.send('showDisabledDialog'); reject('invalid model'); }.bind(this)); }.bind(this)); } else { return Ember.RSVP.resolve(); } }, finishBeforeUpdate: function(isFulfilling, resolve) { if (isFulfilling) { var inventoryLocations = this.get('model.inventoryLocations'), inventoryRequest = this.get('store').createRecord('inv-request', { expenseAccount: this.get('model.expenseAccount'), dateCompleted: new Date(), inventoryItem: this.get('model.inventoryItem'), inventoryLocations: inventoryLocations, quantity: this.get('model.quantity'), transactionType: 'Fulfillment', patient: this.get('model.patient'), markAsConsumed: true }); this.performFulfillRequest(inventoryRequest, false, false, true).then(function() { this.set('model.status', 'Fulfilled'); resolve(); }.bind(this)); } else { resolve(); } }, showUpdateButton: function() { var isFulfilled = this.get('isFulfilled'); if (isFulfilled) { return false; } else { return this._super(); } }.property('updateCapability', 'isFulfilled'), updateButtonText: function() { let i18n = this.get('i18n'); if (this.get('model.hideFulfillRequest')) { return i18n.t('buttons.dispense'); } else if (this.get('isFulfilling')) { return i18n.t('labels.fulfill'); } else if (this.get('model.isNew')) { return i18n.t('buttons.add'); } else { return i18n.t('buttons.update'); } }.property('model.isNew', 'isFulfilling', 'model.hideFulfillRequest'), actions: { addedNewPatient: function(record) { this.send('closeModal'); this.set('model.patient', record); this.set('newPatientId'); this.send('update'); } } });
export default AbstractEditController.extend(AppointmentStatuses, PatientSubmodule, VisitTypes, { appointmentsController: Ember.inject.controller('appointments'), endHour: null, endMinute: null, findPatientVisits: false, startHour: null, startMinute: null, hourList: function() { var hour, hourList = []; for (hour = 0; hour < 24; hour++) { var hourText = (hour % 12) + (hour < 12 ? ' AM' : ' PM'); if (hourText === '0 AM') { hourText = 'Midnight'; } else if (hourText === '0 PM') { hourText = 'Noon'; } hourList.push({ name: hourText, value: hour }); } return hourList; }.property(), locationList: Ember.computed.alias('appointmentsController.locationList'), lookupListsToUpdate: [{ name: 'physicianList', property: 'model.provider', id: 'physician_list' }, { name: 'locationList', property: 'model.location', id: 'visit_location_list' }], minuteList: function() { var minute, minuteList = []; for (minute = 0; minute < 60; minute++) { minuteList.push(String('00' + minute).slice(-2)); } return minuteList; }.property(), physicianList: Ember.computed.alias('appointmentsController.physicianList'), showTime: function() { var allDay = this.get('model.allDay'), isAdmissionAppointment = this.get('isAdmissionAppointment'); return (!allDay && isAdmissionAppointment); }.property('model.allDay', 'isAdmissionAppointment'), visitTypesList: Ember.computed.alias('appointmentsController.visitTypeList'), cancelAction: function() { var returnTo = this.get('model.returnTo'); if (Ember.isEmpty(returnTo)) { return this._super(); } else { return 'returnTo'; } }.property('model.returnTo'), isAdmissionAppointment: function() { var model = this.get('model'), appointmentType = model.get('appointmentType'), isAdmissionAppointment = (appointmentType === 'Admission'); if (!isAdmissionAppointment) { model.set('allDay', true); } return isAdmissionAppointment; }.property('model.appointmentType'), updateCapability: 'add_appointment', afterUpdate: function() { this.send(this.get('cancelAction')); }, beforeUpdate: function() { this._updateAppointmentDates(); return Ember.RSVP.Promise.resolve(); }, endHourChanged: function() { this._updateDate('endHour', 'endDate'); }.observes('endHour'), endMinuteChanged: function() { this._updateDate('endMinute', 'endDate'); }.observes('endMinute'), endTimeHasError: function() { var endDateError = this.get('model.errors.endDate'); return (endDateError.length > 0); }.property('model.isValid'), isAllDay: function() { var allDay = this.get('model.allDay'), isAdmissionAppointment = this.get('isAdmissionAppointment'); if (allDay) { var endDate = this.get('model.endDate'), startDate = this.get('model.startDate'); this.set('model.startDate', moment(startDate).startOf('day').toDate()); this.set('startHour', 0); this.set('startMinute', '00'); this.set('model.endDate', moment(endDate).endOf('day').toDate()); this.set('endHour', 23); this.set('endMinute', '59'); } else { if (isAdmissionAppointment) { this._updateAllTimes(); } } return allDay; }.property('model.allDay'), startHourChanged: function() { this._updateDate('startHour', 'startDate'); }.observes('startHour'), startMinuteChanged: function() { this._updateDate('startMinute', 'startDate'); }.observes('startMinute'), _updateAllTimes: function() { this.endHourChanged(); this.endMinuteChanged(); this.startMinuteChanged(); this.startHourChanged(); }, _updateAppointmentDates: function() { var allDay = this.get('model.allDay'), isAdmissionAppointment = this.get('isAdmissionAppointment'), appointmentDate = this.get('model.appointmentDate'); if (!isAdmissionAppointment) { this.set('model.endDate', appointmentDate); this.set('model.startDate', appointmentDate); if (!allDay) { this._updateAllTimes(); } } }, _updateDate: function(fieldName, dateFieldName) { var model = this.get('model'), fieldValue = this.get(fieldName), dateToChange = model.get(dateFieldName); if (!Ember.isEmpty(dateToChange)) { dateToChange = moment(dateToChange); if (fieldName.indexOf('Hour') > -1) { dateToChange.hour(fieldValue); } else { dateToChange.minute(fieldValue); } model.set(dateFieldName, dateToChange.toDate()); Ember.run.once(this, function() { model.validate().catch(Ember.K); }); } } });