diff --git a/app/models/appointment.js b/app/models/appointment.js index 74e88eed97..19d683727b 100644 --- a/app/models/appointment.js +++ b/app/models/appointment.js @@ -4,11 +4,8 @@ import Ember from 'ember'; import PatientValidation from 'hospitalrun/utils/patient-validation'; export default AbstractModel.extend({ + // Attributes allDay: DS.attr(), - patient: DS.belongsTo('patient', { - async: false - }), - visits: DS.hasMany('visit'), provider: DS.attr('string'), location: DS.attr('string'), appointmentType: DS.attr('string'), @@ -17,6 +14,11 @@ export default AbstractModel.extend({ notes: DS.attr('string'), status: DS.attr('string', { defaultValue: 'Scheduled' }), + // Associations + patient: DS.belongsTo('patient', { async: false }), + visits: DS.hasMany('visit'), + + // Formats longDateFormat: 'l h:mm A', shortDateFormat: 'l', timeFormat: 'h:mm A', diff --git a/app/models/billing-line-item.js b/app/models/billing-line-item.js index 1b7317d0cc..3989d38c3f 100644 --- a/app/models/billing-line-item.js +++ b/app/models/billing-line-item.js @@ -4,16 +4,17 @@ import Ember from 'ember'; import NumberFormat from 'hospitalrun/mixins/number-format'; export default AbstractModel.extend(NumberFormat, { + // Attributes amountOwed: DS.attr('number'), category: DS.attr('string'), description: DS.attr('string'), - details: DS.hasMany('line-item-detail', { - async: false - }), /* The individual objects that make up this line item. */ discount: DS.attr('number'), name: DS.attr('string'), nationalInsurance: DS.attr('number'), privateInsurance: DS.attr('number'), + // Associations + /* The individual objects that make up this line item. */ + details: DS.hasMany('line-item-detail', { async: false }), amountOwedChanged: function() { Ember.run.debounce(this, function() { diff --git a/app/models/imaging.js b/app/models/imaging.js index f7c41736ca..80fc21a803 100644 --- a/app/models/imaging.js +++ b/app/models/imaging.js @@ -2,37 +2,35 @@ import AbstractModel from 'hospitalrun/models/abstract'; import CanEditRequested from 'hospitalrun/mixins/can-edit-requested'; import DateFormat from 'hospitalrun/mixins/date-format'; import DS from 'ember-data'; +import Ember from 'ember'; import PatientValidation from 'hospitalrun/utils/patient-validation'; import ResultValidation from 'hospitalrun/mixins/result-validation'; +const { computed } = Ember; + export default AbstractModel.extend(CanEditRequested, DateFormat, ResultValidation, { - charges: DS.hasMany('proc-charge', { - async: false - }), + // Attributes imagingDate: DS.attr('date'), - imagingType: DS.belongsTo('pricing', { - async: false - }), notes: DS.attr('string'), - patient: DS.belongsTo('patient', { - async: false - }), radiologist: DS.attr('string'), requestedBy: DS.attr('string'), requestedDate: DS.attr('date'), result: DS.attr('string'), status: DS.attr('string'), - visit: DS.belongsTo('visit', { - async: false - }), - imagingDateAsTime: function() { + // Associations + charges: DS.hasMany('proc-charge', { async: false }), + imagingType: DS.belongsTo('pricing', { async: false }), + patient: DS.belongsTo('patient', { async: false }), + visit: DS.belongsTo('visit', { async: false }), + + imagingDateAsTime: computed('imagingDate', function() { return this.dateToTime(this.get('imagingDate')); - }.property('imagingDate'), + }), - requestedDateAsTime: function() { + requestedDateAsTime: computed('requestedDate', function() { return this.dateToTime(this.get('requestedDate')); - }.property('requestedDate'), + }), validations: { imagingTypeName: { diff --git a/app/models/inventory.js b/app/models/inventory.js index f550d5962d..3c8a5d8799 100644 --- a/app/models/inventory.js +++ b/app/models/inventory.js @@ -5,49 +5,50 @@ import computed from 'ember-computed'; import LocationName from 'hospitalrun/mixins/location-name'; import { rankToMultiplier, getCondition } from 'hospitalrun/utils/item-condition'; +const { get, set } = Ember; + let validateIfNewItem = { if: function validateNewItem(object) { - let skipSavePurchase = object.get('skipSavePurchase'); + let skipSavePurchase = get(object, 'skipSavePurchase'); // Only validate on new items and only if we are saving a purchase. - return (!skipSavePurchase && object.get('isNew')); + return (!skipSavePurchase && get(object, 'isNew')); } }; export default AbstractModel.extend(LocationName, { - purchases: DS.hasMany('inv-purchase', { - async: false - }), - locations: DS.hasMany('inv-location', { - async: false - }), + // Attributes + crossReference: DS.attr('string'), description: DS.attr('string'), + distributionUnit: DS.attr('string'), friendlyId: DS.attr('string'), + inventoryType: DS.attr('string'), keywords: DS.attr(), name: DS.attr('string'), - quantity: DS.attr('number'), - crossReference: DS.attr('string'), - inventoryType: DS.attr('string'), price: DS.attr('number'), - reorderPoint: DS.attr('number'), - distributionUnit: DS.attr('string'), + quantity: DS.attr('number'), rank: DS.attr('string'), + reorderPoint: DS.attr('number'), + + // Associations + locations: DS.hasMany('inv-location', { async: false }), + purchases: DS.hasMany('inv-purchase', { async: false }), // TODO: this value should be server calcuated property on model! estimatedDaysOfStock: 14, availableLocations: computed('locations.@each.quantity', function() { - let locations = this.get('locations').filter((location) => { - return location.get('quantity') > 0; + let locations = get(this, 'locations').filter((location) => { + return get(location, 'quantity') > 0; }); return locations; }), displayLocations: computed('availableLocations', function() { - let locations = this.get('availableLocations'); + let locations = get(this, 'availableLocations'); let returnLocations = []; locations.forEach((currentLocation) => { - let aisleLocationName = currentLocation.get('aisleLocation'); - let locationName = currentLocation.get('location'); + let aisleLocationName = get(currentLocation, 'aisleLocation'); + let locationName = get(currentLocation, 'location'); let displayLocationName = this.formatLocationName(locationName, aisleLocationName); if (!Ember.isEmpty(displayLocationName)) { returnLocations.push(displayLocationName); @@ -57,8 +58,8 @@ export default AbstractModel.extend(LocationName, { }), condition: computed('rank', 'estimatedDaysOfStock', function() { - let estimatedDaysOfStock = this.get('estimatedDaysOfStock'); - let multiplier = rankToMultiplier(this.get('rank')); + let estimatedDaysOfStock = get(this, 'estimatedDaysOfStock'); + let multiplier = rankToMultiplier(get(this, 'rank')); return getCondition(estimatedDaysOfStock, multiplier); }), @@ -101,7 +102,7 @@ export default AbstractModel.extend(LocationName, { }, updateQuantity() { - let purchases = this.get('purchases'); + let purchases = get(this, 'purchases'); let newQuantity = purchases.reduce((previousItem, currentItem) => { let currentQuantity = 0; if (!currentItem.get('expired')) { @@ -109,6 +110,6 @@ export default AbstractModel.extend(LocationName, { } return previousItem + currentQuantity; }, 0); - this.set('quantity', newQuantity); + set(this, 'quantity', newQuantity); } }); diff --git a/app/models/option.js b/app/models/option.js index bf571c14f3..204528d83e 100644 --- a/app/models/option.js +++ b/app/models/option.js @@ -1,5 +1,6 @@ import { Model } from 'ember-pouch'; import DS from 'ember-data'; + export default Model.extend({ value: DS.attr('') -}); +}); \ No newline at end of file diff --git a/app/models/override-price.js b/app/models/override-price.js index e95e7e77cf..bc4f49ea5a 100644 --- a/app/models/override-price.js +++ b/app/models/override-price.js @@ -2,10 +2,12 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; export default AbstractModel.extend({ - profile: DS.belongsTo('price-profile', { - async: false - }), + // Attributes price: DS.attr('number'), + + // Associations + profile: DS.belongsTo('price-profile', { async: false }), + validations: { profile: { presence: true diff --git a/app/models/payment.js b/app/models/payment.js index 649be4c3c9..5b8d8bccce 100644 --- a/app/models/payment.js +++ b/app/models/payment.js @@ -1,20 +1,25 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; +import Ember from 'ember'; + +const { computed, get } = Ember; export default AbstractModel.extend({ + // Attributes amount: DS.attr('number'), - charityPatient: DS.attr('boolean'), // Is patient a charity case - expenseAccount: DS.attr('string'), - invoice: DS.belongsTo('invoice', { - async: false - }), + /* Is patient a charity case */ + charityPatient: DS.attr('boolean'), datePaid: DS.attr('date'), - paymentType: DS.attr('string'), + expenseAccount: DS.attr('string'), notes: DS.attr('string'), + paymentType: DS.attr('string'), - canRemovePayment: function() { - return (this.get('paymentType') === 'Deposit'); - }.property('paymentType'), + // Associations + invoice: DS.belongsTo('invoice', { async: false }), + + canRemovePayment: computed('paymentType', function() { + return get(this, 'paymentType') === 'Deposit'; + }), validations: { amount: { diff --git a/app/models/photo.js b/app/models/photo.js index b281e27352..43c41eba9e 100644 --- a/app/models/photo.js +++ b/app/models/photo.js @@ -2,13 +2,15 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; export default AbstractModel.extend({ - _attachments: DS.attr(), // Temporarily store file as attachment until it gets uploaded to the server + // Attributes + /* Temporarily store file as attachment until it gets uploaded to the server */ + _attachments: DS.attr(), + caption: DS.attr('string'), coverImage: DS.attr('boolean'), fileName: DS.attr('string'), localFile: DS.attr('boolean'), - patient: DS.belongsTo('patient', { - async: false - }), - caption: DS.attr('string'), - url: DS.attr('string') + url: DS.attr('string'), + + // Associations + patient: DS.belongsTo('patient', { async: false }) }); diff --git a/app/models/pricing.js b/app/models/pricing.js index ab675f6457..11301697da 100644 --- a/app/models/pricing.js +++ b/app/models/pricing.js @@ -2,14 +2,15 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; export default AbstractModel.extend({ + // Attributes category: DS.attr('string'), expenseAccount: DS.attr('string'), name: DS.attr('string'), price: DS.attr('number'), pricingType: DS.attr('string'), - pricingOverrides: DS.hasMany('override-price', { - async: false - }), + + // Associations + pricingOverrides: DS.hasMany('override-price', { async: false }), validations: { category: { diff --git a/app/models/procedure.js b/app/models/procedure.js index 6a1ad0b1e1..7f0317da9f 100644 --- a/app/models/procedure.js +++ b/app/models/procedure.js @@ -2,13 +2,11 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; export default AbstractModel.extend({ + // Attributes anesthesiaType: DS.attr('string'), anesthesiologist: DS.attr('string'), assistant: DS.attr('string'), description: DS.attr('string'), - charges: DS.hasMany('proc-charge', { - async: false - }), cptCode: DS.attr('string'), location: DS.attr('string'), notes: DS.attr('string'), @@ -16,9 +14,10 @@ export default AbstractModel.extend({ procedureDate: DS.attr('date'), timeStarted: DS.attr('string'), timeEnded: DS.attr('string'), - visit: DS.belongsTo('visit', { - async: false - }), + + // Associations + charges: DS.hasMany('proc-charge', { async: false }), + visit: DS.belongsTo('visit', { async: false }), validations: { description: { diff --git a/app/models/sequence.js b/app/models/sequence.js index ffa5e29fb4..370b02759b 100644 --- a/app/models/sequence.js +++ b/app/models/sequence.js @@ -1,6 +1,8 @@ import { Model } from 'ember-pouch'; import DS from 'ember-data'; + export default Model.extend({ + // Attributes prefix: DS.attr('string'), value: DS.attr('number') }); diff --git a/app/models/social-expense.js b/app/models/social-expense.js index 64f281bc28..e535d9e18a 100644 --- a/app/models/social-expense.js +++ b/app/models/social-expense.js @@ -4,10 +4,13 @@ import DS from 'ember-data'; import EmberValidations from 'ember-validations'; import { Model } from 'ember-pouch'; + export default Model.extend(EmberValidations, { + // Attributes category: DS.attr('string'), sources: DS.attr('string'), cost: DS.attr(), + validations: { category: { presence: true diff --git a/app/models/user-role.js b/app/models/user-role.js index f8cb0b9556..4c48927047 100644 --- a/app/models/user-role.js +++ b/app/models/user-role.js @@ -1,6 +1,8 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; + export default AbstractModel.extend({ + // Attributes name: DS.attr('string'), capabilities: DS.attr() -}); +}); \ No newline at end of file diff --git a/app/models/user.js b/app/models/user.js index 854b3e3642..db1c71affe 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -2,7 +2,11 @@ import DS from 'ember-data'; import EmailValidation from 'hospitalrun/utils/email-validation'; import Ember from 'ember'; import EmberValidations from 'ember-validations'; + +const { computed } = Ember; + let User = DS.Model.extend(EmberValidations, { + // Attributes derived_key: DS.attr('string'), deleted: DS.attr('boolean'), displayName: DS.attr('string'), @@ -17,18 +21,18 @@ let User = DS.Model.extend(EmberValidations, { salt: DS.attr('string'), userPrefix: DS.attr('string'), - displayRole: function() { + displayRole: computed('roles', function() { let roles = this.get('roles'); if (!Ember.isEmpty(roles)) { return roles[0]; } - }.property('roles'), + }), validations: { email: { format: { with: EmailValidation.emailRegex, - message: 'please enter a valid email address' + message: 'Please, enter a valid email address' } } } diff --git a/app/models/vital.js b/app/models/vital.js index 7fffa09d8d..d775d41cab 100644 --- a/app/models/vital.js +++ b/app/models/vital.js @@ -2,14 +2,16 @@ import AbstractModel from 'hospitalrun/models/abstract'; import DS from 'ember-data'; export default AbstractModel.extend({ + // Attributes dateRecorded: DS.attr('date'), - temperature: DS.attr('number'), - weight: DS.attr('string'), - height: DS.attr('string'), - sbp: DS.attr('number'), dbp: DS.attr('number'), heartRate: DS.attr('number'), + height: DS.attr('string'), respiratoryRate: DS.attr('number'), + sbp: DS.attr('number'), + temperature: DS.attr('number'), + weight: DS.attr('string'), + validations: { temperature: { numericality: true