Move decrementing to server and out of observe hook

This commit is contained in:
Erik Ziegler 2016-01-11 19:47:19 +01:00
parent fdde2f9ff9
commit 906f7c6234
2 changed files with 27 additions and 34 deletions

View File

@ -181,34 +181,26 @@ Template.viewer.onCreated(function() {
removeToolDataWithMeasurementId(imageId, toolType, measurementId);
});
// Update all Measurements to decrement the lesion numbers for those
// that were created after the current lesion by 1
Meteor.call('decrementLesionNumbers', data, function(error, response) {
if (error) {
log.warn(error);
// Sync database data with toolData for all the measurements
// that have just been updated
// Note that here we need to use greater than and equals to
// find the Measurements, whereas on the server it's
// only "greater than", since inside this callback the
// Measurements have already been decremented.
Measurements.find({
patientId: data.patientId,
lesionNumberAbsolute: {
$gte: data.lesionNumberAbsolute
}
}).forEach(function(measurementData) {
syncMeasurementAndToolData(measurementData);
});
// Sync database data with toolData for all the measurements
// that have just been updated
// Note that here we need to use greater than and equals to
// find the Measurements, whereas on the server it's
// only "greater than", since inside this callback the
// Measurements have already been decremented.
Measurements.find({
patientId: data.patientId,
lesionNumberAbsolute: {
$gte: data.lesionNumberAbsolute
}
}).forEach(function(measurementData) {
syncMeasurementAndToolData(measurementData);
});
// Update each displayed viewport
var viewports = $('.imageViewerViewport').not('.empty');
viewports.each(function(index, element) {
cornerstone.updateImage(element);
});
// Update each displayed viewport
var viewports = $('.imageViewerViewport').not('.empty');
viewports.each(function(index, element) {
cornerstone.updateImage(element);
});
}
});

View File

@ -1,13 +1,7 @@
Meteor.methods({
removeMeasurement: function(id) {
Measurements.remove(id);
},
removeMeasurementsByPatientId: function(patientId) {
Measurements.remove({
patientId: patientId
});
},
decrementLesionNumbers: function(lesionData) {
var lesionData = Measurements.findOne(id);
// Update all Measurements to decrement the lesion numbers for those
// that were created after the current lesion by 1
@ -42,5 +36,12 @@ Meteor.methods({
}, {
multi: true
});
Measurements.remove(id);
},
removeMeasurementsByPatientId: function(patientId) {
Measurements.remove({
patientId: patientId
});
}
});