LT-297: Fixing all measurements number after removal
This commit is contained in:
parent
8520b2aea8
commit
5d02b76453
@ -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) {
|
fetch(measurementTypeId, selector, options) {
|
||||||
if (!this[measurementTypeId]) {
|
if (!this[measurementTypeId]) {
|
||||||
throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId;
|
throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId;
|
||||||
|
|||||||
@ -45,47 +45,23 @@ Template.measurementTableRow.events({
|
|||||||
},
|
},
|
||||||
|
|
||||||
'click .js-delete'(event, instance) {
|
'click .js-delete'(event, instance) {
|
||||||
const measurementTypeId = instance.data.rowItem.measurementTypeId;
|
|
||||||
const measurement = instance.data.rowItem.entries[0];
|
|
||||||
|
|
||||||
const dialogSettings = {
|
const dialogSettings = {
|
||||||
title: 'Delete measurements',
|
title: 'Delete measurements',
|
||||||
message: 'Are you sure you want to delete the measurement among all timepoints?'
|
message: 'Are you sure you want to delete the measurement among all timepoints?'
|
||||||
};
|
};
|
||||||
|
|
||||||
OHIF.ui.showFormDialog('dialogConfirm', dialogSettings).then(formData => {
|
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 = {
|
// Remove all the measurements with the given type and number
|
||||||
toolType: measurement.toolType,
|
api.deleteMeasurements(measurementTypeId, toolType, measurementNumber);
|
||||||
measurementNumber: measurement.measurementNumber,
|
|
||||||
patientId: measurement.patientId
|
|
||||||
};
|
|
||||||
|
|
||||||
const entries = collection.find(filter).fetch();
|
// Repaint the images on all viewports without the removed measurements
|
||||||
|
_.each($('.imageViewerViewport'), element => cornerstone.updateImage(element));
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user