Enabling child tools labeling and removing

This commit is contained in:
Bruno Alves de Faria committed 2017-12-28 08:59:25 -02:00
1 parent 4e31faa294
commit ebcdf80d49
8 files changed
+117 -33

No files matched your search

@@ -134,7 +134,10 @@ class MeasurementHandlers {
Collection._c2._simpleSchema.clean(measurement);
// Update the measurement in the collection
Collection.update(parentMeasurement._id, { $set: { [key]: measurement[key] } });
Collection.update(parentMeasurement._id, {
$set: { [key]: measurement[key] },
$inc: { childToolsCount: 1 }
});
// Update the measurementData ID and measurementNumber
measurementData._id = parentMeasurement._id;
@@ -172,17 +175,8 @@ class MeasurementHandlers {
}
static onAdded(event, instance, eventData) {
const { MeasurementApi } = OHIF.measurements;
const configuration = MeasurementApi.getConfiguration();
const toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
const { toolType } = eventData;
const toolGroupId = toolsGroupsMap[toolType];
const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId });
if (!toolGroup) return;
const tool = _.findWhere(toolGroup.childTools, { id: toolType });
const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType);
const params = {
instance,
eventData,
@@ -191,6 +185,8 @@ class MeasurementHandlers {
toolGroup
};
if (!tool) return;
if (tool.parentTool) {
MeasurementHandlers.handleChildMeasurementAdded(params);
} else {
@@ -275,17 +271,8 @@ class MeasurementHandlers {
}
static onModified(event, instance, eventData) {
const { MeasurementApi } = OHIF.measurements;
const configuration = MeasurementApi.getConfiguration();
const toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
const { toolType } = eventData;
const toolGroupId = toolsGroupsMap[toolType];
const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId });
if (!toolGroup) return;
const tool = _.findWhere(toolGroup.childTools, { id: toolType });
const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType);
const params = {
instance,
eventData,
@@ -294,6 +281,8 @@ class MeasurementHandlers {
toolGroup
};
if (!tool) return;
if (tool.parentTool) {
MeasurementHandlers.handleChildMeasurementModified(params);
} else {
@@ -301,16 +290,14 @@ class MeasurementHandlers {
}
}
static onRemoved(e, instance, eventData) {
static handleSingleMeasurementRemoved({ instance, eventData, tool, toolGroupId, toolGroup }) {
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
const measurementData = eventData.measurementData;
const { measurementApi, timepointApi } = instance.data;
const Collection = measurementApi.tools[eventData.toolType];
// Stop here if the tool data shall not be persisted (e.g. temp tools)
if (!Collection) {
return;
}
if (!Collection) return;
const measurementTypeId = measurementApi.toolsGroupsMap[measurementData.toolType];
const measurement = Collection.findOne(measurementData._id);
@@ -335,6 +322,62 @@ class MeasurementHandlers {
// Signal unsaved changes
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);
}
static handleChildMeasurementRemoved({ instance, eventData, tool, toolGroupId, toolGroup }) {
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
const measurementData = eventData.measurementData;
const { measurementApi, timepointApi } = instance.data;
const Collection = measurementApi.tools[tool.parentTool];
// Stop here if the tool data shall not be persisted (e.g. temp tools)
if (!Collection) return;
const measurement = Collection.findOne(measurementData._id);
// Stop here if the measurement is already gone or never existed
if (!measurement) return;
if (measurement.childToolsCount === 1) {
// Remove the measurement
Collection.remove(measurement._id);
// Sync the new measurement data with cornerstone tools
const baseline = timepointApi.baseline();
measurementApi.sortMeasurements(baseline.timepointId);
} else {
// Update the measurement in the collection
Collection.update(measurement._id, {
$set: { [tool.attribute]: null },
$inc: { childToolsCount: -1 }
});
}
// Repaint the images on all viewports without the removed measurements
_.each($('.imageViewerViewport'), element => cornerstone.updateImage(element));
// Signal unsaved changes
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);
}
static onRemoved(e, instance, eventData) {
const { toolType } = eventData;
const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType);
const params = {
instance,
eventData,
tool,
toolGroupId,
toolGroup
};
if (!tool) return;
if (tool.parentTool) {
MeasurementHandlers.handleChildMeasurementRemoved(params);
} else {
MeasurementHandlers.handleSingleMeasurementRemoved(params);
}
}
}
OHIF.measurements.MeasurementHandlers = MeasurementHandlers;
@@ -0,0 +1,27 @@
import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core';
/**
* Return the tool configuration of a given tool type
*
* @param {String} toolType The tool type of the desired configuration
*/
OHIF.measurements.getToolConfiguration = toolType => {
const { MeasurementApi } = OHIF.measurements;
const configuration = MeasurementApi.getConfiguration();
const toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
const toolGroupId = toolsGroupsMap[toolType];
const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId });
let tool;
if (toolGroup) {
tool = _.findWhere(toolGroup.childTools, { id: toolType });
}
return {
toolGroupId,
toolGroup,
tool
};
};
@@ -8,6 +8,7 @@ import './getImageDataUrl';
import './getMeasurementsGroupedByNumber';
import './getLocationLabel';
import './getTimepointName';
import './getToolConfiguration';
import './hangingProtocolCustomizations';
import './MeasurementHandlers';
import './MeasurementManager';
@@ -4,7 +4,13 @@ import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core';
OHIF.measurements.toggleLabelButton = options => {
const toolType = options.measurement.toolType;
let { toolType } = options.measurement;
const { tool } = OHIF.measurements.getToolConfiguration(toolType);
if (!tool) return;
toolType = (tool && tool.parentTool) || toolType;
const measurementId = options.measurement._id;
let buttonView = null;