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

Minor models changes #912

Merged
merged 11 commits into from
Jan 10, 2017
10 changes: 6 additions & 4 deletions app/models/appointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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',
Expand Down
7 changes: 4 additions & 3 deletions app/models/billing-line-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
30 changes: 14 additions & 16 deletions app/models/imaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
45 changes: 23 additions & 22 deletions app/models/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}),
Expand Down Expand Up @@ -101,14 +102,14 @@ 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')) {
currentQuantity = currentItem.get('currentQuantity');
}
return previousItem + currentQuantity;
}, 0);
this.set('quantity', newQuantity);
set(this, 'quantity', newQuantity);
}
});
3 changes: 2 additions & 1 deletion app/models/option.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Model } from 'ember-pouch';
import DS from 'ember-data';

export default Model.extend({
value: DS.attr('')
});
});
8 changes: 5 additions & 3 deletions app/models/override-price.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions app/models/payment.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
14 changes: 8 additions & 6 deletions app/models/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
});
7 changes: 4 additions & 3 deletions app/models/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
11 changes: 5 additions & 6 deletions app/models/procedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ 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'),
physician: DS.attr('string'),
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: {
Expand Down
2 changes: 2 additions & 0 deletions app/models/sequence.js
Original file line number Diff line number Diff line change
@@ -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')
});
3 changes: 3 additions & 0 deletions app/models/social-expense.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/models/user-role.js
Original file line number Diff line number Diff line change
@@ -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()
});
});
10 changes: 7 additions & 3 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'
}
}
}
Expand Down
Loading