diff --git a/Packages/ohif-measurements/both/configuration/measurements.js b/Packages/ohif-measurements/both/configuration/measurements.js index d5141788d..730658f21 100644 --- a/Packages/ohif-measurements/both/configuration/measurements.js +++ b/Packages/ohif-measurements/both/configuration/measurements.js @@ -2,6 +2,7 @@ import { Mongo } from 'meteor/mongo'; import { Tracker } from 'meteor/tracker'; import { _ } from 'meteor/underscore'; import { OHIF } from 'meteor/ohif:core'; +import { cornerstoneTools } from 'meteor/ohif:cornerstone'; let configuration = {}; @@ -289,6 +290,7 @@ class MeasurementApi { toolGroup.childTools.forEach(tool => { const measurements = this.tools[tool.id].find().fetch(); measurements.forEach(measurement => { + // TODO [PWV-184] >>>> iterate over multiple overlays here OHIF.measurements.syncMeasurementAndToolData(measurement); }); }); diff --git a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js index 668776903..4a5909553 100644 --- a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js +++ b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js @@ -1,14 +1,41 @@ import { Meteor } from 'meteor/meteor'; import { $ } from 'meteor/jquery'; import { _ } from 'meteor/underscore'; +import { cornerstone } from 'meteor/ohif:cornerstone'; import { OHIF } from 'meteor/ohif:core'; class MeasurementHandlers { + static handleSingleMeasurementAdded() { + console.warn('>>>>handleSingleMeasurementAdded'); + } + + static handleChildMeasurementAdded() { + console.warn('>>>>handleChildMeasurementAdded'); + } + static onAdded(e, instance, eventData) { + const { MeasurementApi } = OHIF.measurements; + const configuration = MeasurementApi.getConfiguration(); + const toolsGroupsMap = MeasurementApi.getToolsGroupsMap(); + const { measurementApi } = instance.data; - const measurementData = eventData.measurementData; - const Collection = measurementApi.tools[eventData.toolType]; + let { measurementData, toolType } = eventData; + + const toolGroupId = toolsGroupsMap[toolType]; + const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId }); + + if (!toolGroup) return; + + console.warn('>>>>', toolType, toolGroupId, configuration.measurementTools); + const tool = _.findWhere(toolGroup.childTools, { id: toolType }); + if (tool.parentTool) { + MeasurementHandlers.handleChildMeasurementAdded(); + } else { + MeasurementHandlers.handleSingleMeasurementAdded(); + } + + const Collection = measurementApi.tools[toolType]; // Stop here if the tool data shall not be persisted (e.g. temp tools) if (!Collection) { @@ -41,7 +68,8 @@ class MeasurementHandlers { OHIF.log.info('CornerstoneToolsMeasurementAdded'); const imagePath = [studyInstanceUid, seriesInstanceUid, sopInstanceUid, frameIndex].join('_'); - let measurement = $.extend({ + let measurement = { measurementNumber: measurementData.measurementNumber }; + const additionalProperties = { userId: Meteor.userId(), patientId, studyInstanceUid, @@ -49,7 +77,13 @@ class MeasurementHandlers { sopInstanceUid, frameIndex, imagePath - }, measurementData); + }; + + if (tool.parentTool) { + measurement[tool.attribute] = _.extend({}, measurementData, additionalProperties); + } else { + _.extend(measurement, additionalProperties); + } // Get the related timepoint by the measurement number and use its location if defined const relatedTimepoint = Collection.findOne({ @@ -69,7 +103,7 @@ class MeasurementHandlers { // Insert the new measurement into the collection measurementData._id = Collection.insert(measurement); - // Get the update the measurement number after inserting + // Get the updated measurement number after inserting Meteor.defer(() => { measurementData.measurementNumber = Collection.findOne(measurementData._id).measurementNumber; cornerstone.updateImage(OHIF.viewerbase.viewportUtils.getActiveViewportElement()); @@ -141,7 +175,6 @@ class MeasurementHandlers { // Stop here if the measurement is already gone or never existed if (!measurement) return; - // Remove all the measurements with the given type and number const { measurementNumber, timepointId } = measurement; measurementApi.deleteMeasurements(measurementTypeId, { diff --git a/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js b/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js index 08b670710..0123ce2a4 100644 --- a/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js +++ b/Packages/ohif-measurements/client/lib/syncMeasurementAndToolData.js @@ -1,5 +1,5 @@ -import { $ } from 'meteor/jquery'; import { OHIF } from 'meteor/ohif:core'; +import { cornerstoneTools } from 'meteor/ohif:cornerstone'; OHIF.measurements.syncMeasurementAndToolData = measurement => { OHIF.log.info('syncMeasurementAndToolData'); @@ -41,7 +41,7 @@ OHIF.measurements.syncMeasurementAndToolData = measurement => { alreadyExists = true; // Update the toolData from the Measurement data - $.extend(tool, measurement); + Object.assign(tool, measurement); return false; });