Fixed bug LT-85 (Location Response Selections). Work on LT-9 and LT-12

This commit is contained in:
Erik Ziegler committed 2015-12-20 18:24:51 -05:00
1 parent 28cee350ff
commit 220ff065dc
44 files changed
+1515 -824

No files matched your search

@@ -0,0 +1,96 @@
/**
* Activates a set of lesions when lesion table row is clicked
*
* @param measurementId The unique key for a specific Measurement
*/
activateLesion = function(measurementId, templateData) {
// Set background color of selected row
$("tr[data-measurementid=" + measurementId + "]").addClass("selectedRow").siblings().removeClass("selectedRow");
var measurementData = Measurements.findOne(measurementId);
// If there is no measurement with this ID, stop here
if (!measurementData) {
log.warn('No Measurements entry associated to an ID in a lesion table row');
return;
}
// Get the timepoint data from this Measurement
var timepoints = measurementData.timepoints;
// Get all non-dummy timepoint entries in the Measurement
// TODO=Re-evaluate this approach to populating viewports with timepoints
// What is the desired behaviour here?
var timepointsWithEntries = [];
Object.keys(timepoints).forEach(function(key) {
var timepoint = timepoints[key];
if (timepoint.imageId === "" ||
timepoint.studyInstanceUid === "" ||
timepoint.seriesInstanceUid === "") {
return;
}
timepointsWithEntries.push(timepoint);
});
// If there are no non-dummy timepoint entries, stop here
if (!timepointsWithEntries.length) {
return;
}
// Loop through the viewports and display each timepoint
$(".imageViewerViewport").each(function(viewportIndex, element) {
// Stop if we run out of timepoints before viewports
if (viewportIndex >= timepointsWithEntries.length) {
// Update the element anyway, to remove any other highlights that are present
deactivateAllToolData(element, 'lesion');
deactivateAllToolData(element, 'nonTarget');
cornerstone.updateImage(element);
return false;
}
// Find measurements related to the Nth timepoint
// TODO=Re-evaluate this approach to populating viewports with timepoints
// What is the desired behaviour here?
var measurementAtTimepoint = timepointsWithEntries[viewportIndex];
// Find the image that is currently in this viewport
var enabledElement = cornerstone.getEnabledElement(element);
if (!enabledElement || !enabledElement.image) {
return;
}
// If there is no measurement data to display, stop here
if (!measurementAtTimepoint) {
// Update the element anyway, to remove any other highlights that are present
deactivateAllToolData(element, 'lesion');
deactivateAllToolData(element, 'nonTarget');
cornerstone.updateImage(element);
return;
}
// Check which study and series are required to display the measurement at this timepoint
var requiredSeriesData = {
seriesInstanceUid: measurementAtTimepoint.seriesInstanceUid,
studyInstanceUid: measurementAtTimepoint.studyInstanceUid
};
// Check if the study / series we need is already the one in the viewport
var currentSeriesData = OHIF.viewer.loadedSeriesData[viewportIndex];
if (currentSeriesData.seriesInstanceUid === measurementAtTimepoint.seriesInstanceUid &&
currentSeriesData.studyInstanceUid === measurementAtTimepoint.studyInstanceUid) {
// If it is, activate the measurements in this viewport and stop here
activateMeasurements(element, measurementId, templateData, viewportIndex);
return;
}
// Otherwise, re-render the viewport with the required study/series, then
// add an onRendered callback to activate the measurements
rerenderViewportWithNewSeries(element, requiredSeriesData, function(element) {
activateMeasurements(element, measurementId, templateData, viewportIndex);
});
});
};
@@ -0,0 +1,83 @@
/**
* Switch to the image of the correct image index
* Activate the selected measurement on the switched image (color to be green)
* Deactivate all other measurements on the switched image (color to be white)
*/
activateMeasurements = function(element, measurementId, templateData, viewportIndex) {
// TODO=Switch this to use the new CornerstoneToolMeasurementModified event,
// Once it has 'modified on activation' set up
var enabledElement = cornerstone.getEnabledElement(element);
var imageId = enabledElement.image.imageId;
var timepointData = getTimepointObject(imageId);
var measurementData = Measurements.findOne(measurementId);
var measurementAtTimepoint = measurementData.timepoints[timepointData.timepointID];
if (!measurementAtTimepoint) {
return;
}
// If type is active, load image and activate lesion
// If type is inactive, update lesions of enabledElement as inactive
//TODO: !stackData.currentImageIdIndex returns incorrect value
// Get loadedSeriesData currentImageIdIndex from ViewerData
var contentId = templateData.contentId;
var viewerData = ViewerData[contentId];
var elementCurrentImageIdIndex = viewerData.loadedSeriesData[viewportIndex].currentImageIdIndex;
var stackToolDataSource = cornerstoneTools.getToolState(element, 'stack');
var stackData = stackToolDataSource.data[0];
var imageIds = stackData.imageIds;
var imageIdIndex = imageIds.indexOf(measurementAtTimepoint.imageId);
if (imageIdIndex < 0) {
return;
}
if (imageIdIndex === elementCurrentImageIdIndex) {
activateTool(element, measurementData, timepointData.timepointID);
} else {
cornerstone.loadAndCacheImage(imageIds[imageIdIndex]).then(function(image) {
cornerstone.displayImage(element, image);
activateTool(element, measurementData, timepointData.timepointID);
});
}
};
/**
* Activates a specific tool data instance and deactivates all other
* target and non-target measurement data
*
* @param element
* @param measurementData
* @param timepointID
*/
function activateTool(element, measurementData, timepointID) {
deactivateAllToolData(element, 'lesion');
deactivateAllToolData(element, 'nonTarget');
var toolType = measurementData.isTarget ? 'lesion' : 'nonTarget';
var toolData = cornerstoneTools.getToolState(element, toolType);
if (!toolData) {
return;
}
var measurementAtTimepoint = measurementData.timepoints[timepointID];
for (var i = 0; i < toolData.data.length; i++) {
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.active = true;
break;
}
}
cornerstone.updateImage(element);
}
@@ -0,0 +1,34 @@
clearMeasurementTimepointData = function(measurementId, timepointId) {
var data = Measurements.findOne(measurementId);
// Check that this Measurement actually contains data for this timepoint
if (!data || !data.timepoints[timepointId]) {
return;
}
// Clear the Measurement data for this timepoint
var imageId = data.timepoints[timepointId].imageId;
var toolType = data.isTarget ? 'lesion' : 'nonTarget';
removeToolDataWithMeasurementId(imageId, toolType, measurementId);
// Update any viewports that are currently displaying this imageId
var enabledElements = cornerstone.getEnabledElementsByImageId(imageId);
enabledElements.forEach(function(enabledElement) {
cornerstone.updateImage(enabledElement.element);
});
delete data.timepoints[timepointId];
if (Object.keys(data.timepoints).length === 0) {
Meteor.call("removeMeasurement", measurementId, function(error, response) {
console.log('Removed!');
});
} else {
// Update the Timepoint object of the Measurement document
Measurements.update(measurementId, {
$set: {
timepoints: data.timepoints
}
});
}
};
@@ -0,0 +1,18 @@
/**
* Sets all tool data entries value for 'active' to false
* This is used to remove the active color on entire sets of tools
*
* @param element The Cornerstone element that is being used
* @param toolType The tooltype of the tools that will be deactivated
*/
deactivateAllToolData = function(element, toolType) {
var 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;
}
};
@@ -0,0 +1,13 @@
/**
* Returns timepoint object given a specified imageId
*
* @param imageId
* @returns {*|{}} Timepoint object
*/
getTimepointObject = function(imageId) {
var study = cornerstoneTools.metaData.get('study', imageId);
if (!study) {
return;
}
return Timepoints.findOne({timepointName: study.studyDate});
};
@@ -0,0 +1,28 @@
removeToolDataWithMeasurementId = function(imageId, toolType, measurementId) {
var toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
// Find any related toolData
if (!toolState[imageId] || !toolState[imageId][toolType]) {
return;
}
var toolData = toolState[imageId][toolType].data;
if (!toolData.length) {
return;
}
// Search toolData for entries linked to the specified Measurement
var toRemove = [];
toolData.forEach(function(measurement, index) {
if (measurement.id === measurementId) {
toRemove.push(index);
return false;
}
});
// If any toolData entries need to be removed, splice them from
// the toolData array
toRemove.forEach(function(index) {
toolData.splice(index, 1);
});
};
@@ -15,7 +15,7 @@ toggleLesionTrackerTools = function() {
// Hide the tools (set them all to disabled)
var toolDefaultStates = {
activate: [],
activate: ['deleteLesionKeyboardTool'],
deactivate: [],
enable: [],
disable: ['lesion', 'nonTarget', 'biDirectional']