Handling modified event on child tools

This commit is contained in:
Bruno Alves de Faria 2017-12-11 10:06:20 -02:00
parent cebb3f4f00
commit 0cdc034915
4 changed files with 94 additions and 43 deletions

View File

@ -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 },

View File

@ -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
}
});

View File

@ -2,7 +2,7 @@
{{#if hasDataAtThisTimepoint}}
<div class="measurementTableTimepointCell noselect {{#if isLoading}}loading{{/if}}" tabindex="1">
<i class="fa fa-spin fa-circle-o-notch fa-fw loading-spinner"></i>
{{displayData}}
{{{displayData}}}
</div>
{{else}}
<div class="measurementTableTimepointCell noselect empty">

View File

@ -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;