Linking child tools

This commit is contained in:
Bruno Alves de Faria 2017-12-11 11:49:42 -02:00
parent 0cdc034915
commit 4e31faa294

View File

@ -112,12 +112,40 @@ class MeasurementHandlers {
userId: Meteor.userId() userId: Meteor.userId()
}); });
const childMeasurement = _.extend({}, measurementData, additionalProperties);
const parentMeasurement = Collection.findOne({
toolType: tool.parentTool,
patientId: imageAttributes.patientId,
[tool.attribute]: null
});
// Check if a measurement to fit this child tool already exists
if (parentMeasurement) {
const key = tool.attribute;
// Add the createdAt attribute
childMeasurement.createdAt = new Date();
// Add the child measurement
measurement[key] = childMeasurement;
// Clean the measurement according to the Schema
Collection._c2._simpleSchema.clean(measurement);
// Update the measurement in the collection
Collection.update(parentMeasurement._id, { $set: { [key]: measurement[key] } });
// Update the measurementData ID and measurementNumber
measurementData._id = parentMeasurement._id;
measurementData.measurementNumber = parentMeasurement.measurementNumber;
} else {
measurement[tool.attribute] = _.extend({}, measurementData, additionalProperties); measurement[tool.attribute] = _.extend({}, measurementData, additionalProperties);
// 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: measurement.toolType, toolType: tool.parentTool,
patientId: imageAttributes.patientId patientId: imageAttributes.patientId
}); });
@ -137,6 +165,7 @@ class MeasurementHandlers {
measurementData.measurementNumber = Collection.findOne(measurementData._id).measurementNumber; measurementData.measurementNumber = Collection.findOne(measurementData._id).measurementNumber;
cornerstone.updateImage(OHIF.viewerbase.viewportUtils.getActiveViewportElement()); cornerstone.updateImage(OHIF.viewerbase.viewportUtils.getActiveViewportElement());
}); });
}
// Signal unsaved changes // Signal unsaved changes
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType); OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);