Bug fixing: Linking on last row in lesion table is broken

This commit is contained in:
Evren Ozkan 2015-11-25 07:48:29 -05:00
parent 8a844dd2fe
commit e6f1f34d1c
2 changed files with 20 additions and 13 deletions

View File

@ -70,27 +70,28 @@ Template.viewerMain.helpers({
Template.viewerMain.events({ Template.viewerMain.events({
'click button#clearTools': function(e, template) { 'click button#clearTools': function(e, template) {
var contentId = template.data.contentId;
var patientId = template.data.studies[0].patientId; var patientId = template.data.studies[0].patientId;
var toolTypes = ["lesion", "nonTarget"]; var toolTypes = ["lesion", "nonTarget"];
var toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState; var toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
var toolStateKeys = Object.keys(toolState).slice(0); var toolStateKeys = Object.keys(toolState).slice(0);
// Set null array for toolState data found by imageId and toolType
toolStateKeys.forEach(function (imageId) { toolStateKeys.forEach(function (imageId) {
toolTypes.forEach(function (toolType) { toolTypes.forEach(function (toolType) {
if(toolState[imageId][toolType]) { var toolTypeData = toolState[imageId][toolType];
if(toolState[imageId][toolType].data[0].patientId === patientId) { if(toolTypeData && toolTypeData.data.length > 0) {
if(toolTypeData.data[0].patientId === patientId) {
toolState[imageId][toolType] = { toolState[imageId][toolType] = {
data: [] data: []
} };
} }
} }
}); });
}); });
// Update imageViewerViewport elements // Update imageViewerViewport elements
$("#"+contentId+" .imageViewerViewport").each(function(viewportIndex, element) { $(".imageViewerViewport").each(function(viewportIndex, element) {
cornerstone.updateImage(element); cornerstone.updateImage(element);
}); });

View File

@ -3,7 +3,7 @@
* *
* @param measurementId The unique key for a specific Measurement * @param measurementId The unique key for a specific Measurement
*/ */
function activateLesion(measurementId) { function activateLesion(measurementId, templateData) {
// Find Measurement data for this lesion // Find Measurement data for this lesion
var measurementData = Measurements.findOne(measurementId); var measurementData = Measurements.findOne(measurementId);
@ -71,14 +71,14 @@ function activateLesion(measurementId) {
if (currentSeriesData.seriesInstanceUid === measurementAtTimepoint.seriesInstanceUid && if (currentSeriesData.seriesInstanceUid === measurementAtTimepoint.seriesInstanceUid &&
currentSeriesData.studyInstanceUid === measurementAtTimepoint.studyInstanceUid) { currentSeriesData.studyInstanceUid === measurementAtTimepoint.studyInstanceUid) {
// If it is, activate the measurements in this viewport and stop here // If it is, activate the measurements in this viewport and stop here
activateMeasurements(element, measurementId); activateMeasurements(element, measurementId, templateData, viewportIndex);
return; return;
} }
// Otherwise, re-render the viewport with the required study/series, then // Otherwise, re-render the viewport with the required study/series, then
// add an onRendered callback to activate the measurements // add an onRendered callback to activate the measurements
rerenderViewportWithNewSeries(element, requiredSeriesData, function(element) { rerenderViewportWithNewSeries(element, requiredSeriesData, function(element) {
activateMeasurements(element, measurementId); activateMeasurements(element, measurementId, templateData, viewportIndex);
}); });
}); });
} }
@ -100,7 +100,7 @@ function getTimepointObject(imageId) {
* Activate the selected measurement on the switched image (color to be green) * Activate the selected measurement on the switched image (color to be green)
* Deactivate all other measurements on the switched image (color to be white) * Deactivate all other measurements on the switched image (color to be white)
*/ */
function activateMeasurements(element, measurementId) { function activateMeasurements(element, measurementId, templateData, viewportIndex) {
// TODO=Switch this to use the new CornerstoneToolMeasurementModified event, // TODO=Switch this to use the new CornerstoneToolMeasurementModified event,
// Once it has 'modified on activation' set up // Once it has 'modified on activation' set up
@ -116,6 +116,12 @@ function activateMeasurements(element, measurementId) {
// If type is active, load image and activate lesion // If type is active, load image and activate lesion
// If type is inactive, update lesions of enabledElement as inactive // 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 stackToolDataSource = cornerstoneTools.getToolState(element, 'stack');
var stackData = stackToolDataSource.data[0]; var stackData = stackToolDataSource.data[0];
var imageIds = stackData.imageIds; var imageIds = stackData.imageIds;
@ -125,7 +131,7 @@ function activateMeasurements(element, measurementId) {
return; return;
} }
if (imageIdIndex === stackData.currentImageIdIndex){ if (imageIdIndex === elementCurrentImageIdIndex){
activateTool(element, measurementData, timepointData.timepointID); activateTool(element, measurementData, timepointData.timepointID);
} else { } else {
cornerstone.loadAndCacheImage(imageIds[imageIdIndex]).then(function(image) { cornerstone.loadAndCacheImage(imageIds[imageIdIndex]).then(function(image) {
@ -202,9 +208,9 @@ Template.lesionTable.helpers({
}); });
Template.lesionTable.events({ Template.lesionTable.events({
'click table#tblLesion tbody tr': function(e) { 'click table#tblLesion tbody tr': function(e, template) {
// Retrieve the lesion id from the DOM data for this row // Retrieve the lesion id from the DOM data for this row
var measurementId = $(e.currentTarget).data('measurementid'); var measurementId = $(e.currentTarget).data('measurementid');
activateLesion(measurementId); activateLesion(measurementId,template.data);
} }
}); });