Started handling child measurements on tools

This commit is contained in:
Bruno Alves de Faria 2017-12-08 08:05:03 -02:00
parent 26fd6e8a2b
commit 0bc3843c70
3 changed files with 43 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import { Mongo } from 'meteor/mongo';
import { Tracker } from 'meteor/tracker'; import { Tracker } from 'meteor/tracker';
import { _ } from 'meteor/underscore'; import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
import { cornerstoneTools } from 'meteor/ohif:cornerstone';
let configuration = {}; let configuration = {};
@ -289,6 +290,7 @@ class MeasurementApi {
toolGroup.childTools.forEach(tool => { toolGroup.childTools.forEach(tool => {
const measurements = this.tools[tool.id].find().fetch(); const measurements = this.tools[tool.id].find().fetch();
measurements.forEach(measurement => { measurements.forEach(measurement => {
// TODO [PWV-184] >>>> iterate over multiple overlays here
OHIF.measurements.syncMeasurementAndToolData(measurement); OHIF.measurements.syncMeasurementAndToolData(measurement);
}); });
}); });

View File

@ -1,14 +1,41 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { $ } from 'meteor/jquery'; import { $ } from 'meteor/jquery';
import { _ } from 'meteor/underscore'; import { _ } from 'meteor/underscore';
import { cornerstone } from 'meteor/ohif:cornerstone';
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
class MeasurementHandlers { class MeasurementHandlers {
static handleSingleMeasurementAdded() {
console.warn('>>>>handleSingleMeasurementAdded');
}
static handleChildMeasurementAdded() {
console.warn('>>>>handleChildMeasurementAdded');
}
static onAdded(e, instance, eventData) { static onAdded(e, instance, eventData) {
const { MeasurementApi } = OHIF.measurements;
const configuration = MeasurementApi.getConfiguration();
const toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
const { measurementApi } = instance.data; const { measurementApi } = instance.data;
const measurementData = eventData.measurementData; let { measurementData, toolType } = eventData;
const Collection = measurementApi.tools[eventData.toolType];
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) // Stop here if the tool data shall not be persisted (e.g. temp tools)
if (!Collection) { if (!Collection) {
@ -41,7 +68,8 @@ class MeasurementHandlers {
OHIF.log.info('CornerstoneToolsMeasurementAdded'); OHIF.log.info('CornerstoneToolsMeasurementAdded');
const imagePath = [studyInstanceUid, seriesInstanceUid, sopInstanceUid, frameIndex].join('_'); const imagePath = [studyInstanceUid, seriesInstanceUid, sopInstanceUid, frameIndex].join('_');
let measurement = $.extend({ let measurement = { measurementNumber: measurementData.measurementNumber };
const additionalProperties = {
userId: Meteor.userId(), userId: Meteor.userId(),
patientId, patientId,
studyInstanceUid, studyInstanceUid,
@ -49,7 +77,13 @@ class MeasurementHandlers {
sopInstanceUid, sopInstanceUid,
frameIndex, frameIndex,
imagePath 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 // Get the related timepoint by the measurement number and use its location if defined
const relatedTimepoint = Collection.findOne({ const relatedTimepoint = Collection.findOne({
@ -69,7 +103,7 @@ class MeasurementHandlers {
// Insert the new measurement into the collection // Insert the new measurement into the collection
measurementData._id = Collection.insert(measurement); measurementData._id = Collection.insert(measurement);
// Get the update the measurement number after inserting // Get the updated measurement number after inserting
Meteor.defer(() => { Meteor.defer(() => {
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());
@ -141,7 +175,6 @@ class MeasurementHandlers {
// Stop here if the measurement is already gone or never existed // Stop here if the measurement is already gone or never existed
if (!measurement) return; if (!measurement) return;
// Remove all the measurements with the given type and number // Remove all the measurements with the given type and number
const { measurementNumber, timepointId } = measurement; const { measurementNumber, timepointId } = measurement;
measurementApi.deleteMeasurements(measurementTypeId, { measurementApi.deleteMeasurements(measurementTypeId, {

View File

@ -1,5 +1,5 @@
import { $ } from 'meteor/jquery';
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
import { cornerstoneTools } from 'meteor/ohif:cornerstone';
OHIF.measurements.syncMeasurementAndToolData = measurement => { OHIF.measurements.syncMeasurementAndToolData = measurement => {
OHIF.log.info('syncMeasurementAndToolData'); OHIF.log.info('syncMeasurementAndToolData');
@ -41,7 +41,7 @@ OHIF.measurements.syncMeasurementAndToolData = measurement => {
alreadyExists = true; alreadyExists = true;
// Update the toolData from the Measurement data // Update the toolData from the Measurement data
$.extend(tool, measurement); Object.assign(tool, measurement);
return false; return false;
}); });