diff --git a/Packages/ohif-measurements/both/configuration/measurements.js b/Packages/ohif-measurements/both/configuration/measurements.js index 06586a0f3..4a94c1373 100644 --- a/Packages/ohif-measurements/both/configuration/measurements.js +++ b/Packages/ohif-measurements/both/configuration/measurements.js @@ -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; diff --git a/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.js b/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.js index bc9631368..32e285001 100644 --- a/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.js +++ b/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.js @@ -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)); }); },