PWV-2: Exposing ohif:measurements package's lib functions on OHIF namespace
This commit is contained in:
1 parent
60aa1d0982
commit
5c5c2afb42
23 files changed
+254
-344
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
// Get the current measurement API configuration with information about tools, data exchange
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
import './lib';
|
||||
import './helpers';
|
||||
// import './components';
|
||||
// import './ui';
|
||||
@@ -1,153 +1,133 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { $ } from 'meteor/jquery';
|
||||
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { MeasurementManager } from 'meteor/ohif:measurements/client/lib/MeasurementManager';
|
||||
|
||||
let MeasurementHandlers = {};
|
||||
class MeasurementHandlers {
|
||||
|
||||
MeasurementHandlers.onAdded = (e, instance, eventData) => {
|
||||
const measurementData = eventData.measurementData;
|
||||
static onAdded(e, instance, eventData) {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => tool.cornerstoneToolType);
|
||||
|
||||
const index = toolTypes.indexOf(eventData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
const index = toolTypes.indexOf(eventData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi[measurementToolConfiguration.id];
|
||||
|
||||
// Get the Cornerstone imageId
|
||||
const enabledElement = cornerstone.getEnabledElement(eventData.element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
|
||||
// Get studyInstanceUid & patientId
|
||||
const study = cornerstoneTools.metaData.get('study', imageId);
|
||||
const studyInstanceUid = study.studyInstanceUid;
|
||||
const patientId = study.patientId;
|
||||
|
||||
// Get seriesInstanceUid
|
||||
const series = cornerstoneTools.metaData.get('series', imageId);
|
||||
const seriesInstanceUid = series.seriesInstanceUid;
|
||||
|
||||
// Get sopInstanceUid
|
||||
const sopInstance = cornerstoneTools.metaData.get('instance', imageId);
|
||||
const sopInstanceUid = sopInstance.sopInstanceUid;
|
||||
const frameIndex = sopInstance.frame || 0;
|
||||
|
||||
OHIF.log.info('CornerstoneToolsMeasurementAdded');
|
||||
|
||||
let measurement = $.extend({
|
||||
userId: Meteor.userId(),
|
||||
patientId: patientId,
|
||||
studyInstanceUid: studyInstanceUid,
|
||||
seriesInstanceUid: seriesInstanceUid,
|
||||
sopInstanceUid: sopInstanceUid,
|
||||
frameIndex: frameIndex,
|
||||
imageId: imageId // TODO: In the future we should consider removing this
|
||||
}, measurementData);
|
||||
|
||||
const timepointApi = instance.data.timepointApi;
|
||||
if (timepointApi) {
|
||||
const timepoint = timepointApi.study(studyInstanceUid)[0];
|
||||
const timepointId = timepoint.timepointId;
|
||||
measurement.timepointId = timepointId;
|
||||
measurement.measurementNumber = OHIF.measurements.MeasurementManager.getNewMeasurementNumber(timepointId, Collection, timepointApi);
|
||||
|
||||
// TODO: Fix this
|
||||
measurement.measurementNumberAbsolute = measurement.measurementNumber;
|
||||
} else {
|
||||
const numCurrentMeasurementsInStudy = Collection.find({
|
||||
studyInstanceUid: study.studyInstanceUid
|
||||
}).count();
|
||||
measurement.measurementNumber = numCurrentMeasurementsInStudy + 1;
|
||||
}
|
||||
|
||||
// Clean the measurement according to the Schema
|
||||
measurementToolConfiguration.schema.clean(measurement);
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
measurementData.id = Collection.insert(measurement);
|
||||
}
|
||||
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi[measurementToolConfiguration.id];
|
||||
static onModified(e, instance, eventData) {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
// Get the Cornerstone imageId
|
||||
const enabledElement = cornerstone.getEnabledElement(eventData.element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => tool.cornerstoneToolType);
|
||||
|
||||
// Get studyInstanceUid & patientId
|
||||
const study = cornerstoneTools.metaData.get('study', imageId);
|
||||
const studyInstanceUid = study.studyInstanceUid;
|
||||
const patientId = study.patientId;
|
||||
const index = toolTypes.indexOf(eventData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get seriesInstanceUid
|
||||
const series = cornerstoneTools.metaData.get('series', imageId);
|
||||
const seriesInstanceUid = series.seriesInstanceUid;
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi[measurementToolConfiguration.id];
|
||||
|
||||
// Get sopInstanceUid
|
||||
const sopInstance = cornerstoneTools.metaData.get('instance', imageId);
|
||||
const sopInstanceUid = sopInstance.sopInstanceUid;
|
||||
const frameIndex = sopInstance.frame || 0;
|
||||
OHIF.log.info('CornerstoneToolsMeasurementModified');
|
||||
|
||||
OHIF.log.info('CornerstoneToolsMeasurementAdded');
|
||||
let measurement = Collection.findOne(measurementData.id);
|
||||
|
||||
let measurement = $.extend({
|
||||
userId: Meteor.userId(),
|
||||
patientId: patientId,
|
||||
studyInstanceUid: studyInstanceUid,
|
||||
seriesInstanceUid: seriesInstanceUid,
|
||||
sopInstanceUid: sopInstanceUid,
|
||||
frameIndex: frameIndex,
|
||||
imageId: imageId // TODO: In the future we should consider removing this
|
||||
}, measurementData);
|
||||
Object.keys(measurementData).forEach(key => {
|
||||
measurement[key] = measurementData[key];
|
||||
});
|
||||
|
||||
const timepointApi = instance.data.timepointApi;
|
||||
if (timepointApi) {
|
||||
const timepoint = timepointApi.study(studyInstanceUid)[0];
|
||||
const timepointId = timepoint.timepointId;
|
||||
measurement.timepointId = timepointId;
|
||||
measurement.measurementNumber = MeasurementManager.getNewMeasurementNumber(timepointId, Collection, timepointApi);
|
||||
const measurementId = measurement._id;
|
||||
delete measurement._id;
|
||||
|
||||
// TODO: Fix this
|
||||
measurement.measurementNumberAbsolute = measurement.measurementNumber;
|
||||
} else {
|
||||
const numCurrentMeasurementsInStudy = Collection.find({
|
||||
studyInstanceUid: study.studyInstanceUid
|
||||
}).count();
|
||||
measurement.measurementNumber = numCurrentMeasurementsInStudy + 1;
|
||||
// Clean the measurement according to the Schema
|
||||
measurementToolConfiguration.schema.clean(measurement);
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
Collection.update(measurementId, {
|
||||
$set: measurement
|
||||
});
|
||||
}
|
||||
|
||||
// Clean the measurement according to the Schema
|
||||
measurementToolConfiguration.schema.clean(measurement);
|
||||
static onRemoved(e, instance, eventData) {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
measurementData.id = Collection.insert(measurement);
|
||||
};
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => tool.cornerstoneToolType);
|
||||
|
||||
MeasurementHandlers.onModified = (e, instance, eventData) => {
|
||||
const measurementData = eventData.measurementData;
|
||||
const index = toolTypes.indexOf(measurementData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
||||
|
||||
const index = toolTypes.indexOf(eventData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi[measurementToolConfiguration.id];
|
||||
|
||||
Collection.remove(measurementData.id);
|
||||
}
|
||||
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi[measurementToolConfiguration.id];
|
||||
}
|
||||
|
||||
// Get the Cornerstone imageId
|
||||
const enabledElement = cornerstone.getEnabledElement(eventData.element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
|
||||
// Get studyInstanceUid & patientId
|
||||
const study = cornerstoneTools.metaData.get('study', imageId);
|
||||
const studyInstanceUid = study.studyInstanceUid;
|
||||
const patientId = study.patientId;
|
||||
|
||||
// Get seriesInstanceUid
|
||||
const series = cornerstoneTools.metaData.get('series', imageId);
|
||||
const seriesInstanceUid = series.seriesInstanceUid;
|
||||
|
||||
// Get sopInstanceUid
|
||||
const sopInstance = cornerstoneTools.metaData.get('instance', imageId);
|
||||
const sopInstanceUid = sopInstance.sopInstanceUid;
|
||||
const frameIndex = sopInstance.frame || 0;
|
||||
|
||||
OHIF.log.info('CornerstoneToolsMeasurementModified');
|
||||
|
||||
let measurement = Collection.findOne(measurementData.id);
|
||||
|
||||
Object.keys(measurementData).forEach(key => {
|
||||
measurement[key] = measurementData[key];
|
||||
})
|
||||
|
||||
const measurementId = measurement._id;
|
||||
delete measurement._id;
|
||||
|
||||
// Clean the measurement according to the Schema
|
||||
measurementToolConfiguration.schema.clean(measurement);
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
Collection.update(measurementId, {
|
||||
$set: measurement
|
||||
});
|
||||
};
|
||||
|
||||
MeasurementHandlers.onRemoved = (e, instance, eventData) => {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
|
||||
const index = toolTypes.indexOf(measurementData.toolType);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
||||
|
||||
const measurementToolConfiguration = config.measurementTools[index];
|
||||
const measurementApi = instance.data.measurementApi;
|
||||
const Collection = measurementApi[measurementToolConfiguration.id];
|
||||
|
||||
Collection.remove(measurementData.id);
|
||||
};
|
||||
|
||||
export { MeasurementHandlers };
|
||||
OHIF.measurements.MeasurementHandlers = MeasurementHandlers;
|
||||
@@ -1,47 +1,53 @@
|
||||
/**
|
||||
* Returns new measurement number given a timepointId
|
||||
* @param timepointId
|
||||
* @param isTarget
|
||||
* @returns {*}
|
||||
*/
|
||||
function getNewMeasurementNumber(timepointId, Collection, timepointApi) {
|
||||
// Get all current lesion measurements
|
||||
const numMeasurements = Collection.find().count();
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
// If no measurements exist yet, start at 1
|
||||
if (!numMeasurements) {
|
||||
return 1;
|
||||
}
|
||||
class MeasurementManager {
|
||||
|
||||
const timepoint = timepointApi.timepoints.findOne({timepointId: timepointId});
|
||||
const numMeasurementsAtTimepoint = Collection.find({
|
||||
studyInstanceUid: {
|
||||
$in: timepoint.studyInstanceUids
|
||||
/**
|
||||
* Returns new measurement number given a timepointId
|
||||
* @param timepointId
|
||||
* @param isTarget
|
||||
* @returns {number} - Number of measurements in timepoint
|
||||
*/
|
||||
static getNewMeasurementNumber(timepointId, Collection, timepointApi) {
|
||||
// Get all current lesion measurements
|
||||
const numMeasurements = Collection.find().count();
|
||||
|
||||
// If no measurements exist yet, start at 1
|
||||
if (!numMeasurements) {
|
||||
return 1;
|
||||
}
|
||||
}).count();
|
||||
|
||||
return numMeasurementsAtTimepoint + 1;
|
||||
}
|
||||
const timepoint = timepointApi.timepoints.findOne({
|
||||
timepointId: timepointId
|
||||
});
|
||||
|
||||
/**
|
||||
* If the current Measurements Number already exists
|
||||
* for any other timepoint, returns lesion locationUID
|
||||
* @param measurementData
|
||||
* @returns {*}
|
||||
*/
|
||||
function getLocationIdIfMeasurementExists(measurementData, Collection) {
|
||||
const measurement = Collection.findOne({
|
||||
measurementNumber: measurementData.measurementNumber
|
||||
});
|
||||
const numMeasurementsAtTimepoint = Collection.find({
|
||||
studyInstanceUid: {
|
||||
$in: timepoint.studyInstanceUids
|
||||
}
|
||||
}).count();
|
||||
|
||||
if (!measurement) {
|
||||
return;
|
||||
return numMeasurementsAtTimepoint + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the current Measurements Number already exists
|
||||
* for any other timepoint, returns lesion locationUID
|
||||
* @param measurementData
|
||||
* @returns {number} - Measurement location ID
|
||||
*/
|
||||
static getLocationIdIfMeasurementExists(measurementData, Collection) {
|
||||
const measurement = Collection.findOne({
|
||||
measurementNumber: measurementData.measurementNumber
|
||||
});
|
||||
|
||||
if (!measurement) {
|
||||
return;
|
||||
}
|
||||
|
||||
return measurement.locationId;
|
||||
}
|
||||
|
||||
return measurement.locationId;
|
||||
}
|
||||
|
||||
export const MeasurementManager = {
|
||||
getNewMeasurementNumber: getNewMeasurementNumber,
|
||||
getLocationIdIfMeasurementExists: getLocationIdIfMeasurementExists
|
||||
};
|
||||
OHIF.measurements.MeasurementManager = MeasurementManager;
|
||||
@@ -76,7 +76,7 @@ OHIF.measurements.activateLesion = (measurementId, templateData) => {
|
||||
const measurementAtTimepoint = orderedTimepointEntries[viewportIndex];
|
||||
|
||||
// Find the image that is currently in this viewport
|
||||
var enabledElement = cornerstone.getEnabledElement(element);
|
||||
const enabledElement = cornerstone.getEnabledElement(element);
|
||||
if (!enabledElement || !enabledElement.image) {
|
||||
return;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ OHIF.measurements.activateLesion = (measurementId, templateData) => {
|
||||
|
||||
// Otherwise, re-render the viewport with the required study/series, then
|
||||
// add an onRendered callback to activate the measurements
|
||||
layoutManager.rerenderViewportWithNewDisplaySet(element, requiredSeriesData, element => {
|
||||
window.layoutManager.rerenderViewportWithNewDisplaySet(element, requiredSeriesData, element => {
|
||||
activateMeasurements(element, measurementId, templateData, viewportIndex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ OHIF.measurements.activateMeasurements = (element, measurementId, templateData,
|
||||
|
||||
const enabledElement = cornerstone.getEnabledElement(element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
const timepointData = getTimepointObject(imageId);
|
||||
const timepointData = OHIF.measurements.getTimepointObject(imageId);
|
||||
const measurementData = Measurements.findOne(measurementId);
|
||||
|
||||
if (!timepointData) {
|
||||
@@ -27,7 +27,7 @@ OHIF.measurements.activateMeasurements = (element, measurementId, templateData,
|
||||
// If type is inactive, update lesions of enabledElement as inactive
|
||||
//TODO: !stackData.currentImageIdIndex returns incorrect value
|
||||
// Get loadedSeriesData currentImageIdIndex from ViewerData
|
||||
const viewerData = ViewerData[templateData.contentId];
|
||||
const viewerData = window.ViewerData[templateData.contentId];
|
||||
const loadedSeriesData = viewerData.loadedSeriesData[viewportIndex];
|
||||
const elementCurrentImageIdIndex = loadedSeriesData.currentImageIdIndex;
|
||||
|
||||
|
||||
@@ -17,23 +17,23 @@ OHIF.measurements.activateTool = (element, measurementData, timepointId) => {
|
||||
OHIF.measurements.deactivateAllToolData(element, 'unTool');
|
||||
OHIF.measurements.deactivateAllToolData(element, 'exTool');
|
||||
|
||||
var toolType = measurementData.toolType;
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
const toolType = measurementData.toolType;
|
||||
const toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
if (!toolData) {
|
||||
return;
|
||||
}
|
||||
|
||||
var measurementAtTimepoint = measurementData.timepoints[timepointId];
|
||||
const measurementAtTimepoint = measurementData.timepoints[timepointId];
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
data = toolData.data[i];
|
||||
for (let i = 0; i < toolData.data.length; i++) {
|
||||
const data = toolData.data[i];
|
||||
|
||||
// When click a row of table measurements, measurement will be active and color will be green
|
||||
// TODO= Remove this with the measurementId once it is in the tool data
|
||||
if (data.seriesInstanceUid === measurementAtTimepoint.seriesInstanceUid &&
|
||||
data.studyInstanceUid === measurementAtTimepoint.studyInstanceUid &&
|
||||
data.lesionNumber === measurementData.lesionNumber &&
|
||||
data.isTarget == measurementData.isTarget) {
|
||||
data.isTarget === measurementData.isTarget) {
|
||||
|
||||
data.active = true;
|
||||
break;
|
||||
|
||||
@@ -8,13 +8,12 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
* @param toolType The tooltype of the tools that will be deactivated
|
||||
*/
|
||||
OHIF.measurements.deactivateAllToolData = (element, toolType) => {
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
const toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
if (!toolData) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
data.active = false;
|
||||
for (let i = 0; i < toolData.data.length; i++) {
|
||||
toolData.data[i].active = false;
|
||||
}
|
||||
};
|
||||
@@ -8,14 +8,14 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
* @param timepoint
|
||||
* @returns {*} The timepoint name
|
||||
*/
|
||||
OHIF.measurements.getTimepointName = (timepoint) => {
|
||||
OHIF.measurements.getTimepointName = timepoint => {
|
||||
// Check if this is a Baseline timepoint, if it is, return 'Baseline'
|
||||
if (timepoint.timepointType === 'baseline') {
|
||||
return 'Baseline';
|
||||
}
|
||||
|
||||
// Retrieve all of the relevant follow-up timepoints for this patient
|
||||
var followupTimepoints = Timepoints.find({
|
||||
const followupTimepoints = Timepoints.find({
|
||||
patientId: timepoint.patientId,
|
||||
timepointType: timepoint.timepointType
|
||||
}, {
|
||||
@@ -26,13 +26,11 @@ OHIF.measurements.getTimepointName = (timepoint) => {
|
||||
|
||||
// Create an array of just timepointIds, so we can use indexOf
|
||||
// on it to find the current timepoint's relative position
|
||||
var followupTimepointIds = followupTimepoints.map(function(timepoint) {
|
||||
return timepoint.timepointId;
|
||||
});
|
||||
const followupTimepointIds = followupTimepoints.map(timepoint => timepoint.timepointId);
|
||||
|
||||
// Calculate the index of the current timepoint in the array of all
|
||||
// relevant follow-up timepoints
|
||||
var index = followupTimepointIds.indexOf(timepoint.timepointId) + 1;
|
||||
const index = followupTimepointIds.indexOf(timepoint.timepointId) + 1;
|
||||
|
||||
// If index is 0, it means that the current timepoint was not in the list
|
||||
// Log a warning and return here
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
/**
|
||||
* Returns timepoint object given a specified imageId
|
||||
*
|
||||
* @param imageId
|
||||
* @returns {*|{}} Timepoint object
|
||||
*/
|
||||
getTimepointObject = function(imageId) {
|
||||
var study = cornerstoneTools.metaData.get('study', imageId);
|
||||
OHIF.measurements.getTimepointObject = imageId => {
|
||||
const study = cornerstoneTools.metaData.get('study', imageId);
|
||||
if (!study) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
// TODO: [LT-refactor] move this to ohif:hanging-protocols package
|
||||
|
||||
getTimepointType = function(study) {
|
||||
const getTimepointType = study => {
|
||||
const timepointApi = Template.instance().timepointApi;
|
||||
if (!timepointApi) {
|
||||
return;
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { $ } from 'meteor/jquery';
|
||||
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
function toolDataExists(toolState, imageId, toolType) {
|
||||
const currentToolState = toolState[imageId][toolType];
|
||||
return (currentToolState && currentToolState.data && currentToolState.data.length);
|
||||
}
|
||||
|
||||
syncMeasurementAndToolData = function(measurement) {
|
||||
OHIF.measurements.syncMeasurementAndToolData = measurement => {
|
||||
OHIF.log.info('syncMeasurementAndToolData');
|
||||
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
@@ -17,18 +14,19 @@ syncMeasurementAndToolData = function(measurement) {
|
||||
toolState[imageId] = {};
|
||||
}
|
||||
|
||||
const currentToolState = toolState[imageId][toolType];
|
||||
const toolData = currentToolState && currentToolState.data;
|
||||
|
||||
// Check if we already have toolData for this imageId and toolType
|
||||
if (toolDataExists(toolState, imageId, toolType)) {
|
||||
// If we have toolData, we should search it for any toolData
|
||||
// related to the current Measurement
|
||||
if (toolData && toolData.length) {
|
||||
// If we have toolData, we should search it for any data related to the current Measurement
|
||||
const toolData = toolState[imageId][toolType].data;
|
||||
|
||||
// Create a flag so we know if we have successfully updated
|
||||
// this Measurement's in the toolData
|
||||
// Create a flag so we know if we've successfully updated the Measurement in the toolData
|
||||
let alreadyExists = false;
|
||||
|
||||
// Loop through the toolData to search for this Measurement
|
||||
toolData.forEach(function(tool) {
|
||||
toolData.forEach(tool => {
|
||||
// Break the loop if this isn't the Measurement we are looking for
|
||||
if (tool._id !== measurement._id) {
|
||||
return;
|
||||
@@ -42,8 +40,7 @@ syncMeasurementAndToolData = function(measurement) {
|
||||
return false;
|
||||
});
|
||||
|
||||
// If we have found the Measurement we intended to update, we can stop
|
||||
// this function here
|
||||
// If we have found the Measurement we intended to update, we can stop this function here
|
||||
if (alreadyExists === true) {
|
||||
return;
|
||||
}
|
||||
@@ -54,8 +51,8 @@ syncMeasurementAndToolData = function(measurement) {
|
||||
};
|
||||
}
|
||||
|
||||
// If we have reached this point, it means we haven't found the Measurement we are
|
||||
// looking for in the current toolData. This means we need to add it.
|
||||
// If we have reached this point, it means we haven't found the Measurement we are looking for
|
||||
// in the current toolData. This means we need to add it.
|
||||
|
||||
// Add the MeasurementData into the toolData for this imageId
|
||||
toolState[imageId][toolType].data.push(measurement);
|
||||
|
||||
Reference in new issue
Block a user