Fixing hanging protocols matching score issues

This commit is contained in:
Bruno Alves de Faria 2016-08-24 11:53:31 -03:00
parent 88e504a010
commit 17f8d87d32
3 changed files with 95 additions and 38 deletions

View File

@ -462,37 +462,29 @@ HP.ProtocolEngine = class ProtocolEngine {
sopInstanceUid: instance.sopInstanceUid,
currentImageIdIndex: index,
matchingScore: totalMatchScore,
matchDetails: matchDetails
matchDetails: matchDetails,
sortingInfo: {
score: totalMatchScore,
study: study.studyDate + study.studyTime,
series: series.seriesNumber, // TODO: change for seriesDateTime
instance: instance.instanceNumber // TODO: change for acquisitionTime
}
};
// Find the displaySet
const filter = {
sopInstanceUid: instance.sopInstanceUid
};
const displaySet = _.filter(study.displaySets, ds => _.findWhere(ds.images, filter))[0];
// If the instance was found, set the displaySet ID
if (displaySet) {
imageDetails.displaySetInstanceUid = displaySet.displaySetInstanceUid;
imageDetails.imageId = getImageId(instance);
}
if ((totalMatchScore > highestImageMatchingScore) || !bestMatch) {
highestImageMatchingScore = totalMatchScore;
// Set the displaySet ID
study.displaySets.every(displaySet => {
// Skip displaySet if it has no images
if (!displaySet.images.length) {
return true;
}
// Skip displaySet if series is different
if (displaySet.seriesInstanceUid !== series.seriesInstanceUid) {
return true;
}
// Try to find the current instance
const instanceFound = _.findWhere(displaySet.images, {
sopInstanceUid: instance.sopInstanceUid
});
// If the instance was found, set the displaySet ID
if (instanceFound) {
imageDetails.displaySetInstanceUid = displaySet.displaySetInstanceUid;
imageDetails.imageId = getImageId(instance);
return false;
}
});
bestMatch = imageDetails;
}
@ -501,6 +493,20 @@ HP.ProtocolEngine = class ProtocolEngine {
});
});
// Sort the matchingScores
const sortingFunction = OHIF.utils.sortBy({
name: 'score',
reverse: true
}, {
name: 'study',
reverse: true
}, {
name: 'series'
}, {
name: 'instance'
});
matchingScores.sort((a, b) => sortingFunction(a.sortingInfo, b.sortingInfo));
return {
bestMatch: bestMatch,
matchingScores: matchingScores
@ -605,21 +611,27 @@ HP.ProtocolEngine = class ProtocolEngine {
});
};
if (details.bestMatch) {
currentViewportData.studyInstanceUid = details.bestMatch.studyInstanceUid;
currentViewportData.seriesInstanceUid = details.bestMatch.seriesInstanceUid;
currentViewportData.sopInstanceUid = details.bestMatch.sopInstanceUid;
currentViewportData.currentImageIdIndex = details.bestMatch.currentImageIdIndex;
currentViewportData.displaySetInstanceUid = details.bestMatch.displaySetInstanceUid;
currentViewportData.imageId = details.bestMatch.imageId;
let currentMatch = details.bestMatch;
let currentPosition = 1;
const scoresLength = details.matchingScores.length;
while (currentPosition < scoresLength && _.findWhere(viewportData, {
imageId: currentMatch.imageId
})) {
currentMatch = details.matchingScores[currentPosition];
currentPosition++;
}
const study = ViewerStudies.findOne({
studyInstanceUid: details.bestMatch.studyInstanceUid
});
if (currentMatch.imageId) {
currentViewportData.studyInstanceUid = currentMatch.studyInstanceUid;
currentViewportData.seriesInstanceUid = currentMatch.seriesInstanceUid;
currentViewportData.sopInstanceUid = currentMatch.sopInstanceUid;
currentViewportData.currentImageIdIndex = currentMatch.currentImageIdIndex;
currentViewportData.displaySetInstanceUid = currentMatch.displaySetInstanceUid;
currentViewportData.imageId = currentMatch.imageId;
}
if (!currentViewportData.displaySetInstanceUid) {
throw "No matching display set found?";
throw 'No matching display set found?';
}
viewportData.push(currentViewportData);

View File

@ -2,4 +2,5 @@ import './blaze.js';
import './string.js';
import './ui.js';
import './user.js';
import './utils.js';
import './viewer.js';

View File

@ -0,0 +1,44 @@
import { OHIF } from 'meteor/ohif:core';
OHIF.utils = {};
// Return the array sorting function for its object's properties
OHIF.utils.sortBy = function() {
var fields = [].slice.call(arguments),
n_fields = fields.length;
return function(A, B) {
var a, b, field, key, primer, reverse, result, i;
for (i = 0; i < n_fields; i++) {
result = 0;
field = fields[i];
key = typeof field === 'string' ? field : field.name;
a = A[key];
b = B[key];
if (typeof field.primer !== 'undefined') {
a = field.primer(a);
b = field.primer(b);
}
reverse = (field.reverse) ? -1 : 1;
if (a < b) {
result = reverse * -1;
}
if (a > b) {
result = reverse * 1;
}
if (result !== 0) {
break;
}
}
return result;
};
};