LT-297: Fixing all measurements number after removal

This commit is contained in:
Bruno Alves de Faria 2016-11-11 12:30:18 -02:00 committed by Erik Ziegler
parent 8520b2aea8
commit 5d02b76453
2 changed files with 52 additions and 33 deletions

View File

@ -90,6 +90,49 @@ class MeasurementApi {
});
}
deleteMeasurements(measurementTypeId, toolType, measurementNumber) {
const collection = this[measurementTypeId];
const filter = {
toolType,
measurementNumber
};
// Get the entries information before removing them
const entries = collection.find(filter).fetch();
collection.remove(filter);
// Synchronize the new data with cornerstone tools
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
_.each(entries, entry => {
if (toolState[entry.imageId]) {
const toolData = toolState[entry.imageId][entry.toolType];
const measurementsData = toolData && toolData.data;
const measurementEntry = _.findWhere(measurementsData, {
_id: entry._id
});
if (measurementEntry) {
const index = measurementsData.indexOf(measurementEntry);
measurementsData.splice(index, 1);
}
}
});
// Update the measurement numbers for the remaning measurements
const updateFilter = _.clone(filter);
updateFilter.measurementNumber = {
$gt: measurementNumber
};
collection.update(updateFilter, {
$inc: {
measurementNumber: -1
}
}, {
multi: true
});
}
fetch(measurementTypeId, selector, options) {
if (!this[measurementTypeId]) {
throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId;

View File

@ -45,47 +45,23 @@ Template.measurementTableRow.events({
},
'click .js-delete'(event, instance) {
const measurementTypeId = instance.data.rowItem.measurementTypeId;
const measurement = instance.data.rowItem.entries[0];
const dialogSettings = {
title: 'Delete measurements',
message: 'Are you sure you want to delete the measurement among all timepoints?'
};
OHIF.ui.showFormDialog('dialogConfirm', dialogSettings).then(formData => {
const collection = instance.data.measurementApi[measurementTypeId];
const measurementTypeId = instance.data.rowItem.measurementTypeId;
const measurement = instance.data.rowItem.entries[0];
const toolType = measurement.toolType;
const measurementNumber = measurement.measurementNumber;
const api = instance.data.measurementApi;
const filter = {
toolType: measurement.toolType,
measurementNumber: measurement.measurementNumber,
patientId: measurement.patientId
};
// Remove all the measurements with the given type and number
api.deleteMeasurements(measurementTypeId, toolType, measurementNumber);
const entries = collection.find(filter).fetch();
collection.remove(filter);
// Synchronize the new data with cornerstone tools
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
_.each(entries, entry => {
if (toolState[entry.imageId]) {
const toolData = toolState[entry.imageId][entry.toolType];
const measurementsData = toolData && toolData.data;
const measurementEntry = _.findWhere(measurementsData, {
_id: entry._id
});
if (measurementEntry) {
console.warn('>>>>REMOVING FROM CORNERSTONE', measurementEntry);
const index = measurementsData.indexOf(measurementEntry);
measurementsData.splice(index, 1);
// Repaint the images on all viewports without the removed measurements
_.each($('.imageViewerViewport'), elm => cornerstone.updateImage(elm));
}
}
});
// Repaint the images on all viewports without the removed measurements
_.each($('.imageViewerViewport'), element => cornerstone.updateImage(element));
});
},