Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Modified proc-charge model #918

Merged
merged 2 commits into from
Jan 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions app/models/proc-charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,46 @@ import DS from 'ember-data';
import Ember from 'ember';
import MedicationDetails from 'hospitalrun/mixins/medication-details';

const { computed, get } = Ember;

/**
* Procedure charges
*/
export default AbstractModel.extend(MedicationDetails, {
medication: DS.belongsTo('inventory', {
async: false
}),
pricingItem: DS.belongsTo('pricing', {
async: false
}),
// Attributes
quantity: DS.attr('number'),
dateCharged: DS.attr('date'),

medicationCharge: function() {
let medication = this.get('medication');
let newMedicationCharge = this.get('newMedicationCharge');
return (!Ember.isEmpty(medication) || !Ember.isEmpty(newMedicationCharge));
}.property('medication', 'newMedicationCharge'),
// Associations
medication: DS.belongsTo('inventory', { async: false }),
pricingItem: DS.belongsTo('pricing', { async: false }),

medicationName: function() {
medicationCharge: computed('medication', 'newMedicationCharge', function() {
let medication = get(this, 'medication');
let newMedicationCharge = get(this, 'newMedicationCharge');
return !Ember.isEmpty(medication) || !Ember.isEmpty(newMedicationCharge);
}),

medicationName: computed('medication', function() {
return this.get('medication.name');
}.property('medication'),
}),

medicationPrice: function() {
medicationPrice: computed('medication', function() {
return this.get('medication.price');
}.property('medication'),
}),

validations: {
itemName: {
presence: true,
acceptance: {
accept: true,
if(object) {
let medicationCharge = object.get('medicationCharge');
if (!medicationCharge || !object.get('hasDirtyAttributes')) {
let medicationCharge = get(object, 'medicationCharge');
if (!medicationCharge || !get(object, 'hasDirtyAttributes')) {
return false;
}
let itemName = object.get('inventoryItem.name');
let itemTypeAhead = object.get('itemName');
let itemName = get(object, 'inventoryItem.name');
let itemTypeAhead = get(object, 'itemName');
if (Ember.isEmpty(itemName) || Ember.isEmpty(itemTypeAhead)) {
// force validation to fail
return true;
Expand Down