LT-92: Adding schema validation for JSON criteria
This commit is contained in:
parent
ed2f0ee36b
commit
697b4e7ff8
@ -8,14 +8,20 @@ export class CriteriaEvaluator {
|
||||
|
||||
_.each(criteriaObject, (optionsObject, criterionkey) => {
|
||||
const Criterion = Criteria[`${criterionkey}Criterion`];
|
||||
if (optionsObject instanceof Array) {
|
||||
_.each(optionsObject, options => {
|
||||
const criterion = new Criterion(options);
|
||||
this.criteria.push(criterion);
|
||||
});
|
||||
} else {
|
||||
this.criteria.push(new Criterion(optionsObject));
|
||||
}
|
||||
const optionsArray = optionsObject instanceof Array ? optionsObject : [optionsObject];
|
||||
_.each(optionsArray, options => {
|
||||
const validator = Criteria[`${criterionkey}Validator`];
|
||||
if (!validator(options)) {
|
||||
let message = `Invalid ${criterionkey}Criterion definition.`;
|
||||
_.each(validator.errors, error => {
|
||||
message += `\noptions${error.dataPath} ${error.message}`;
|
||||
});
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
const criterion = new Criterion(options);
|
||||
this.criteria.push(criterion);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
export const MaxTargetsSchema = {
|
||||
export const MaxTargetsValidator = new Ajv().compile({
|
||||
properties: {
|
||||
limit: {
|
||||
label: 'Max targets allowed in study',
|
||||
@ -10,7 +11,7 @@ export const MaxTargetsSchema = {
|
||||
}
|
||||
},
|
||||
required: ['limit']
|
||||
};
|
||||
});
|
||||
|
||||
/* MaxTargetsCriterion
|
||||
* Check if the number of target measurements exceeded the limit allowed
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
export const MaxTargetsPerOrganSchema = {
|
||||
export const MaxTargetsPerOrganValidator = new Ajv().compile({
|
||||
properties: {
|
||||
limit: {
|
||||
label: 'Max targets allowed per organ',
|
||||
@ -9,7 +10,7 @@ export const MaxTargetsPerOrganSchema = {
|
||||
}
|
||||
},
|
||||
required: ['limit']
|
||||
};
|
||||
});
|
||||
|
||||
/*
|
||||
* MaxTargetsPerOrganCriterion
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
export const MeasurementsLengthSchema = {
|
||||
export const MeasurementsLengthValidator = new Ajv().compile({
|
||||
properties: {
|
||||
longAxis: {
|
||||
label: 'Minimum length of long axis',
|
||||
@ -63,17 +64,17 @@ export const MeasurementsLengthSchema = {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
oneOf: [
|
||||
anyOf: [
|
||||
{ required: ['message', 'longAxis'] },
|
||||
{ required: ['message', 'shortAxis'] },
|
||||
{ required: ['message', 'longAxisSliceThicknessMultiplier'] },
|
||||
{ required: ['message', 'shortAxisSliceThicknessMultiplier'] }
|
||||
]
|
||||
};
|
||||
});
|
||||
|
||||
/*
|
||||
* MeasurementsLengthCriterion
|
||||
* Check the measurements of all bidirectional tools based on
|
||||
* Check the measurements of all bidirectional tools based on
|
||||
* short axis, long axis, modalities, location and slice thickness
|
||||
* Options:
|
||||
* longAxis: Minimum length of long axis
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
export const ModalitySchema = {
|
||||
export const ModalityValidator = new Ajv().compile({
|
||||
properties: {
|
||||
method: {
|
||||
label: 'Specify if it\'s goinig to "allow" or "restrict" the modalities',
|
||||
type: 'string'
|
||||
label: 'Specify if it\'s goinig to "allow" or "deny" the modalities',
|
||||
type: 'string',
|
||||
enum: ['allow', 'deny']
|
||||
},
|
||||
measurementTypes: {
|
||||
label: 'List of measurement types that will be evaluated',
|
||||
@ -17,7 +19,7 @@ export const ModalitySchema = {
|
||||
uniqueItems: true
|
||||
},
|
||||
modalities: {
|
||||
label: 'List of allowed/restricted modalities',
|
||||
label: 'List of allowed/denied modalities',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
@ -27,15 +29,15 @@ export const ModalitySchema = {
|
||||
}
|
||||
},
|
||||
required: ['method', 'modalities']
|
||||
};
|
||||
});
|
||||
|
||||
/*
|
||||
* ModalityCriteria
|
||||
* Check if a modality is allowed or restricted
|
||||
* Check if a modality is allowed or denied
|
||||
* Options:
|
||||
* method (string): Specify if it\'s goinig to "allow" or "restrict" the modalities
|
||||
* method (string): Specify if it\'s goinig to "allow" or "deny" the modalities
|
||||
* measurementTypes (string[]): List of measurement types that will be evaluated
|
||||
* modalities (string[]): List of allowed/restricted modalities
|
||||
* modalities (string[]): List of allowed/denied modalities
|
||||
*/
|
||||
export class ModalityCriterion extends BaseCriterion {
|
||||
|
||||
@ -60,7 +62,7 @@ export class ModalityCriterion extends BaseCriterion {
|
||||
const modality = metadata.modality.toUpperCase();
|
||||
|
||||
if (((validationMethod === 'allow') && !modalitiesSet.has(modality)) ||
|
||||
((validationMethod === 'restrict') && modalitiesSet.has(modality))) {
|
||||
((validationMethod === 'deny') && modalitiesSet.has(modality))) {
|
||||
measurements.push(measurement);
|
||||
invalidModalities.push(modality);
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
export const NonTargetResponseSchema = {
|
||||
};
|
||||
export const NonTargetResponseValidator = new Ajv().compile({
|
||||
});
|
||||
|
||||
/* NonTargetResponseCriterion
|
||||
* Check if the there are non-target measurements with response different than "present" on baseline
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
export const TargetTypeSchema = {
|
||||
};
|
||||
export const TargetTypeValidator = new Ajv().compile({
|
||||
});
|
||||
|
||||
/* TargetTypeCriterion
|
||||
* Check if the there are non-bidirectional target measurements on baseline
|
||||
|
||||
Loading…
Reference in New Issue
Block a user