LT-115: Adjusting functions to save and retrieve measurements again
This commit is contained in:
parent
c9c2cd548e
commit
f13080309e
@ -138,7 +138,9 @@ Template.viewer.onCreated(() => {
|
||||
// to hang the first measurement's imageId immediately, rather
|
||||
// than changing images after initial loading...
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const measurementTypeId = config.measurementTools[0].id;
|
||||
const tools = config.measurementTools[0].childTools;
|
||||
const firstTool = tools[Object.keys(tools)[0]];
|
||||
const measurementTypeId = firstTool.id;
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const timepointApi = instance.data.timepointApi;
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ Template.measurementLocationDialog.onCreated(() => {
|
||||
setMeasurementNumberCallback: getSetMeasurementNumberCallbackFunction(measurementTypeId, measurementApi, timepointApi),
|
||||
// TODO: Check the position for these, the Add Label button position seems very awkward
|
||||
getMeasurementLocationCallback: toggleLabel,
|
||||
changeMeasurementLocationCallback: toggleLabel,
|
||||
changeMeasurementLocationCallback: toggleLabel
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ class MeasurementApi {
|
||||
|
||||
measurements.forEach(measurement => {
|
||||
delete measurement._id;
|
||||
this.tools[measurementTypeId].insert(measurement);
|
||||
this.tools[measurement.toolType].insert(measurement);
|
||||
});
|
||||
});
|
||||
|
||||
@ -70,9 +70,14 @@ class MeasurementApi {
|
||||
}
|
||||
|
||||
let measurementData = {};
|
||||
configuration.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
measurementData[measurementTypeId] = this.tools[measurementTypeId].find().fetch();
|
||||
configuration.measurementTools.forEach(toolGroup => {
|
||||
toolGroup.childTools.forEach(tool => {
|
||||
if (!measurementData[toolGroup.id]) {
|
||||
measurementData[toolGroup.id] = [];
|
||||
}
|
||||
|
||||
measurementData[toolGroup.id] = measurementData[toolGroup.id].concat(this.tools[tool.id].find().fetch());
|
||||
});
|
||||
});
|
||||
|
||||
const timepointIds = timepoints.map(t => t.timepointId);
|
||||
@ -97,10 +102,12 @@ class MeasurementApi {
|
||||
}
|
||||
|
||||
syncMeasurementsAndToolData() {
|
||||
configuration.measurementTools.forEach(tool => {
|
||||
const measurements = this.tools[tool.id].find().fetch();
|
||||
measurements.forEach(measurement => {
|
||||
OHIF.measurements.syncMeasurementAndToolData(measurement);
|
||||
configuration.measurementTools.forEach(toolGroup => {
|
||||
toolGroup.childTools.forEach(tool => {
|
||||
const measurements = this.tools[tool.id].find().fetch();
|
||||
measurements.forEach(measurement => {
|
||||
OHIF.measurements.syncMeasurementAndToolData(measurement);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -5,19 +5,15 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
class MeasurementHandlers {
|
||||
|
||||
static onAdded(e, instance, eventData) {
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => tool.cornerstoneToolType);
|
||||
const measurementData = eventData.measurementData;
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi.tools[eventData.toolType];
|
||||
|
||||
const index = toolTypes.indexOf(eventData.toolType);
|
||||
if (index === -1) {
|
||||
// Stop here if collection was not found for the given tool
|
||||
if (!Collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
const measurementData = eventData.measurementData;
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi.tools[measurementToolConfiguration.id];
|
||||
|
||||
// Get the Cornerstone imageId
|
||||
const enabledElement = cornerstone.getEnabledElement(eventData.element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
@ -76,13 +72,15 @@ class MeasurementHandlers {
|
||||
}
|
||||
|
||||
// Clean the measurement according to the Schema
|
||||
measurementToolConfiguration.schema.clean(measurement);
|
||||
Collection._c2._simpleSchema.clean(measurement);
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
console.warn('>>>>INSERTING', measurement);
|
||||
measurementData._id = Collection.insert(measurement);
|
||||
console.warn('>>>>INSERTED', measurementData);
|
||||
|
||||
// Signal unsaved changes
|
||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + measurementToolConfiguration.id);
|
||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);
|
||||
|
||||
// Update the Overall Measurement Numbers for all Measurements
|
||||
if (timepointApi) {
|
||||
@ -97,18 +95,8 @@ class MeasurementHandlers {
|
||||
|
||||
static onModified(e, instance, eventData) {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => tool.cornerstoneToolType);
|
||||
|
||||
const index = toolTypes.indexOf(eventData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi.tools[measurementToolConfiguration.id];
|
||||
const Collection = measurementApi.tools[eventData.toolType];
|
||||
|
||||
OHIF.log.info('CornerstoneToolsMeasurementModified');
|
||||
|
||||
@ -123,12 +111,12 @@ class MeasurementHandlers {
|
||||
|
||||
// If the measurement configuration includes a value for Viewport,
|
||||
// we will populate this with the Cornerstone Viewport
|
||||
if (measurementToolConfiguration.schema.schema('viewport')) {
|
||||
if (Collection._c2._simpleSchema.schema('viewport')) {
|
||||
measurement.viewport = cornerstone.getViewport(eventData.element);
|
||||
}
|
||||
|
||||
// Clean the measurement according to the Schema
|
||||
measurementToolConfiguration.schema.clean(measurement);
|
||||
Collection._c2._simpleSchema.clean(measurement);
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
Collection.update(measurementId, {
|
||||
@ -136,30 +124,20 @@ class MeasurementHandlers {
|
||||
});
|
||||
|
||||
// Signal unsaved changes
|
||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + measurementToolConfiguration.id);
|
||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);
|
||||
}
|
||||
|
||||
static onRemoved(e, instance, eventData) {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => tool.cornerstoneToolType);
|
||||
|
||||
const index = toolTypes.indexOf(measurementData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
||||
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementData = eventData.measurementData;
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi.tools[measurementToolConfiguration.id];
|
||||
const Collection = measurementApi.tools[eventData.toolType];
|
||||
|
||||
// Remove the measurement from the collection
|
||||
Collection.remove(measurementData._id);
|
||||
|
||||
// Signal unsaved changes
|
||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + measurementToolConfiguration.id);
|
||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);
|
||||
|
||||
// Update the Overall Measurement Numbers for all Measurements
|
||||
const timepointApi = instance.data.timepointApi;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user