diff --git a/Packages/ohif-measurements/both/configuration/measurements.js b/Packages/ohif-measurements/both/configuration/measurements.js index 730658f21..39c7b616b 100644 --- a/Packages/ohif-measurements/both/configuration/measurements.js +++ b/Packages/ohif-measurements/both/configuration/measurements.js @@ -55,9 +55,7 @@ class MeasurementApi { // Preventing errors thrown when non-associated (standalone) study is opened... // @TODO: Make sure this logic is correct. - if (!timepoint) { - return; - } + if (!timepoint) return; const emptyItem = groupCollection.findOne({ toolId: { $eq: null }, diff --git a/Packages/ohif-measurements/both/schema/measurements.js b/Packages/ohif-measurements/both/schema/measurements.js index bc0dcb111..ea7ffc901 100644 --- a/Packages/ohif-measurements/both/schema/measurements.js +++ b/Packages/ohif-measurements/both/schema/measurements.js @@ -34,24 +34,21 @@ const Measurement = new SimpleSchema({ if (this.isInsert) { return new Date(); } else if (this.isUpsert) { - return { - $setOnInsert: new Date() - }; + return { $setOnInsert: new Date() }; } else { - this.unset(); // Prevent user from supplying their own value + // [PWV-184] Preventing unset due to child tools updating + // this.unset(); // Prevent user from supplying their own value } } }, // Force value to be current date (on server) upon update - // and don't allow it to be set upon insert. updatedAt: { type: Date, autoValue: function() { if (this.isUpdate) { - return new Date(); + // return new Date(); } }, - // denyInsert: true, // Commenting this out for now since we are constantly re-adding entries to client-side collections optional: true } }); diff --git a/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.html b/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.html index d740dff5c..b7ebd029b 100644 --- a/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.html +++ b/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.html @@ -2,7 +2,7 @@ {{#if hasDataAtThisTimepoint}}
- {{displayData}} + {{{displayData}}}
{{else}}
diff --git a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js index ff6624214..7cd510c14 100644 --- a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js +++ b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js @@ -39,19 +39,15 @@ class MeasurementHandlers { static handleSingleMeasurementAdded({ instance, eventData, tool }) { const { measurementApi } = instance.data; - let { measurementData, toolType } = eventData; + const { measurementData, toolType } = eventData; const Collection = measurementApi.tools[toolType]; // Stop here if the tool data shall not be persisted (e.g. temp tools) - if (!Collection) { - return; - } + if (!Collection) return; // Stop here if there's no measurement data or if it was cancelled - if (!measurementData || measurementData.cancelled) { - return; - } + if (!measurementData || measurementData.cancelled) return; OHIF.log.info('CornerstoneToolsMeasurementAdded'); @@ -91,25 +87,27 @@ class MeasurementHandlers { static handleChildMeasurementAdded({ instance, eventData, tool, toolGroupId, toolGroup }) { const { measurementApi } = instance.data; - let { measurementData, toolType } = eventData; + const { measurementData } = eventData; - const Collection = measurementApi.tools[toolType]; + const Collection = measurementApi.tools[tool.parentTool]; // Stop here if the tool data shall not be persisted (e.g. temp tools) - if (!Collection) { - return; - } + if (!Collection) return; // Stop here if there's no measurement data or if it was cancelled - if (!measurementData || measurementData.cancelled) { - return; - } + if (!measurementData || measurementData.cancelled) return; OHIF.log.info('CornerstoneToolsMeasurementAdded'); - const measurement = { measurementNumber: measurementData.measurementNumber }; - const imageAttributes = getImageAttributes(eventData.element); + const measurement = { + toolType: tool.parentTool, + measurementNumber: measurementData.measurementNumber, + userId: Meteor.userId(), + patientId: imageAttributes.patientId, + studyInstanceUid: imageAttributes.studyInstanceUid + }; + const additionalProperties = _.extend(imageAttributes, { userId: Meteor.userId() }); @@ -119,7 +117,7 @@ class MeasurementHandlers { // Get the related timepoint by the measurement number and use its location if defined const relatedTimepoint = Collection.findOne({ measurementNumber: measurement.measurementNumber, - toolType: measurementData.toolType, + toolType: measurement.toolType, patientId: imageAttributes.patientId }); @@ -171,19 +169,18 @@ class MeasurementHandlers { } } - static onModified(e, instance, eventData) { + static handleSingleMeasurementModified({ instance, eventData, tool, toolGroupId, toolGroup }) { const { measurementApi } = instance.data; - const measurementData = eventData.measurementData; - const Collection = measurementApi.tools[eventData.toolType]; + const { measurementData, toolType } = eventData; + + const Collection = measurementApi.tools[toolType]; // Stop here if the tool data shall not be persisted (e.g. temp tools) - if (!Collection) { - return; - } + if (!Collection) return; OHIF.log.info('CornerstoneToolsMeasurementModified'); - let measurement = Collection.findOne(measurementData._id); + const measurement = Collection.findOne(measurementData._id); // Stop here if the measurement is already deleted if (!measurement) return; @@ -204,18 +201,77 @@ class MeasurementHandlers { measurement.viewport = cornerstone.getViewport(eventData.element); } - // Clean the measurement according to the Schema - Collection._c2._simpleSchema.clean(_.clone(measurement)); - - // Insert the new measurement into the collection - Collection.update(measurementId, { - $set: measurement - }); + // Update the measurement in the collection + Collection.update(measurementId, { $set: measurement }); // Signal unsaved changes OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType); } + static handleChildMeasurementModified({ instance, eventData, tool, toolGroupId, toolGroup }) { + const { measurementApi } = instance.data; + const { measurementData } = eventData; + + const Collection = measurementApi.tools[tool.parentTool]; + + // Stop here if the tool data shall not be persisted (e.g. temp tools) + if (!Collection) return; + + OHIF.log.info('CornerstoneToolsMeasurementModified'); + + const measurement = Collection.findOne(measurementData._id); + const childMeasurement = measurement && measurement[tool.attribute]; + + // Stop here if the measurement is already deleted + if (!childMeasurement) return; + + // Update the collection data with the cornerstone measurement data + const ignoredKeys = ['location', 'description', 'response']; + Object.keys(measurementData).forEach(key => { + if (_.contains(ignoredKeys, key)) return; + childMeasurement[key] = measurementData[key]; + }); + + // If the measurement configuration includes a value for Viewport, + // we will populate this with the Cornerstone Viewport + if (Collection._c2._simpleSchema.schema(`${tool.attribute}.viewport`)) { + childMeasurement.viewport = cornerstone.getViewport(eventData.element); + } + + // Update the measurement in the collection + Collection.update(measurement._id, { $set: { [tool.attribute]: childMeasurement } }); + + // Signal unsaved changes + OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType); + } + + 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 params = { + instance, + eventData, + tool, + toolGroupId, + toolGroup + }; + + if (tool.parentTool) { + MeasurementHandlers.handleChildMeasurementModified(params); + } else { + MeasurementHandlers.handleSingleMeasurementModified(params); + } + } + static onRemoved(e, instance, eventData) { OHIF.log.info('CornerstoneToolsMeasurementRemoved'); const measurementData = eventData.measurementData;