Handling modified event on child tools
This commit is contained in:
parent
cebb3f4f00
commit
0cdc034915
@ -55,9 +55,7 @@ class MeasurementApi {
|
|||||||
|
|
||||||
// Preventing errors thrown when non-associated (standalone) study is opened...
|
// Preventing errors thrown when non-associated (standalone) study is opened...
|
||||||
// @TODO: Make sure this logic is correct.
|
// @TODO: Make sure this logic is correct.
|
||||||
if (!timepoint) {
|
if (!timepoint) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emptyItem = groupCollection.findOne({
|
const emptyItem = groupCollection.findOne({
|
||||||
toolId: { $eq: null },
|
toolId: { $eq: null },
|
||||||
|
|||||||
@ -34,24 +34,21 @@ const Measurement = new SimpleSchema({
|
|||||||
if (this.isInsert) {
|
if (this.isInsert) {
|
||||||
return new Date();
|
return new Date();
|
||||||
} else if (this.isUpsert) {
|
} else if (this.isUpsert) {
|
||||||
return {
|
return { $setOnInsert: new Date() };
|
||||||
$setOnInsert: new Date()
|
|
||||||
};
|
|
||||||
} else {
|
} 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
|
// Force value to be current date (on server) upon update
|
||||||
// and don't allow it to be set upon insert.
|
|
||||||
updatedAt: {
|
updatedAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
autoValue: function() {
|
autoValue: function() {
|
||||||
if (this.isUpdate) {
|
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
|
optional: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
{{#if hasDataAtThisTimepoint}}
|
{{#if hasDataAtThisTimepoint}}
|
||||||
<div class="measurementTableTimepointCell noselect {{#if isLoading}}loading{{/if}}" tabindex="1">
|
<div class="measurementTableTimepointCell noselect {{#if isLoading}}loading{{/if}}" tabindex="1">
|
||||||
<i class="fa fa-spin fa-circle-o-notch fa-fw loading-spinner"></i>
|
<i class="fa fa-spin fa-circle-o-notch fa-fw loading-spinner"></i>
|
||||||
{{displayData}}
|
{{{displayData}}}
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="measurementTableTimepointCell noselect empty">
|
<div class="measurementTableTimepointCell noselect empty">
|
||||||
|
|||||||
@ -39,19 +39,15 @@ class MeasurementHandlers {
|
|||||||
|
|
||||||
static handleSingleMeasurementAdded({ instance, eventData, tool }) {
|
static handleSingleMeasurementAdded({ instance, eventData, tool }) {
|
||||||
const { measurementApi } = instance.data;
|
const { measurementApi } = instance.data;
|
||||||
let { measurementData, toolType } = eventData;
|
const { measurementData, toolType } = eventData;
|
||||||
|
|
||||||
const Collection = measurementApi.tools[toolType];
|
const Collection = measurementApi.tools[toolType];
|
||||||
|
|
||||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||||
if (!Collection) {
|
if (!Collection) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop here if there's no measurement data or if it was cancelled
|
// Stop here if there's no measurement data or if it was cancelled
|
||||||
if (!measurementData || measurementData.cancelled) {
|
if (!measurementData || measurementData.cancelled) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OHIF.log.info('CornerstoneToolsMeasurementAdded');
|
OHIF.log.info('CornerstoneToolsMeasurementAdded');
|
||||||
|
|
||||||
@ -91,25 +87,27 @@ class MeasurementHandlers {
|
|||||||
|
|
||||||
static handleChildMeasurementAdded({ instance, eventData, tool, toolGroupId, toolGroup }) {
|
static handleChildMeasurementAdded({ instance, eventData, tool, toolGroupId, toolGroup }) {
|
||||||
const { measurementApi } = instance.data;
|
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)
|
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||||
if (!Collection) {
|
if (!Collection) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop here if there's no measurement data or if it was cancelled
|
// Stop here if there's no measurement data or if it was cancelled
|
||||||
if (!measurementData || measurementData.cancelled) {
|
if (!measurementData || measurementData.cancelled) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OHIF.log.info('CornerstoneToolsMeasurementAdded');
|
OHIF.log.info('CornerstoneToolsMeasurementAdded');
|
||||||
|
|
||||||
const measurement = { measurementNumber: measurementData.measurementNumber };
|
|
||||||
|
|
||||||
const imageAttributes = getImageAttributes(eventData.element);
|
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, {
|
const additionalProperties = _.extend(imageAttributes, {
|
||||||
userId: Meteor.userId()
|
userId: Meteor.userId()
|
||||||
});
|
});
|
||||||
@ -119,7 +117,7 @@ class MeasurementHandlers {
|
|||||||
// Get the related timepoint by the measurement number and use its location if defined
|
// Get the related timepoint by the measurement number and use its location if defined
|
||||||
const relatedTimepoint = Collection.findOne({
|
const relatedTimepoint = Collection.findOne({
|
||||||
measurementNumber: measurement.measurementNumber,
|
measurementNumber: measurement.measurementNumber,
|
||||||
toolType: measurementData.toolType,
|
toolType: measurement.toolType,
|
||||||
patientId: imageAttributes.patientId
|
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 { measurementApi } = instance.data;
|
||||||
const measurementData = eventData.measurementData;
|
const { measurementData, toolType } = eventData;
|
||||||
const Collection = measurementApi.tools[eventData.toolType];
|
|
||||||
|
const Collection = measurementApi.tools[toolType];
|
||||||
|
|
||||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||||
if (!Collection) {
|
if (!Collection) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OHIF.log.info('CornerstoneToolsMeasurementModified');
|
OHIF.log.info('CornerstoneToolsMeasurementModified');
|
||||||
|
|
||||||
let measurement = Collection.findOne(measurementData._id);
|
const measurement = Collection.findOne(measurementData._id);
|
||||||
|
|
||||||
// Stop here if the measurement is already deleted
|
// Stop here if the measurement is already deleted
|
||||||
if (!measurement) return;
|
if (!measurement) return;
|
||||||
@ -204,18 +201,77 @@ class MeasurementHandlers {
|
|||||||
measurement.viewport = cornerstone.getViewport(eventData.element);
|
measurement.viewport = cornerstone.getViewport(eventData.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean the measurement according to the Schema
|
// Update the measurement in the collection
|
||||||
Collection._c2._simpleSchema.clean(_.clone(measurement));
|
Collection.update(measurementId, { $set: measurement });
|
||||||
|
|
||||||
// Insert the new measurement into the collection
|
|
||||||
Collection.update(measurementId, {
|
|
||||||
$set: measurement
|
|
||||||
});
|
|
||||||
|
|
||||||
// Signal unsaved changes
|
// Signal unsaved changes
|
||||||
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);
|
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) {
|
static onRemoved(e, instance, eventData) {
|
||||||
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
||||||
const measurementData = eventData.measurementData;
|
const measurementData = eventData.measurementData;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user