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

Commit

Permalink
Added the ability to request multiple lab and imaging requests at once
Browse files Browse the repository at this point in the history
Resolves #49
Resolves #50
  • Loading branch information
jkleinsc committed Jul 23, 2015
1 parent 35225e0 commit 62bd339
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 200 deletions.
23 changes: 16 additions & 7 deletions app/controllers/abstract-edit-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ export default Ember.ObjectController.extend(IsUpdateDisabled, ModalHelper, User
*/
update: function(skipAfterUpdate) {
this.beforeUpdate().then(function() {
this.get('model').save().then(function(record){
this.updateLookupLists();
if (!skipAfterUpdate) {
this.afterUpdate(record);
}
}.bind(this));
this.saveModel(skipAfterUpdate);
}.bind(this));
}
},
Expand All @@ -130,7 +125,21 @@ export default Ember.ObjectController.extend(IsUpdateDisabled, ModalHelper, User
*/
beforeUpdate: function() {
return Ember.RSVP.Promise.resolve();
},
},

/**
* Save the model and then (optionally) run the after update.
* @param skipAfterUpdate boolean (optional) indicating whether or not
* to skip the afterUpdate call.
*/
saveModel: function(skipAfterUpdate) {
this.get('model').save().then(function(record){
this.updateLookupLists();
if (!skipAfterUpdate) {
this.afterUpdate(record);
}
}.bind(this));
},

/**
* Update any new values added to a lookup list
Expand Down
102 changes: 51 additions & 51 deletions app/imaging/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {
chargeRoute: 'imaging.charge',

canComplete: function() {
return this.currentUserCan('complete_imaging');
}.property(),
var imagingTypeName = this.get('selectedImagingType');
if (Ember.isArray(imagingTypeName) && imagingTypeName.length >1) {
return false;
} else {
return this.currentUserCan('complete_imaging');
}
}.property('selectedImagingType.[]'),

actions: {
completeImaging: function() {
Expand All @@ -20,7 +25,42 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {
this.set('imagingDate', new Date());
this.send('update');
}
}
},

/**
* Save the imaging request(s), creating multiples when user selects multiple imaging tests.
*/
update: function() {
if (this.get('isNew')) {
var newImaging = this.get('model'),
selectedImagingType = this.get('selectedImagingType');
if (Ember.isEmpty(this.get('status'))) {
this.set('status', 'Requested');
}
this.set('requestedBy', newImaging.getUserName());
this.set('requestedDate', new Date());
if (Ember.isEmpty(selectedImagingType)) {
this.saveNewPricing(this.get('imagingTypeName'), 'Imaging','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('imagingType', pricingRecords);
this.addChildToVisit(newImaging, 'imaging', 'Imaging').then(function() {
this.saveModel();
}.bind(this));
}
}.bind(this));
}
} else {
this.saveModel();
}
}
},

additionalButtons: function() {
Expand Down Expand Up @@ -49,30 +89,12 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {

radiologistList: Ember.computed.alias('controllers.imaging.radiologistList'),

imagingTypeChanged: function() {
this.objectTypeChanged('imagingTypeName', 'imagingType');
}.observes('imagingType'),

imagingTypeNameChanged: function() {
this.objectTypeNameChanged('imagingTypeName', 'selectedImagingType');
}.observes('imagingTypeName'),

showCharges: function() {
var imagingType = this.get('imagingType'),
patient = this.get('patient'),
visit = this.get('visit');
return (!Ember.isEmpty(imagingType) && !Ember.isEmpty(patient) &&
!Ember.isEmpty(visit));
}.property('imagingType','patient', 'visit'),

updateCapability: 'add_imaging',

selectedImagingTypeChanged: function() {
this.selectedObjectTypeChanged('selectedImagingType', 'imagingType');
}.observes('selectedImagingType'),

afterUpdate: function() {
var alertTitle,
afterUpdate: function(saveResponse, multipleRecords) {
this.updateLookupLists();
var afterDialogAction,
alertTitle,
alertMessage;
if (this.get('status') === 'Completed') {
alertTitle = 'Imaging Request Completed';
Expand All @@ -81,33 +103,11 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {
alertTitle = 'Imaging Request Saved';
alertMessage = 'The imaging request has been saved.';
}
this.saveVisitIfNeeded(alertTitle, alertMessage);
this.set('selectPatient', false);
},

beforeUpdate: function() {
if (!this.get('isValid')) {
return Ember.RSVP.reject();
if (multipleRecords) {
afterDialogAction = 'allItems';
}
return new Ember.RSVP.Promise(function(resolve, reject) {
this.updateCharges().then(function() {
if (this.get('isNew')) {
var newImaging = this.get('model');
this.set('status', 'Requested');
this.set('requestedBy', newImaging.getUserName());
this.set('requestedDate', new Date());
if (this.get('newObjectType')) {
this.saveNewPricing(this.get('imagingTypeName'), 'Imaging','imagingType').then(function() {
this.addChildToVisit(newImaging, 'imaging', 'Imaging').then(resolve, reject);
}.bind(this), reject);
} else {
return this.addChildToVisit(newImaging, 'imaging', 'Imaging').then(resolve, reject);
}
} else {
resolve();
}
}.bind(this), reject);
}.bind(this), 'beforeUpdate on imaging edit');
this.saveVisitIfNeeded(alertTitle, alertMessage, afterDialogAction);
this.set('selectPatient', false);
}

});
34 changes: 17 additions & 17 deletions app/imaging/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
{{patient-typeahead property="patientTypeAhead" label="Patient" content=patientList selection=selectedPatient class="required"}}
{{else}}
{{patient-summary patient=patient returnTo='imaging.edit' returnToContext=id disablePatientLink=isNew }}
{{/if}}
<div class="row">
{{#if isNew}}
{{/if}}
{{#if isNew}}
<div class="row">
{{em-select class="col-xs-3 required" label="Visit"
property="visit" content=patientVisits
optionValuePath="content" optionLabelPath="content.visitDescription"
prompt="--Add New Visit--"
selected=visit
}}
{{else}}
</div>
{{checkbox-or-typeahead property="imagingTypeName"
label="Imaging Type" list=objectTypeList
selection=selectedImagingType
optionLabelPath='content.name'
typeAheadType='pricing'
class="required"
prompt=" "
model=model
}}
{{else}}
<div class="row">
<div class="form-group col-xs-3">
<label>Visit</label>
<p class="form-control-static">{{visit.visitDate}}</p>
</div>
{{/if}}
{{#if isNew}}
{{select-or-typeahead property="imagingTypeName"
label="Imaging Type" list=objectTypeList
selection=selectedImagingType
optionLabelPath='content.name'
typeAheadType='pricing'
class="required col-xs-9"
prompt=" "
}}
{{else}}
<div class="form-group col-xs-9">
<label>Imaging Type</label>
<p class="form-control-static">{{imagingType.name}}</p>
</div>
{{/if}}
</div>
</div>
{{/if}}
{{#if canComplete}}
{{select-or-typeahead property="radiologist"
label="Radiologist" list=radiologistList
Expand Down
98 changes: 49 additions & 49 deletions app/labs/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {


canComplete: function() {
return this.currentUserCan('complete_lab');
}.property(),
var labTypeName = this.get('selectedLabType');
if (Ember.isArray(labTypeName) && labTypeName.length >1) {
return false;
} else {
return this.currentUserCan('complete_lab');
}
}.property('selectedLabType.[]'),

actions: {
completeLab: function() {
Expand All @@ -21,6 +26,41 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {
this.set('labDate', new Date());
this.send('update');
}
},

/**
* Update the model and perform the before update and after update
*/
update: function() {
if (this.get('isNew')) {
var newLab = this.get('model'),
selectedLabType = this.get('selectedLabType');
if (Ember.isEmpty(this.get('status'))) {
this.set('status', 'Requested');
}
this.set('requestedBy', newLab.getUserName());
this.set('requestedDate', new Date());
if (Ember.isEmpty(selectedLabType)) {
this.saveNewPricing(this.get('labTypeName'), 'Lab', 'labType').then(function() {
this.addChildToVisit(newLab, 'labs', 'Lab').then(function() {
this.saveModel();
}.bind(this));
}.bind(this));
} else {
this.getSelectedPricing('selectedLabType').then(function(pricingRecords) {
if (Ember.isArray(pricingRecords)) {
this.createMultipleRequests(pricingRecords, 'labType','labs', 'Lab');
} else {
this.set('labType', pricingRecords);
this.addChildToVisit(newLab, 'labs', 'Lab').then(function() {
this.saveModel();
}.bind(this));
}
}.bind(this));
}
} else {
this.saveModel();
}
}
},

Expand All @@ -42,30 +82,11 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {

pricingList: null, //This gets filled in by the route

labTypeChanged: function() {
this.objectTypeChanged('labTypeName', 'labType');
}.observes('labType'),

labTypeNameChanged: function() {
this.objectTypeNameChanged('labTypeName', 'selectedLabType');
}.observes('labTypeName'),

showCharges: function() {
var labType = this.get('labType'),
patient = this.get('patient'),
visit = this.get('visit');
return (!Ember.isEmpty(labType) && !Ember.isEmpty(patient) &&
!Ember.isEmpty(visit));
}.property('labType','patient', 'visit'),

updateCapability: 'add_lab',

selectedLabTypeChanged: function() {
this.selectedObjectTypeChanged('selectedLabType', 'labType');
}.observes('selectedLabType'),

afterUpdate: function() {
var alertMessage,
afterUpdate: function(saveResponse, multipleRecords) {
var afterDialogAction,
alertMessage,
alertTitle;
if (this.get('status') === 'Completed') {
alertTitle = 'Lab Request Completed';
Expand All @@ -74,32 +95,11 @@ export default AbstractEditController.extend(ChargeActions, PatientSubmodule, {
alertTitle = 'Lab Request Saved';
alertMessage = 'The lab request has been saved.';
}
this.saveVisitIfNeeded(alertTitle, alertMessage);
},

beforeUpdate: function() {
if (!this.get('isValid')) {
return Ember.RSVP.reject();
if (multipleRecords) {
afterDialogAction = 'allItems';
}
return new Ember.RSVP.Promise(function(resolve, reject) {
this.updateCharges().then(function() {
if (this.get('isNew')) {
var newLab = this.get('model');
this.set('status', 'Requested');
this.set('requestedBy', newLab.getUserName());
this.set('requestedDate', new Date());
if (this.get('newObjectType')) {
this.saveNewPricing(this.get('labTypeName'), 'Lab', 'labType').then(function() {
this.addChildToVisit(newLab, 'labs', 'Lab').then(resolve, reject);
}.bind(this), reject);
} else {
return this.addChildToVisit(newLab, 'labs', 'Lab').then(resolve, reject);
}
} else {
resolve();
}
}.bind(this), reject);
}.bind(this), 'beforeUpdate on lab edit');
this.saveVisitIfNeeded(alertTitle, alertMessage, afterDialogAction);
this.set('selectPatient', false);
}

});
Loading

0 comments on commit 62bd339

Please sign in to comment.