Hanging protocol improvements on matching process and other improvements
This commit is contained in:
1 parent
744a0bd76e
commit
35b855de56
18 files changed
+881
-793
No files matched your search
@@ -1,77 +1,12 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { comparators } from '../both/lib/comparators';
|
||||
|
||||
MatchedProtocols = new Meteor.Collection(null);
|
||||
MatchedProtocols._debugName = 'MatchedProtocols';
|
||||
|
||||
Comparators = new Meteor.Collection(null);
|
||||
Comparators._debugName = 'Comparators';
|
||||
|
||||
var comparators = [{
|
||||
id: 'equals',
|
||||
name: '= (Equals)',
|
||||
validator: 'equals',
|
||||
validatorOption: 'value',
|
||||
description: 'The attribute must equal this value.'
|
||||
}, {
|
||||
id: 'doesNotEqual',
|
||||
name: '!= (Does not equal)',
|
||||
validator: 'doesNotEqual',
|
||||
validatorOption: 'value',
|
||||
description: 'The attribute must not equal this value.'
|
||||
}, {
|
||||
id: 'contains',
|
||||
name: 'Contains',
|
||||
validator: 'contains',
|
||||
validatorOption: 'value',
|
||||
description: 'The attribute must contain this value.'
|
||||
}, {
|
||||
id: 'doesNotContain',
|
||||
name: 'Does not contain',
|
||||
validator: 'doesNotContain',
|
||||
validatorOption: 'value',
|
||||
description: 'The attribute must not contain this value.'
|
||||
}, {
|
||||
id: 'onlyInteger',
|
||||
name: 'Only Integers',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'onlyInteger',
|
||||
description: "Real numbers won't be allowed."
|
||||
}, {
|
||||
id: 'greaterThan',
|
||||
name: '> (Greater than)',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'greaterThan',
|
||||
description: 'The attribute has to be greater than this value.'
|
||||
}, {
|
||||
id: 'greaterThanOrEqualTo',
|
||||
name: '>= (Greater than or equal to)',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'greaterThanOrEqualTo',
|
||||
description: 'The attribute has to be at least this value.'
|
||||
}, {
|
||||
id: 'lessThanOrEqualTo',
|
||||
name: '<= (Less than or equal to)',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'lessThanOrEqualTo',
|
||||
description: 'The attribute can be this value at the most.'
|
||||
}, {
|
||||
id: 'lessThan',
|
||||
name: '< (Less than)',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'lessThan',
|
||||
description: 'The attribute has to be less than this value.'
|
||||
}, {
|
||||
id: 'odd',
|
||||
name: 'Odd',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'odd',
|
||||
description: 'The attribute has to be odd.'
|
||||
}, {
|
||||
id: 'even',
|
||||
name: 'Even',
|
||||
validator: 'numericality',
|
||||
validatorOption: 'even',
|
||||
description: 'The attribute has to be even.'
|
||||
}];
|
||||
|
||||
comparators.forEach(function(item) {
|
||||
comparators.forEach(item => {
|
||||
Comparators.insert(item);
|
||||
});
|
||||
@@ -71,7 +71,7 @@ const match = (metadataInstance, rules) => {
|
||||
// If no errorMessages were returned, then validation passed.
|
||||
|
||||
// Add the rule's weight to the total score
|
||||
score += rule.weight;
|
||||
score += parseInt(rule.weight, 10);
|
||||
|
||||
// Log that this rule passed in the matching details object
|
||||
details.passed.push({
|
||||
|
||||
@@ -108,44 +108,6 @@ HP.ProtocolEngine = class ProtocolEngine {
|
||||
return this.protocol.stages[this.stage];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of priors rules for a given protocol. This rules are for raising up the score when
|
||||
* matching a protocol against study's number of priors. Protocols with same study/series/instance
|
||||
* rules that references the exactly number of priors that a study will have highest score.
|
||||
* @param {Integer} numberOfPriorsReferenced Number of priors required by the protocol
|
||||
* @return {Array} Returs an array of HP.ProtocolMatchingRule objects
|
||||
*/
|
||||
getNumberOfPriorsRules(numberOfPriorsReferenced) {
|
||||
const rules = [];
|
||||
|
||||
// If study at least the number of priors required by the protocol
|
||||
const requiredPriorsRule = new HP.ProtocolMatchingRule('numberOfPriorsReferenced', {
|
||||
numericality: {
|
||||
greaterThanOrEqualTo: numberOfPriorsReferenced
|
||||
}
|
||||
});
|
||||
|
||||
// If study has the same number of priors
|
||||
const equalPriorsRule = new HP.ProtocolMatchingRule('numberOfPriorsReferenced', {
|
||||
numericality: {
|
||||
equalTo: numberOfPriorsReferenced
|
||||
}
|
||||
});
|
||||
|
||||
rules.push(requiredPriorsRule, equalPriorsRule);
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given protocol requires a minimum number of priors.
|
||||
* @param {HP.Protocol} protocol HP.Protocol object that contains rules
|
||||
* @return {Boolean} Returns true if the protocol requires priors or false otherwise
|
||||
*/
|
||||
protocolRequiresPriors(protocol) {
|
||||
return protocol.numberOfPriorsReferencedRequired > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the best protocols from Protocol Store, matching each protocol matching rules
|
||||
* with the given study. The best protocol are orded by score and returned in an array
|
||||
@@ -161,45 +123,23 @@ HP.ProtocolEngine = class ProtocolEngine {
|
||||
const studyInstance = study.getFirstInstance();
|
||||
|
||||
// Set custom attribute for study metadata
|
||||
const numberOfPriorsReferenced = this.getNumberOfAvailablePriors(study.getObjectID());
|
||||
studyInstance.setCustomAttribute('numberOfPriorsReferenced', numberOfPriorsReferenced);
|
||||
const numberOfAvailablePriors = this.getNumberOfAvailablePriors(study.getObjectID());
|
||||
|
||||
HP.ProtocolStore.getProtocol().forEach(protocol => {
|
||||
// Clone the protocol's protocolMatchingRules array
|
||||
// We clone it so that we don't accidentally add the
|
||||
// numberOfPriorsReferenced rule to the Protocol itself.
|
||||
let rules = protocol.protocolMatchingRules.slice(0);
|
||||
let rules = protocol.protocolMatchingRules.slice();
|
||||
if (!rules) {
|
||||
return;
|
||||
}
|
||||
|
||||
// To make sure the protocol has updated priors information.
|
||||
// This is reasonable for Viewers that use different APIs to
|
||||
// manage ProtocolStore or protocols.
|
||||
if (!protocol.hasUpdatedPriorsInformation) {
|
||||
|
||||
// If protocol is not an instance of HP.Protocol
|
||||
// make it be.
|
||||
if (!(protocol instanceof HP.Protocol)) {
|
||||
const protocolObject = new HP.Protocol();
|
||||
protocolObject.fromObject(protocol);
|
||||
protocol = protocolObject;
|
||||
}
|
||||
|
||||
protocol.updateNumberOfPriorsReferenced();
|
||||
}
|
||||
|
||||
// Skip protocols that require more priors than the study has
|
||||
const protocolRequiresPriors = this.protocolRequiresPriors(protocol);
|
||||
if (protocolRequiresPriors && numberOfPriorsReferenced < protocol.numberOfPriorsReferenced) {
|
||||
// Check if the study has the minimun number of priors used by the protocol.
|
||||
const numberOfPriorsReferenced = protocol.getNumberOfPriorsReferenced();
|
||||
if (numberOfPriorsReferenced > numberOfAvailablePriors) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get additional rules for number of priors referenced
|
||||
const priorsRules = this.getNumberOfPriorsRules(protocol.numberOfPriorsReferenced);
|
||||
// Concatenate rules
|
||||
rules = rules.concat(priorsRules);
|
||||
|
||||
// Run the matcher and get matching details
|
||||
const matchedDetails = HPMatcher.match(studyInstance, rules);
|
||||
const score = matchedDetails.score;
|
||||
@@ -312,29 +252,6 @@ HP.ProtocolEngine = class ProtocolEngine {
|
||||
return priors instanceof Array ? priors : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of prior studies based on current protocol matching rules.
|
||||
*
|
||||
* @param {String} studyObjectID The study object ID of the study whose priors are needed
|
||||
* @returns {Array} The array of available priors that match the given rules or an empty array
|
||||
*/
|
||||
getPriorsByProtocolMatchingRules(studyObjectID) {
|
||||
const allPriors = this.getAvailableStudyPriors(studyObjectID);
|
||||
const protocolMatchingRules = this.protocol.protocolMatchingRules;
|
||||
|
||||
if (protocolMatchingRules instanceof Array && protocolMatchingRules.length > 0) {
|
||||
return allPriors.filter(prior => {
|
||||
if (prior instanceof StudyMetadata) {
|
||||
prior = prior.getFirstInstance();
|
||||
}
|
||||
const matchDetails = HPMatcher.match(prior, protocolMatchingRules);
|
||||
return matchDetails.score > 0;
|
||||
});
|
||||
}
|
||||
|
||||
return allPriors;
|
||||
}
|
||||
|
||||
// Match images given a list of Studies and a Viewport's image matching reqs
|
||||
matchImages(viewport, viewportIndex) {
|
||||
OHIF.log.info('ProtocolEngine::matchImages');
|
||||
@@ -342,7 +259,7 @@ HP.ProtocolEngine = class ProtocolEngine {
|
||||
const { studyMatchingRules, seriesMatchingRules, imageMatchingRules: instanceMatchingRules } = viewport;
|
||||
|
||||
const matchingScores = [];
|
||||
const currentStudy = this.studies[0];
|
||||
const currentStudy = this.studies[0]; // @TODO: Should this be: this.studies[this.currentStudy] ???
|
||||
const firstInstance = currentStudy.getFirstInstance();
|
||||
|
||||
let highestStudyMatchingScore = 0;
|
||||
@@ -356,6 +273,9 @@ HP.ProtocolEngine = class ProtocolEngine {
|
||||
firstInstance.setCustomAttribute(ABSTRACT_PRIOR_VALUE, 0);
|
||||
}
|
||||
|
||||
// Only used if study matching rules has abstract prior values defined...
|
||||
let priorStudies;
|
||||
|
||||
studyMatchingRules.forEach(rule => {
|
||||
if (rule.attribute === ABSTRACT_PRIOR_VALUE) {
|
||||
const validatorType = Object.keys(rule.constraint)[0];
|
||||
@@ -365,17 +285,20 @@ HP.ProtocolEngine = class ProtocolEngine {
|
||||
abstractPriorValue = parseInt(abstractPriorValue, 10);
|
||||
// TODO: Restrict or clarify validators for abstractPriorValue?
|
||||
|
||||
const studies = this.getPriorsByProtocolMatchingRules(currentStudy.getObjectID());
|
||||
// No need to call it more than once...
|
||||
if (!priorStudies) {
|
||||
priorStudies = this.getAvailableStudyPriors(currentStudy.getObjectID());
|
||||
}
|
||||
|
||||
// TODO: Revisit this later: What about two studies with the same
|
||||
// study date?
|
||||
|
||||
let priorStudy;
|
||||
if (abstractPriorValue === -1) {
|
||||
priorStudy = studies[studies.length - 1];
|
||||
priorStudy = priorStudies[priorStudies.length - 1];
|
||||
} else {
|
||||
const studyIndex = Math.max(abstractPriorValue - 1, 0);
|
||||
priorStudy = studies[studyIndex];
|
||||
priorStudy = priorStudies[studyIndex];
|
||||
}
|
||||
|
||||
// Invalid data
|
||||
|
||||
@@ -60,7 +60,7 @@ var defaultStrategy = (function () {
|
||||
}
|
||||
|
||||
// Otherwise, return all protocols
|
||||
return HangingProtocols.find();
|
||||
return HangingProtocols.find().fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,18 @@ HP.ProtocolStore = (function () {
|
||||
strategy.onReady(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a HP.Protocol instance for the given protocol object
|
||||
* @param {Object} protocolObject Protocol plain object
|
||||
* @return {HP.Protocol} HP.Protocol instance for the given protocol object
|
||||
*/
|
||||
function getProtocolInstance(protocolObject) {
|
||||
const protocolInstance = new HP.Protocol();
|
||||
protocolInstance.fromObject(protocolObject);
|
||||
|
||||
return protocolInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hanging protocol by protocolId if defined, otherwise all stored hanging protocols
|
||||
*
|
||||
@@ -35,7 +47,23 @@ HP.ProtocolStore = (function () {
|
||||
* @returns {object|array} The hanging protocol by protocolId or array of the stored hanging protocols
|
||||
*/
|
||||
function getProtocol(protocolId) {
|
||||
return strategy.getProtocol(protocolId);
|
||||
let result = strategy.getProtocol(protocolId);
|
||||
|
||||
// If result is an array of protocols objects
|
||||
if (result instanceof Array) {
|
||||
result.forEach( (protocol, index) => {
|
||||
// Check if protocol is an instance of HP.Protocol
|
||||
if (!(protocol instanceof HP.Protocol)) {
|
||||
result[index] = getProtocolInstance(protocol);
|
||||
}
|
||||
});
|
||||
} else if (result !== void 0 && !(result instanceof HP.Protocol)) {
|
||||
// Check if result exists and is not an instance of HP.Protocol
|
||||
result = getProtocolInstance(result);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user