From d6aeebe71262314048e62907cc1c6a3bbf2965af Mon Sep 17 00:00:00 2001 From: Bruno Alves de Faria Date: Thu, 29 Dec 2016 14:01:09 -0200 Subject: [PATCH] LT-115: Linking the tool data with tool group data --- .../configuration/toolGroups/nonTargets.js | 7 ++- .../both/configuration/toolGroups/targets.js | 7 ++- .../both/configuration/toolGroups/temp.js | 7 ++- .../both/configuration/measurements.js | 45 +++++++++++++++++-- .../client/lib/MeasurementHandlers.js | 2 - 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Packages/ohif-lesiontracker/both/configuration/toolGroups/nonTargets.js b/Packages/ohif-lesiontracker/both/configuration/toolGroups/nonTargets.js index 452ebffe5..26a0da477 100644 --- a/Packages/ohif-lesiontracker/both/configuration/toolGroups/nonTargets.js +++ b/Packages/ohif-lesiontracker/both/configuration/toolGroups/nonTargets.js @@ -6,9 +6,12 @@ const NonTargetSchema = new SimpleSchema({ type: String, label: 'Tool ID' }, - toolItemUid: { + toolItemId: { type: String, - label: 'Tool Item UID' + label: 'Tool Item ID' + }, + createdAt: { + type: Date } }); diff --git a/Packages/ohif-lesiontracker/both/configuration/toolGroups/targets.js b/Packages/ohif-lesiontracker/both/configuration/toolGroups/targets.js index 947fae0a1..bc1df0eb2 100644 --- a/Packages/ohif-lesiontracker/both/configuration/toolGroups/targets.js +++ b/Packages/ohif-lesiontracker/both/configuration/toolGroups/targets.js @@ -8,9 +8,12 @@ const TargetSchema = new SimpleSchema({ type: String, label: 'Tool ID' }, - toolItemUid: { + toolItemId: { type: String, - label: 'Tool Item UID' + label: 'Tool Item ID' + }, + createdAt: { + type: Date } }); diff --git a/Packages/ohif-lesiontracker/both/configuration/toolGroups/temp.js b/Packages/ohif-lesiontracker/both/configuration/toolGroups/temp.js index 50bbd8e9a..377ae2ee3 100644 --- a/Packages/ohif-lesiontracker/both/configuration/toolGroups/temp.js +++ b/Packages/ohif-lesiontracker/both/configuration/toolGroups/temp.js @@ -7,9 +7,12 @@ const TempSchema = new SimpleSchema({ type: String, label: 'Tool ID' }, - toolItemUid: { + toolItemId: { type: String, - label: 'Tool Item UID' + label: 'Tool Item ID' + }, + createdAt: { + type: Date } }); diff --git a/Packages/ohif-measurements/both/configuration/measurements.js b/Packages/ohif-measurements/both/configuration/measurements.js index e16c8a3f5..79ecd8759 100644 --- a/Packages/ohif-measurements/both/configuration/measurements.js +++ b/Packages/ohif-measurements/both/configuration/measurements.js @@ -23,16 +23,53 @@ class MeasurementApi { this.tools = {}; configuration.measurementTools.forEach(toolGroup => { - const collection = new Mongo.Collection(null); - collection._debugName = toolGroup.name; - collection.attachSchema(toolGroup.schema); - this.toolGroups[toolGroup.id] = collection; + const groupCollection = new Mongo.Collection(null); + groupCollection._debugName = toolGroup.name; + groupCollection.attachSchema(toolGroup.schema); + this.toolGroups[toolGroup.id] = groupCollection; toolGroup.childTools.forEach(tool => { const collection = new Mongo.Collection(null); collection._debugName = tool.name; collection.attachSchema(tool.schema); this.tools[tool.id] = collection; + + collection.find().observe({ + added(measurement) { + groupCollection.insert({ + toolId: tool.id, + toolItemUid: measurement._id, + createdAt: measurement.createdAt + }); + + const measurementCount = groupCollection.find().count(); + collection.update(measurement._id, { + $set: { + measurementNumber: measurementCount + } + }); + }, + + removedAt(measurement, atIndex) { + groupCollection.remove({ + toolItemUid: measurement._id + }); + + toolGroup.childTools.forEach(childTool => { + this.tools[childTool.id].update({ + measurementNumber: { + $gt: atIndex + } + }, { + $inc: { + measurementNumber: -1 + } + }, { + multi: true + }); + }); + } + }); }); }); } diff --git a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js index b5a9db2ea..e0b8e37d3 100644 --- a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js +++ b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js @@ -75,9 +75,7 @@ class MeasurementHandlers { Collection._c2._simpleSchema.clean(measurement); // Insert the new measurement into the collection - console.warn('>>>>INSERTING', measurement); measurementData._id = Collection.insert(measurement); - console.warn('>>>>INSERTED', measurementData); // Signal unsaved changes OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType);