chore: Tag everything currently unused as legacy.
This commit is contained in:
1 parent
8392c1f97e
commit
414ebc6850
161 files changed
+128
-14712
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,579 +0,0 @@
|
||||
import log from '../../log';
|
||||
import { timepointApiDefaultConfig } from './../configuration.js';
|
||||
|
||||
const configuration = {
|
||||
...timepointApiDefaultConfig,
|
||||
};
|
||||
|
||||
const TIMEPOINT_TYPE_NAMES = {
|
||||
prebaseline: 'Pre-Baseline',
|
||||
baseline: 'Baseline',
|
||||
followup: 'Follow-up',
|
||||
};
|
||||
|
||||
export default class TimepointApi {
|
||||
static Instance;
|
||||
|
||||
static setConfiguration(config) {
|
||||
Object.assign(configuration, config);
|
||||
}
|
||||
|
||||
static getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
constructor(currentTimepointId, options = {}) {
|
||||
if (TimepointApi.Instance) {
|
||||
TimepointApi.Instance.initialize(currentTimepointId, options);
|
||||
return TimepointApi.Instance;
|
||||
}
|
||||
|
||||
this.initialize(currentTimepointId, options);
|
||||
TimepointApi.Instance = this;
|
||||
}
|
||||
|
||||
initialize(currentTimepointId, options = {}) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
this.comparisonTimepointKey = options.comparisonTimepointKey || 'baseline';
|
||||
this.options = options;
|
||||
this.timepoints = [];
|
||||
}
|
||||
|
||||
onTimepointsUpdated() {
|
||||
if (typeof this.options.onTimepointsUpdated !== 'function') {
|
||||
log.warn('Timepoints update callback is not defined');
|
||||
return;
|
||||
}
|
||||
|
||||
this.options.onTimepointsUpdated(Object.assign([], this.timepoints));
|
||||
}
|
||||
|
||||
calculateVisitNumber(timepoint) {
|
||||
// Retrieve all of the relevant follow-up timepoints for this patient
|
||||
const sortedTimepoints = this.timepoints.sort((tp1, tp2) => {
|
||||
return tp1.visitDate > tp2.visitDate ? 1 : -1;
|
||||
});
|
||||
const filteredTimepoints = sortedTimepoints.find(
|
||||
tp =>
|
||||
tp.PatientID === timepoint.PatientID &&
|
||||
tp.timepointType === timepoint.timepointType
|
||||
);
|
||||
|
||||
// Create an array of just timepointIds, so we can use indexOf
|
||||
// on it to find the current timepoint's relative position
|
||||
const timepointIds = filteredTimepoints.map(
|
||||
timepoint => timepoint.timepointId
|
||||
);
|
||||
|
||||
// Calculate the index of the current timepoint in the array of all
|
||||
// relevant follow-up timepoints
|
||||
const visitNumber = timepointIds.indexOf(timepoint.timepointId) + 1;
|
||||
|
||||
// If visitNumber is 0, it means that the current timepoint was not in the list
|
||||
if (!visitNumber) {
|
||||
throw new Error(
|
||||
'Current timepoint was not in the list of relevant timepoints?'
|
||||
);
|
||||
}
|
||||
|
||||
return visitNumber;
|
||||
}
|
||||
|
||||
retrieveTimepoints(filter) {
|
||||
const retrievalFn = configuration.dataExchange.retrieve;
|
||||
if (typeof retrievalFn !== 'function') {
|
||||
log.error('Timepoint retrieval function has not been configured.');
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
retrievalFn(filter)
|
||||
.then(timepointData => {
|
||||
log.info('Timepoint data retrieval');
|
||||
|
||||
timepointData.forEach(timepoint => {
|
||||
const timepointIndex = this.timepoints.findIndex(
|
||||
tp => tp.timepointId === timepoint.timepointId
|
||||
);
|
||||
if (timepointIndex < 0) {
|
||||
this.timepoints.push(timepoint);
|
||||
} else {
|
||||
this.timepoints[timepointIndex] = timepoint;
|
||||
}
|
||||
});
|
||||
|
||||
// Let others know that the timepoints are updated
|
||||
this.onTimepointsUpdated();
|
||||
|
||||
resolve();
|
||||
})
|
||||
.catch(reason => {
|
||||
log.error(`Timepoint retrieval function failed: ${reason}`);
|
||||
reject(reason);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
storeTimepoints() {
|
||||
const storeFn = configuration.dataExchange.store;
|
||||
if (typeof storeFn !== 'function') {
|
||||
log.error('Timepoint store function has not been configured.');
|
||||
return;
|
||||
}
|
||||
|
||||
log.info('Preparing to store timepoints');
|
||||
log.info(JSON.stringify(this.timepoints, null, 2));
|
||||
|
||||
storeFn(this.timepoints).then(() =>
|
||||
log.info('Timepoint storage completed')
|
||||
);
|
||||
}
|
||||
|
||||
disassociateStudy(timepointIds, StudyInstanceUID) {
|
||||
const disassociateFn = configuration.dataExchange.disassociate;
|
||||
if (typeof disassociateFn !== 'function') {
|
||||
log.error('Study disassociate function has not been configured.');
|
||||
return;
|
||||
}
|
||||
|
||||
disassociateFn(timepointIds, StudyInstanceUID).then(() => {
|
||||
log.info('Disassociation completed');
|
||||
|
||||
this.timepoints = [];
|
||||
this.retrieveTimepoints({});
|
||||
});
|
||||
}
|
||||
|
||||
removeTimepoint(timepointId) {
|
||||
const removeFn = configuration.dataExchange.remove;
|
||||
if (typeof removeFn !== 'function') {
|
||||
log.error('Timepoint remove function has not been configured.');
|
||||
return;
|
||||
}
|
||||
|
||||
const timepointData = {
|
||||
timepointId,
|
||||
};
|
||||
|
||||
log.info('Preparing to remove timepoint');
|
||||
log.info(JSON.stringify(timepointData, null, 2));
|
||||
|
||||
removeFn(timepointData).then(() => {
|
||||
log.info('Timepoint removal completed');
|
||||
|
||||
const tpIndex = this.timepoints.findIndex(
|
||||
tp => tp.timepointId === timepointId
|
||||
);
|
||||
if (tpIndex > -1) {
|
||||
this.timepoints.splice(tpIndex, 1);
|
||||
}
|
||||
|
||||
// Let others know that the timepoints are updated
|
||||
this.onTimepointsUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
updateTimepoint(timepointId, query) {
|
||||
const updateFn = configuration.dataExchange.update;
|
||||
if (typeof updateFn !== 'function') {
|
||||
log.error('Timepoint update function has not been configured.');
|
||||
return;
|
||||
}
|
||||
|
||||
const timepointData = {
|
||||
timepointId,
|
||||
};
|
||||
|
||||
log.info('Preparing to update timepoint');
|
||||
log.info(JSON.stringify(timepointData, null, 2));
|
||||
log.info(JSON.stringify(query, null, 2));
|
||||
|
||||
updateFn(timepointData, query).then(() => {
|
||||
log.info('Timepoint updated completed');
|
||||
|
||||
const tpIndex = this.timepoints.findIndex(
|
||||
tp => tp.timepointId === timepointId
|
||||
);
|
||||
if (tpIndex > -1) {
|
||||
this.timepoints[tpIndex] = Object.assign(
|
||||
{},
|
||||
this.timepoints[tpIndex],
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
// Let others know that the timepoints are updated
|
||||
this.onTimepointsUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
// Return all timepoints
|
||||
all(filter) {
|
||||
let timepointsToReturn;
|
||||
if (filter) {
|
||||
timepointsToReturn = this.timepoints.filter(filter);
|
||||
} else {
|
||||
timepointsToReturn = this.timepoints;
|
||||
}
|
||||
|
||||
return timepointsToReturn.sort((tp1, tp2) => {
|
||||
return tp1.visitDate < tp2.visitDate ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
// Return only the current timepoint
|
||||
current() {
|
||||
return this.timepoints.find(
|
||||
tp => tp.timepointId === this.currentTimepointId
|
||||
);
|
||||
}
|
||||
|
||||
lock() {
|
||||
const tpIndex = this.timepoints.findIndex(
|
||||
tp => tp.timepointId === this.currentTimepointId
|
||||
);
|
||||
if (tpIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.timepoints[tpIndex] = Object.assign({}, this.timepoints[tpIndex], {
|
||||
locked: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Return the prior timepoint
|
||||
prior() {
|
||||
const current = this.current();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.all().find(tp => tp.visitDate < current.visitDate);
|
||||
}
|
||||
|
||||
// Return only the current and prior timepoints
|
||||
currentAndPrior() {
|
||||
const timepoints = [];
|
||||
|
||||
const current = this.current();
|
||||
if (current) {
|
||||
timepoints.push(current);
|
||||
}
|
||||
|
||||
const prior = this.prior();
|
||||
if (current && prior && prior.timepointId !== current.timepointId) {
|
||||
timepoints.push(prior);
|
||||
}
|
||||
|
||||
return timepoints;
|
||||
}
|
||||
|
||||
// Return the current and the comparison timepoints
|
||||
currentAndComparison(comparisonTimepointKey = this.comparisonTimepointKey) {
|
||||
const current = this.current();
|
||||
const comparisonTimepoint = this.comparison(comparisonTimepointKey);
|
||||
const timepoints = [current];
|
||||
|
||||
if (
|
||||
comparisonTimepoint &&
|
||||
!timepoints.find(tp => tp.timepointId === comparisonTimepoint.timepointId)
|
||||
) {
|
||||
timepoints.push(comparisonTimepoint);
|
||||
}
|
||||
|
||||
return timepoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there are 2 or more baseline timepoints before and at the current timepoint, otherwise false
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isRebaseline(timepointId) {
|
||||
const current = timepointId
|
||||
? this.timepoints.find(tp => tp.timepointId === timepointId)
|
||||
: this.current();
|
||||
if (!current) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const baselines = this.timepoints.filter(
|
||||
tp => tp.timepointType === 'baseline' && tp.visitDate <= current.visitDate
|
||||
);
|
||||
return baselines.length > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next (closest future) baseline after current timepoint
|
||||
* @returns {*}
|
||||
*/
|
||||
nextBaselineAfterCurrent() {
|
||||
let current = this.current();
|
||||
|
||||
// Get all next timepoints newer than the current timepoint sorted by visitDate ascending
|
||||
const sortedTimepoints = this.timepoints.sort((tp1, tp2) => {
|
||||
return tp1.visitDate > tp2.visitDate ? 1 : -1;
|
||||
});
|
||||
return sortedTimepoints.find(
|
||||
tp => tp.visitDate > current.visitDate && tp.timepointType === 'baseline'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current timepoint id
|
||||
* @param timepointId
|
||||
*/
|
||||
setCurrentTimepointId(timepointId) {
|
||||
this.currentTimepointId = timepointId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comparison timepoint that overrides the default comparison timepoint (called based on user selection in a viewport)
|
||||
* @param timepoint
|
||||
*/
|
||||
setUserComparison(timepoint) {
|
||||
this.userComparison = timepoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only the comparison timepoint
|
||||
* @param {String} [comparisonTimepointKey]
|
||||
* @return {*}
|
||||
*/
|
||||
comparison(comparisonTimepointKey = this.comparisonTimepointKey) {
|
||||
// Return the comparison timepoint set by user if exists
|
||||
if (this.userComparison) {
|
||||
return this.userComparison;
|
||||
}
|
||||
|
||||
const current = this.current();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If current timepoint is prebaseline, the first (closest future) BL after current is comparison regardless of default comparison timepoint
|
||||
if (current.timepointType === 'prebaseline') {
|
||||
const nextBaselineAfterCurrent = this.nextBaselineAfterCurrent();
|
||||
// If there is a next baseline, make it comparison, otherwise comparison is done by default comparison timepoint
|
||||
if (nextBaselineAfterCurrent) {
|
||||
return nextBaselineAfterCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
// If current timepoint is baseline, the prior is comparison if exists regardless of default comparison timepoint
|
||||
if (current.timepointType === 'baseline') {
|
||||
const prior = this.prior();
|
||||
if (prior) {
|
||||
return prior;
|
||||
}
|
||||
}
|
||||
|
||||
const comparison = this[comparisonTimepointKey]();
|
||||
|
||||
// Do not return a comparison if it would be identical to
|
||||
// the current.
|
||||
if (comparison && comparison.timepointId === current.timepointId) {
|
||||
return;
|
||||
}
|
||||
|
||||
return comparison;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the latest initial (prebaseline or baseline) timepoint after current and before the next followup timepoint
|
||||
* @returns {*}
|
||||
*/
|
||||
latestInitialTimepointAfterCurrent() {
|
||||
let currentTimepoint = this.current();
|
||||
|
||||
// Skip if the current timepoint is FU since there is no initial timepoint after follow-up
|
||||
if (currentTimepoint.timepointType === 'followup') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all next timepoints newer than the current timepoint sorted by visitDate ascending
|
||||
const sortedTimepoints = this.timepoints.sort((tp1, tp2) => {
|
||||
return tp1.visitDate > tp2.visitDate ? 1 : -1;
|
||||
});
|
||||
const allNextTimepoints = sortedTimepoints.filter(
|
||||
tp => tp.visitDate > currentTimepoint.visitDate
|
||||
);
|
||||
|
||||
const nextFollowupIndex = allNextTimepoints.findIndex(
|
||||
tp => tp.timepointType === 'followup'
|
||||
);
|
||||
const latestInitialBeforeNextFUIndex = nextFollowupIndex - 1;
|
||||
|
||||
if (latestInitialBeforeNextFUIndex < 0) {
|
||||
// There is no FU and all next timepoints are initial, so return the last one
|
||||
return allNextTimepoints[allNextTimepoints.length - 1];
|
||||
}
|
||||
|
||||
// Return the latest initial timepoint before the next FU
|
||||
return allNextTimepoints[latestInitialBeforeNextFUIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return timepoint ids of initial timepoints which are prebaseline and baseline
|
||||
* @returns {*}
|
||||
*/
|
||||
initialTimepointIds() {
|
||||
let timepointToCheck = this.current();
|
||||
|
||||
// If the current timepoint is PBL or BL, then get the recent PBL/BL of the current timepoint by its first FU
|
||||
// If it does not exist, then there is no newer initial timepoint, so the current timepoint is used to determine initial timepoint ids
|
||||
if (
|
||||
timepointToCheck.timepointType === 'prebaseline' ||
|
||||
timepointToCheck.timepointType === 'baseline'
|
||||
) {
|
||||
timepointToCheck =
|
||||
this.latestInitialTimepointAfterCurrent() || timepointToCheck;
|
||||
}
|
||||
|
||||
const visitDateToCheck = timepointToCheck.visitDate;
|
||||
|
||||
const preBaselineTimepoints =
|
||||
this.timepoints.filter(
|
||||
tp =>
|
||||
tp.timepointType === 'prebaseline' && tp.visitDate <= visitDateToCheck
|
||||
) || [];
|
||||
const preBaselineTimepointIds = preBaselineTimepoints.map(
|
||||
timepoint => timepoint.timepointId
|
||||
);
|
||||
|
||||
const baselineTimepoints =
|
||||
this.timepoints.filter(
|
||||
tp =>
|
||||
tp.timepointType === 'baseline' && tp.visitDate <= visitDateToCheck
|
||||
) || [];
|
||||
const baselineTimepointIds = baselineTimepoints.map(
|
||||
timepoint => timepoint.timepointId
|
||||
);
|
||||
|
||||
return preBaselineTimepointIds.concat(baselineTimepointIds);
|
||||
}
|
||||
|
||||
// Return only the baseline timepoint
|
||||
baseline() {
|
||||
const currentVisitDate = this.current().visitDate;
|
||||
return this.all().find(
|
||||
tp => tp.timepointType === 'baseline' && tp.visitDate <= currentVisitDate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only the nadir timepoint. Must be prior to the current timepoint
|
||||
* @return {any}
|
||||
*/
|
||||
nadir() {
|
||||
const current = this.current();
|
||||
const nadir = this.all().find(
|
||||
tp =>
|
||||
tp.timepointId !== current.timepointId &&
|
||||
tp.timepointKey === 'nadir' &&
|
||||
tp.visitDate <= current.visitDate
|
||||
);
|
||||
|
||||
// If we have found a nadir, return that
|
||||
if (nadir) {
|
||||
return nadir;
|
||||
}
|
||||
|
||||
// Otherwise, return the most recent baseline
|
||||
// This should only happen if we are only at FU1,
|
||||
// so the baseline is the nadir.
|
||||
return this.baseline();
|
||||
}
|
||||
|
||||
// Return only the key timepoints (current, prior, nadir and baseline)
|
||||
key() {
|
||||
const result = [this.current()];
|
||||
const prior = this.prior();
|
||||
const nadir = this.nadir();
|
||||
const baseline = this.baseline();
|
||||
|
||||
const resultIncludes = timepoint =>
|
||||
!!result.find(x => x.timepointId === timepoint.timepointId);
|
||||
|
||||
if (prior && resultIncludes(prior) === false) {
|
||||
result.push(prior);
|
||||
}
|
||||
|
||||
if (nadir && resultIncludes(nadir) === false) {
|
||||
result.push(nadir);
|
||||
}
|
||||
|
||||
if (baseline && resultIncludes(baseline) === false) {
|
||||
result.push(baseline);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Return only the timepoints for the given study
|
||||
study(StudyInstanceUID) {
|
||||
return this.all().filter(timepoint =>
|
||||
timepoint.studyInstanceUIDs.includes(StudyInstanceUID)
|
||||
);
|
||||
}
|
||||
|
||||
// Return the timepoint's name
|
||||
name(timepoint) {
|
||||
const timepointTypeName = TIMEPOINT_TYPE_NAMES[timepoint.timepointType];
|
||||
|
||||
// Check if this is a Baseline timepoint, if it is, return 'Baseline'
|
||||
if (timepoint.timepointType === 'baseline') {
|
||||
return 'Baseline';
|
||||
} else if (timepoint.visitNumber) {
|
||||
return `${timepointTypeName} ${timepoint.visitNumber}`;
|
||||
}
|
||||
|
||||
const visitNumber = this.calculateVisitNumber(timepoint);
|
||||
|
||||
// Return the timepoint name as 'Follow-up N'
|
||||
return `${timepointTypeName} ${visitNumber}`;
|
||||
}
|
||||
|
||||
// Build the timepoint title based on its date
|
||||
title(timepoint) {
|
||||
const timepointName = this.name(timepoint);
|
||||
|
||||
const all = this.all();
|
||||
let index = -1;
|
||||
let currentIndex = null;
|
||||
for (let i = 0; i < all.length; i++) {
|
||||
const currentTimepoint = all[i];
|
||||
|
||||
// Skip the iterations until we can't find the selected timepoint on study list
|
||||
if (this.currentTimepointId === currentTimepoint.timepointId) {
|
||||
currentIndex = 0;
|
||||
}
|
||||
|
||||
if (currentIndex !== null) {
|
||||
index = currentIndex++;
|
||||
}
|
||||
|
||||
// Break the loop if reached the timepoint to get the title
|
||||
if (currentTimepoint.timepointId === timepoint.timepointId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const states = {
|
||||
0: ['Current'],
|
||||
1: ['Prior'],
|
||||
};
|
||||
const parenthesis = states[index] || [];
|
||||
const nadir = this.nadir();
|
||||
|
||||
if (nadir && nadir.timepointId === timepoint.timepointId) {
|
||||
parenthesis.push('Nadir');
|
||||
}
|
||||
|
||||
let parenthesisText = '';
|
||||
if (parenthesis.length) {
|
||||
parenthesisText = `(${parenthesis.join(', ')})`;
|
||||
}
|
||||
|
||||
return `${timepointName} ${parenthesisText}`;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
import MeasurementApi from './MeasurementApi';
|
||||
import TimepointApi from './TimepointApi';
|
||||
|
||||
export { TimepointApi, MeasurementApi };
|
||||
@@ -1,42 +0,0 @@
|
||||
import { allTools } from './toolGroups/allTools';
|
||||
import {
|
||||
retrieveMeasurements,
|
||||
storeMeasurements,
|
||||
retrieveTimepoints,
|
||||
storeTimepoints,
|
||||
removeTimepoint,
|
||||
updateTimepoint,
|
||||
disassociateStudy,
|
||||
} from './dataExchange';
|
||||
|
||||
const measurementApiDefaultConfig = {
|
||||
measurementTools: [allTools],
|
||||
newLesions: [
|
||||
{
|
||||
id: 'newTargets',
|
||||
name: 'New Targets',
|
||||
toolGroupId: 'targets',
|
||||
},
|
||||
{
|
||||
id: 'newNonTargets',
|
||||
name: 'New Non-Targets',
|
||||
toolGroupId: 'nonTargets',
|
||||
},
|
||||
],
|
||||
dataExchange: {
|
||||
retrieve: retrieveMeasurements,
|
||||
store: storeMeasurements,
|
||||
},
|
||||
};
|
||||
|
||||
const timepointApiDefaultConfig = {
|
||||
dataExchange: {
|
||||
retrieve: retrieveTimepoints,
|
||||
store: storeTimepoints,
|
||||
remove: removeTimepoint,
|
||||
update: updateTimepoint,
|
||||
disassociate: disassociateStudy,
|
||||
},
|
||||
};
|
||||
|
||||
export { measurementApiDefaultConfig, timepointApiDefaultConfig };
|
||||
@@ -1,229 +0,0 @@
|
||||
import { CriteriaEvaluator } from './CriteriaEvaluator';
|
||||
import * as initialEvaluations from './evaluations';
|
||||
import log from '../../log';
|
||||
|
||||
const evaluations = Object.assign({}, initialEvaluations);
|
||||
|
||||
const BASELINE = 'baseline';
|
||||
const FOLLOWUP = 'followup';
|
||||
const BOTH = 'both';
|
||||
const TARGETS = 'targets';
|
||||
const NONTARGETS = 'nonTargets';
|
||||
|
||||
class ConformanceCriteria {
|
||||
constructor(measurementApi, timepointApi, options = {}) {
|
||||
this.measurementApi = measurementApi;
|
||||
this.timepointApi = timepointApi;
|
||||
this.nonconformities = [];
|
||||
this.groupedNonConformities = [];
|
||||
this.maxTargets = null;
|
||||
this.maxNewTargets = null;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
loadStudy(StudyInstanceUID) {
|
||||
if (typeof this.options.loadStudy !== 'function') {
|
||||
throw new Error('loadStudy callback is not defined');
|
||||
}
|
||||
|
||||
return this.options.loadStudy(null, StudyInstanceUID);
|
||||
}
|
||||
|
||||
async validate(trialCriteriaType) {
|
||||
const baselinePromise = this.getData(BASELINE);
|
||||
const followupPromise = this.getData(FOLLOWUP);
|
||||
const [baselineData, followupData] = await Promise.all([
|
||||
baselinePromise,
|
||||
followupPromise,
|
||||
]);
|
||||
const mergedData = {
|
||||
targets: [],
|
||||
nonTargets: [],
|
||||
};
|
||||
|
||||
mergedData.targets = mergedData.targets.concat(baselineData.targets);
|
||||
mergedData.targets = mergedData.targets.concat(followupData.targets);
|
||||
mergedData.nonTargets = mergedData.nonTargets.concat(
|
||||
baselineData.nonTargets
|
||||
);
|
||||
mergedData.nonTargets = mergedData.nonTargets.concat(
|
||||
followupData.nonTargets
|
||||
);
|
||||
|
||||
this.maxTargets = null;
|
||||
this.maxNewTargets = null;
|
||||
const resultBoth = this.validateTimepoint(
|
||||
BOTH,
|
||||
trialCriteriaType,
|
||||
mergedData
|
||||
);
|
||||
const resultBaseline = this.validateTimepoint(
|
||||
BASELINE,
|
||||
trialCriteriaType,
|
||||
baselineData
|
||||
);
|
||||
const resultFollowup = this.validateTimepoint(
|
||||
FOLLOWUP,
|
||||
trialCriteriaType,
|
||||
followupData
|
||||
);
|
||||
const nonconformities = resultBaseline
|
||||
.concat(resultFollowup)
|
||||
.concat(resultBoth);
|
||||
const groupedNonConformities = this.groupNonConformities(nonconformities);
|
||||
|
||||
// Keep both? Group the data only on viewer/measurementTable views?
|
||||
// Work with not grouped data (worse lookup performance on measurementTableRow)?
|
||||
this.nonconformities = nonconformities;
|
||||
this.groupedNonConformities = groupedNonConformities;
|
||||
|
||||
// console.warn('nonconformities');
|
||||
// console.warn(nonconformities);
|
||||
// console.warn('groupedNonConformities');
|
||||
// console.warn(groupedNonConformities);
|
||||
|
||||
return nonconformities;
|
||||
}
|
||||
|
||||
groupNonConformities(nonconformities) {
|
||||
const groups = {};
|
||||
const toolsGroupsMap = this.measurementApi.toolsGroupsMap;
|
||||
|
||||
nonconformities.forEach(nonConformity => {
|
||||
if (nonConformity.isGlobal) {
|
||||
groups.globals = groups.globals || { messages: [] };
|
||||
groups.globals.messages.push(nonConformity.message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
nonConformity.measurements.forEach(measurement => {
|
||||
const groupName = toolsGroupsMap[measurement.toolType];
|
||||
groups[groupName] = groups[groupName] || { measurementNumbers: {} };
|
||||
|
||||
const group = groups[groupName];
|
||||
const measureNumber = measurement.measurementNumber;
|
||||
let measurementNumbers = group.measurementNumbers[measureNumber];
|
||||
|
||||
if (!measurementNumbers) {
|
||||
measurementNumbers = group.measurementNumbers[measureNumber] = {
|
||||
messages: [],
|
||||
measurements: [],
|
||||
};
|
||||
}
|
||||
|
||||
measurementNumbers.messages.push(nonConformity.message);
|
||||
measurementNumbers.measurements.push(measurement);
|
||||
});
|
||||
});
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
validateTimepoint(timepointType, trialCriteriaType, data) {
|
||||
const evaluators = this.getEvaluators(timepointType, trialCriteriaType);
|
||||
let nonconformities = [];
|
||||
|
||||
evaluators.forEach(evaluator => {
|
||||
const maxTargets = evaluator.getMaxTargets(false);
|
||||
const maxNewTargets = evaluator.getMaxTargets(true);
|
||||
if (maxTargets) {
|
||||
this.maxTargets = maxTargets;
|
||||
}
|
||||
|
||||
if (maxNewTargets) {
|
||||
this.maxNewTargets = maxNewTargets;
|
||||
}
|
||||
|
||||
const result = evaluator.evaluate(data);
|
||||
|
||||
if (result.length > 0) {
|
||||
result.forEach(resultItem => {
|
||||
resultItem.timepointType = timepointType;
|
||||
});
|
||||
}
|
||||
|
||||
nonconformities = nonconformities.concat(result);
|
||||
});
|
||||
|
||||
return nonconformities;
|
||||
}
|
||||
|
||||
getEvaluators(timepointType, trialCriteriaType) {
|
||||
const evaluators = [];
|
||||
console.warn(evaluations);
|
||||
const trialCriteriaTypeId = trialCriteriaType.id.toLowerCase();
|
||||
const evaluation = evaluations[trialCriteriaTypeId];
|
||||
|
||||
if (evaluation) {
|
||||
const evaluationTimepoint = evaluation[timepointType];
|
||||
|
||||
if (evaluationTimepoint) {
|
||||
evaluators.push(new CriteriaEvaluator(evaluationTimepoint));
|
||||
}
|
||||
}
|
||||
|
||||
return evaluators;
|
||||
}
|
||||
|
||||
/*
|
||||
* Build the data that will be used to do the conformance criteria checks
|
||||
*/
|
||||
async getData(timepointType) {
|
||||
const data = {
|
||||
targets: [],
|
||||
nonTargets: [],
|
||||
};
|
||||
|
||||
const studyPromises = [];
|
||||
|
||||
const fillData = measurementType => {
|
||||
const measurements = this.measurementApi.fetch(measurementType);
|
||||
|
||||
measurements.forEach(measurement => {
|
||||
const { StudyInstanceUID } = measurement;
|
||||
|
||||
const timepointId = measurement.timepointId;
|
||||
const timepoint =
|
||||
timepointId &&
|
||||
this.timepointApi.timepoints.find(a => a.timepointId === timepointId);
|
||||
|
||||
if (
|
||||
!timepoint ||
|
||||
(timepointType !== BOTH && timepoint.timepointType !== timepointType)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const promise = this.loadStudy(StudyInstanceUID);
|
||||
promise.then(
|
||||
studyMetadata => {
|
||||
data[measurementType].push({
|
||||
measurement,
|
||||
metadata: studyMetadata.getFirstInstance(),
|
||||
timepoint,
|
||||
});
|
||||
},
|
||||
error => {
|
||||
throw new Error(error);
|
||||
}
|
||||
);
|
||||
studyPromises.push(promise);
|
||||
});
|
||||
};
|
||||
|
||||
fillData(TARGETS);
|
||||
fillData(NONTARGETS);
|
||||
|
||||
await Promise.all(studyPromises);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static setEvaluationDefinitions(evaluationKey, evaluationDefinitions) {
|
||||
evaluations[evaluationKey] = evaluationDefinitions;
|
||||
}
|
||||
}
|
||||
|
||||
export default ConformanceCriteria;
|
||||
//OHIF.measurements.ConformanceCriteria = ConformanceCriteria;
|
||||
@@ -1,94 +0,0 @@
|
||||
import { BaseCriterion } from './criteria/BaseCriterion';
|
||||
import * as initialCriteria from './criteria';
|
||||
import Ajv from 'ajv';
|
||||
|
||||
const Criteria = Object.assign({}, initialCriteria);
|
||||
|
||||
export class CriteriaEvaluator {
|
||||
constructor(criteriaObject) {
|
||||
const criteriaValidator = this.getCriteriaValidator();
|
||||
this.criteria = [];
|
||||
|
||||
if (!criteriaValidator(criteriaObject)) {
|
||||
let message = '';
|
||||
criteriaValidator.errors.forEach(error => {
|
||||
message += `\noptions${error.dataPath} ${error.message}`;
|
||||
});
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
Object.keys(criteriaObject).forEach(criterionkey => {
|
||||
const optionsObject = criteriaObject[criterionkey];
|
||||
const Criterion = Criteria[`${criterionkey}Criterion`];
|
||||
const optionsArray =
|
||||
optionsObject instanceof Array ? optionsObject : [optionsObject];
|
||||
optionsArray.forEach(options =>
|
||||
this.criteria.push(new Criterion(options, criterionkey))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
getMaxTargets(newTarget = false) {
|
||||
let result = 0;
|
||||
this.criteria.forEach(criterion => {
|
||||
const newTargetMatch = newTarget === !!criterion.options.newTarget;
|
||||
if (criterion instanceof Criteria.MaxTargetsCriterion && newTargetMatch) {
|
||||
const { limit } = criterion.options;
|
||||
if (limit > result) {
|
||||
result = limit;
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
getCriteriaValidator() {
|
||||
if (CriteriaEvaluator.criteriaValidator) {
|
||||
return CriteriaEvaluator.criteriaValidator;
|
||||
}
|
||||
|
||||
const schema = {
|
||||
properties: {},
|
||||
definitions: {},
|
||||
};
|
||||
|
||||
Object.keys(Criteria).forEach(key => {
|
||||
const Criterion = Criteria[key];
|
||||
if (Criterion.prototype instanceof BaseCriterion) {
|
||||
const criterionkey = key.replace(/Criterion$/, '');
|
||||
const criterionDefinition = `#/definitions/${criterionkey}`;
|
||||
|
||||
schema.definitions[criterionkey] = Criteria[`${criterionkey}Schema`];
|
||||
schema.properties[criterionkey] = {
|
||||
oneOf: [
|
||||
{ $ref: criterionDefinition },
|
||||
{
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: criterionDefinition,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
CriteriaEvaluator.criteriaValidator = new Ajv().compile(schema);
|
||||
return CriteriaEvaluator.criteriaValidator;
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const nonconformities = [];
|
||||
this.criteria.forEach(criterion => {
|
||||
const criterionResult = criterion.evaluate(data);
|
||||
if (!criterionResult.passed) {
|
||||
nonconformities.push(criterionResult);
|
||||
}
|
||||
});
|
||||
return nonconformities;
|
||||
}
|
||||
|
||||
static setCriterion(criterionKey, criterionDefinitions) {
|
||||
Criteria[criterionKey] = criterionDefinitions;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
export class BaseCriterion {
|
||||
constructor(options, criterionName) {
|
||||
this.options = options;
|
||||
this.criterionName = criterionName;
|
||||
}
|
||||
|
||||
generateResponse(message, measurements) {
|
||||
const passed = !message;
|
||||
const isGlobal = !measurements || !measurements.length;
|
||||
|
||||
return {
|
||||
passed,
|
||||
isGlobal,
|
||||
message,
|
||||
measurements,
|
||||
criterionName: this.criterionName,
|
||||
};
|
||||
}
|
||||
|
||||
getNewTargetNumbers(data) {
|
||||
const { options } = this;
|
||||
const baselineMeasurementNumbers = [];
|
||||
const newTargetNumbers = new Set();
|
||||
|
||||
if (options.newTarget) {
|
||||
data.targets.forEach(target => {
|
||||
const { measurementNumber } = target.measurement;
|
||||
if (target.timepoint.timepointType === 'baseline') {
|
||||
baselineMeasurementNumbers.push(measurementNumber);
|
||||
}
|
||||
});
|
||||
data.targets.forEach(target => {
|
||||
const { measurementNumber } = target.measurement;
|
||||
if (target.timepoint.timepointType === 'followup') {
|
||||
if (!baselineMeasurementNumbers.includes(measurementNumber)) {
|
||||
newTargetNumbers.add(measurementNumber);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return newTargetNumbers;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const LocationSchema = {
|
||||
type: 'object',
|
||||
};
|
||||
|
||||
/* LocationCriterion
|
||||
* Check if the there are non-target measurements with response different than "present" on baseline
|
||||
*/
|
||||
export class LocationCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const items = data.targets.concat(data.nonTargets);
|
||||
const measurements = [];
|
||||
let message;
|
||||
|
||||
items.forEach(item => {
|
||||
const measurement = item.measurement;
|
||||
|
||||
if (!measurement.location) {
|
||||
measurements.push(measurement);
|
||||
}
|
||||
});
|
||||
|
||||
if (measurements.length) {
|
||||
message = 'All measurements should have a location';
|
||||
}
|
||||
|
||||
return this.generateResponse(message, measurements);
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const MaxTargetsSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: {
|
||||
label: 'Max targets allowed in study',
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
},
|
||||
newTarget: {
|
||||
label: 'Flag to evaluate only new targets',
|
||||
type: 'boolean',
|
||||
},
|
||||
locationIn: {
|
||||
label:
|
||||
'Filter to evaluate only measurements with the specified locations',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
locationNotIn: {
|
||||
label:
|
||||
'Filter to evaluate only measurements without the specified locations',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
isNodal: {
|
||||
label: 'Filter to evaluate only nodal or extranodal measurements',
|
||||
type: 'boolean'
|
||||
},
|
||||
message: {
|
||||
label: 'Message to be displayed in case of nonconformity',
|
||||
type: 'string',
|
||||
}
|
||||
},
|
||||
required: ['limit'],
|
||||
};
|
||||
|
||||
/* MaxTargetsCriterion
|
||||
* Check if the number of target measurements exceeded the limit allowed
|
||||
* Options:
|
||||
* limit: Max targets allowed in study
|
||||
* newTarget: Flag to evaluate only new targets (must be evaluated on both)
|
||||
* locationIn: Filter to evaluate only measurements with the specified locations
|
||||
* locationNotIn: Filter to evaluate only measurements without the specified locations
|
||||
* isNodal: Filter to evaluate only nodal or extranodal measurements
|
||||
* message: Message to be displayed in case of nonconformity
|
||||
*/
|
||||
export class MaxTargetsCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const { options } = this;
|
||||
|
||||
const newTargetNumbers = this.getNewTargetNumbers(data);
|
||||
const measurementNumbers = [];
|
||||
data.targets.forEach(target => {
|
||||
const { location, measurementNumber, isSplitLesion, isNodal } = target.measurement;
|
||||
|
||||
if (isSplitLesion)
|
||||
return;
|
||||
|
||||
if (typeof isNodal === 'boolean' && typeof options.isNodal === 'boolean' && options.isNodal !== isNodal)
|
||||
return;
|
||||
|
||||
if (options.newTarget && !newTargetNumbers.has(measurementNumber))
|
||||
return;
|
||||
|
||||
if (options.locationIn && options.locationIn.indexOf(location) === -1)
|
||||
return;
|
||||
|
||||
if (options.locationNotIn && options.locationNotIn.indexOf(location) > -1)
|
||||
return;
|
||||
|
||||
measurementNumbers.push(measurementNumber);
|
||||
});
|
||||
|
||||
let lesionType = '';
|
||||
if (typeof options.isNodal === 'boolean') {
|
||||
lesionType = options.isNodal ? 'nodal ' : 'extranodal ';
|
||||
}
|
||||
|
||||
let message;
|
||||
if (measurementNumbers.length > options.limit) {
|
||||
const increment = options.newTarget ? 'new ' : '';
|
||||
const plural = options.limit === 1 ? '' : 's';
|
||||
const amount = options.limit === 0 ? '' : `more than ${options.limit}`;
|
||||
message =
|
||||
options.message ||
|
||||
`The study should not have ${amount} ${increment}${lesionType}target${plural}.`;
|
||||
}
|
||||
|
||||
return this.generateResponse(message);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const MaxTargetsPerOrganSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: {
|
||||
label: 'Max targets allowed per organ',
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
newTarget: {
|
||||
label: 'Flag to evaluate only new targets',
|
||||
type: 'boolean',
|
||||
},
|
||||
isNodal: {
|
||||
label: 'Filter to evaluate only nodal or extranodal measurements',
|
||||
type: 'boolean'
|
||||
},
|
||||
message: {
|
||||
label: 'Message to be displayed in case of nonconformity',
|
||||
type: 'string',
|
||||
}
|
||||
},
|
||||
required: ['limit'],
|
||||
};
|
||||
|
||||
/*
|
||||
* MaxTargetsPerOrganCriterion
|
||||
* Check if the number of target measurements per organ exceeded the limit allowed
|
||||
* Options:
|
||||
* limit: Max targets allowed in study
|
||||
* newTarget: Flag to evaluate only new targets (must be evaluated on both)
|
||||
* isNodal: Filter to evaluate only nodal or extranodal measurements
|
||||
* message: Message to be displayed in case of nonconformity
|
||||
*/
|
||||
export class MaxTargetsPerOrganCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const { options } = this;
|
||||
const targetsPerOrgan = {};
|
||||
let measurements = [];
|
||||
|
||||
const newTargetNumbers = this.getNewTargetNumbers(data);
|
||||
data.targets.forEach(target => {
|
||||
const { measurement } = target;
|
||||
const { location, measurementNumber, isSplitLesion, isNodal } = measurement;
|
||||
|
||||
if (isSplitLesion)
|
||||
return;
|
||||
|
||||
if (typeof isNodal === 'boolean' && typeof options.isNodal === 'boolean' && options.isNodal !== isNodal)
|
||||
return;
|
||||
|
||||
if (!targetsPerOrgan[location]) {
|
||||
targetsPerOrgan[location] = new Set();
|
||||
}
|
||||
|
||||
if (!options.newTarget || newTargetNumbers.has(measurementNumber)) {
|
||||
targetsPerOrgan[location].add(measurementNumber);
|
||||
}
|
||||
|
||||
if (targetsPerOrgan[location].size > options.limit) {
|
||||
measurements.push(measurement);
|
||||
}
|
||||
});
|
||||
|
||||
let message;
|
||||
if (measurements.length) {
|
||||
const increment = options.newTarget ? 'new ' : '';
|
||||
message =
|
||||
options.message ||
|
||||
`Each organ should not have more than ${
|
||||
options.limit
|
||||
} ${increment}targets.`;
|
||||
}
|
||||
|
||||
return this.generateResponse(message, measurements);
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const MeasurementsLengthSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
longAxis: {
|
||||
label: 'Minimum length of long axis',
|
||||
type: 'number',
|
||||
minimum: 0,
|
||||
},
|
||||
shortAxis: {
|
||||
label: 'Minimum length of short axis',
|
||||
type: 'number',
|
||||
minimum: 0,
|
||||
},
|
||||
longAxisSliceThicknessMultiplier: {
|
||||
label: 'Length of long axis multiplier',
|
||||
type: 'number',
|
||||
minimum: 0,
|
||||
},
|
||||
shortAxisSliceThicknessMultiplier: {
|
||||
label: 'Length of short axis multiplier',
|
||||
type: 'number',
|
||||
minimum: 0,
|
||||
},
|
||||
modalityIn: {
|
||||
label:
|
||||
'Filter to evaluate only measurements with the specified modalities',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
modalityNotIn: {
|
||||
label:
|
||||
'Filter to evaluate only measurements without the specified modalities',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
locationIn: {
|
||||
label:
|
||||
'Filter to evaluate only measurements with the specified locations',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
locationNotIn: {
|
||||
label:
|
||||
'Filter to evaluate only measurements without the specified locations',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
isNodal: {
|
||||
label: 'Filter to evaluate only nodal or extranodal measurements',
|
||||
type: 'boolean',
|
||||
},
|
||||
message: {
|
||||
label: 'Message to be displayed in case of nonconformity',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
anyOf: [
|
||||
{ required: ['message', 'longAxis'] },
|
||||
{ required: ['message', 'shortAxis'] },
|
||||
{ required: ['message', 'longAxisSliceThicknessMultiplier'] },
|
||||
{ required: ['message', 'shortAxisSliceThicknessMultiplier'] },
|
||||
],
|
||||
};
|
||||
|
||||
/*
|
||||
* MeasurementsLengthCriterion
|
||||
* 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
|
||||
* shortAxis: Minimum length of short axis
|
||||
* longAxisSliceThicknessMultiplier: Length of long axis multiplier
|
||||
* shortAxisSliceThicknessMultiplier: Length of short axis multiplier
|
||||
* modalityIn: Filter to evaluate only measurements with the specified modalities
|
||||
* modalityNotIn: Filter to evaluate only measurements without the specified modalities
|
||||
* locationIn: Filter to evaluate only measurements with the specified locations
|
||||
* locationNotIn: Filter to evaluate only measurements without the specified locations
|
||||
* isNodal: Filter to evaluate only nodal or extranodal measurements
|
||||
* message: Message to be displayed in case of nonconformity
|
||||
*/
|
||||
export class MeasurementsLengthCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
let message;
|
||||
let measurements = [];
|
||||
const { options } = this;
|
||||
const longMultiplier = options.longAxisSliceThicknessMultiplier;
|
||||
const shortMultiplier = options.shortAxisSliceThicknessMultiplier;
|
||||
|
||||
data.targets.forEach(item => {
|
||||
const { metadata, measurement } = item;
|
||||
const { location } = measurement;
|
||||
|
||||
let { longestDiameter, shortestDiameter, isNodal } = measurement;
|
||||
if (measurement.childToolsCount) {
|
||||
const child = measurement.bidirectional;
|
||||
longestDiameter = (child && child.longestDiameter) || 0;
|
||||
shortestDiameter = (child && child.shortestDiameter) || 0;
|
||||
}
|
||||
|
||||
const { SliceThickness } = metadata;
|
||||
|
||||
const Modality = metadata.getTagValue('Modality') || '';
|
||||
|
||||
// Stop here if the measurement does not match the Modality and location filters
|
||||
if (
|
||||
typeof isNodal === 'boolean' &&
|
||||
typeof options.isNodal === 'boolean' &&
|
||||
options.isNodal !== isNodal
|
||||
)
|
||||
return;
|
||||
if (options.locationIn && options.locationIn.indexOf(location) === -1)
|
||||
return;
|
||||
if (options.modalityIn && options.modalityIn.indexOf(Modality) === -1)
|
||||
return;
|
||||
if (options.locationNotIn && options.locationNotIn.indexOf(location) > -1)
|
||||
return;
|
||||
if (options.modalityNotIn && options.modalityNotIn.indexOf(Modality) > -1)
|
||||
return;
|
||||
|
||||
// Check the measurement length
|
||||
const failed =
|
||||
(options.longAxis && longestDiameter < options.longAxis) ||
|
||||
(options.shortAxis && shortestDiameter < options.shortAxis) ||
|
||||
(longMultiplier &&
|
||||
!isNaN(SliceThickness) &&
|
||||
longestDiameter < longMultiplier * SliceThickness) ||
|
||||
(shortMultiplier &&
|
||||
!isNaN(SliceThickness) &&
|
||||
shortestDiameter < shortMultiplier * SliceThickness);
|
||||
|
||||
// Mark this measurement as invalid if some of the checks have failed
|
||||
if (failed) {
|
||||
measurements.push(measurement);
|
||||
}
|
||||
});
|
||||
|
||||
// Use the options' message if some measurement is invalid
|
||||
if (measurements.length) {
|
||||
message = options.message;
|
||||
}
|
||||
|
||||
return this.generateResponse(message, measurements);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const ModalitySchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
method: {
|
||||
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',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
modalities: {
|
||||
label: 'List of allowed/denied modalities',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
},
|
||||
},
|
||||
required: ['method', 'modalities'],
|
||||
};
|
||||
|
||||
/*
|
||||
* ModalityCriteria
|
||||
* Check if a Modality is allowed or denied
|
||||
* Options:
|
||||
* 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/denied modalities
|
||||
*/
|
||||
export class ModalityCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const measurementTypes = this.options.measurementTypes || ['targets'];
|
||||
const modalitiesSet = new Set(this.options.modalities);
|
||||
const validationMethod = this.options.method;
|
||||
const measurements = [];
|
||||
const invalidModalities = new Set();
|
||||
let message;
|
||||
|
||||
measurementTypes.forEach(measurementType => {
|
||||
const items = data[measurementType];
|
||||
|
||||
items.forEach(item => {
|
||||
const { measurement, metadata } = item;
|
||||
const Modality = metadata.getTagValue('Modality') || '';
|
||||
|
||||
if (
|
||||
(validationMethod === 'allow' && !modalitiesSet.has(Modality)) ||
|
||||
(validationMethod === 'deny' && modalitiesSet.has(Modality))
|
||||
) {
|
||||
measurements.push(measurement);
|
||||
invalidModalities.add(Modality);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (measurements.length) {
|
||||
const uniqueModalities = Array.from(invalidModalities);
|
||||
const uniqueModalitiesText = uniqueModalities.join(', ');
|
||||
const modalityText =
|
||||
uniqueModalities.length > 1 ? 'modalities' : 'Modality';
|
||||
|
||||
message = `The ${modalityText} ${uniqueModalitiesText} should not be used as a method of measurement`;
|
||||
}
|
||||
|
||||
return this.generateResponse(message, measurements);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const NonTargetResponseSchema = {
|
||||
type: 'object',
|
||||
};
|
||||
|
||||
/* NonTargetResponseCriterion
|
||||
* Check if the there are non-target measurements with response different than "present" on baseline
|
||||
*/
|
||||
export class NonTargetResponseCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const items = data.nonTargets;
|
||||
const measurements = [];
|
||||
let message;
|
||||
|
||||
items.forEach(item => {
|
||||
const measurement = item.measurement;
|
||||
const response = (measurement.response || '').toLowerCase();
|
||||
|
||||
if (response !== 'present') {
|
||||
measurements.push(measurement);
|
||||
}
|
||||
});
|
||||
|
||||
if (measurements.length) {
|
||||
message = 'Non-targets can only be assessed as "present"';
|
||||
}
|
||||
|
||||
return this.generateResponse(message, measurements);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { BaseCriterion } from './BaseCriterion';
|
||||
|
||||
export const TargetTypeSchema = {
|
||||
type: 'object',
|
||||
};
|
||||
|
||||
/* TargetTypeCriterion
|
||||
* Check if the there are non-bidirectional target measurements on baseline
|
||||
*/
|
||||
export class TargetTypeCriterion extends BaseCriterion {
|
||||
constructor(...props) {
|
||||
super(...props);
|
||||
}
|
||||
|
||||
evaluate(data) {
|
||||
const items = data.targets;
|
||||
const measurements = [];
|
||||
let message;
|
||||
|
||||
items.forEach(item => {
|
||||
const measurement = item.measurement;
|
||||
|
||||
if (
|
||||
measurement.toolType !== 'Bidirectional' &&
|
||||
!measurement.bidirectional
|
||||
) {
|
||||
measurements.push(measurement);
|
||||
}
|
||||
});
|
||||
|
||||
if (measurements.length) {
|
||||
message =
|
||||
'Target lesions must have measurements (cannot be assessed as CR, UN/NE, EX)';
|
||||
}
|
||||
|
||||
return this.generateResponse(message, measurements);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export * from './Location';
|
||||
export * from './MaxTargetsPerOrgan';
|
||||
export * from './MaxTargets';
|
||||
export * from './MeasurementsLength';
|
||||
export * from './Modality';
|
||||
export * from './NonTargetResponse';
|
||||
export * from './TargetType';
|
||||
@@ -1,3 +0,0 @@
|
||||
import * as recistEvaluation from './recist.json';
|
||||
|
||||
export const recist11 = recistEvaluation;
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"both": {
|
||||
"Location": {}
|
||||
},
|
||||
"baseline": {
|
||||
"TargetType": {},
|
||||
"MaxTargetsPerOrgan": {
|
||||
"limit": 2
|
||||
},
|
||||
"MaxTargets": {
|
||||
"limit": 5
|
||||
},
|
||||
"MeasurementsLength": [
|
||||
{
|
||||
"longAxis": 10,
|
||||
"longAxisSliceThicknessMultiplier": 2,
|
||||
"modalityIn": ["CT", "MR"],
|
||||
"locationNotIn": ["Lymph Node"],
|
||||
"message": "Extranodal lesions must be >= 10mm long axis AND >= double the acquisition slice thickness by CT and MR"
|
||||
},
|
||||
{
|
||||
"shortAxis": 20,
|
||||
"longAxis": 20,
|
||||
"modalityIn": ["PX", "XA"],
|
||||
"locationNotIn": ["Lymph Node"],
|
||||
"message": "Extranodal lesions must be >= 20mm on chest x-ray (although x-rays rarely used for clinical trial assessment)"
|
||||
},
|
||||
{
|
||||
"shortAxis": 15,
|
||||
"shortAxisSliceThicknessMultiplier": 2,
|
||||
"modalityIn": ["CT", "MR"],
|
||||
"locationIn": ["Lymph Node"],
|
||||
"message": "Nodal lesions must be >= 15mm short axis AND >= double the acquisition slice thickness by CT and MR"
|
||||
}
|
||||
]
|
||||
},
|
||||
"followup": {}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import ConformanceCriteria from './ConformanceCriteria';
|
||||
|
||||
export { ConformanceCriteria };
|
||||
@@ -1,36 +0,0 @@
|
||||
import log from '../log';
|
||||
|
||||
export const retrieveMeasurements = (PatientID, timepointIds) => {
|
||||
log.error('retrieveMeasurements');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
export const storeMeasurements = (measurementData, timepointIds) => {
|
||||
log.error('storeMeasurements');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
export const retrieveTimepoints = filter => {
|
||||
log.error('retrieveTimepoints');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
export const storeTimepoints = timepointData => {
|
||||
log.error('storeTimepoints');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
export const updateTimepoint = (timepointData, query) => {
|
||||
log.error('updateTimepoint');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
export const removeTimepoint = timepointId => {
|
||||
log.error('removeTimepoint');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
export const disassociateStudy = (timepointIds, StudyInstanceUID) => {
|
||||
log.error('disassociateStudy');
|
||||
return Promise.resolve();
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
import * as tools from './tools';
|
||||
|
||||
import { MeasurementApi, TimepointApi } from './classes';
|
||||
import { ConformanceCriteria } from './conformance';
|
||||
import MeasurementHandlers from './measurementHandlers';
|
||||
import getDescription from './lib/getDescription';
|
||||
import getImageAttributes from './lib/getImageAttributes';
|
||||
import getImageIdForImagePath from './lib/getImageIdForImagePath';
|
||||
import getLabel from './lib/getLabel';
|
||||
import ltTools from './ltTools';
|
||||
|
||||
const measurements = {
|
||||
TimepointApi,
|
||||
MeasurementApi,
|
||||
ConformanceCriteria,
|
||||
MeasurementHandlers,
|
||||
ltTools,
|
||||
tools,
|
||||
getLabel,
|
||||
getDescription,
|
||||
getImageAttributes,
|
||||
getImageIdForImagePath,
|
||||
};
|
||||
|
||||
export default measurements;
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function(measurement) {
|
||||
return measurement.description;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
|
||||
export default function(element) {
|
||||
// Get the Cornerstone imageId
|
||||
const enabledElement = cornerstone.getEnabledElement(element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
|
||||
// Get StudyInstanceUID & PatientID
|
||||
const {
|
||||
StudyInstanceUID,
|
||||
PatientID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
} = cornerstone.metaData.get('instance', imageId);
|
||||
|
||||
const splitImageId = imageId.split('&frame');
|
||||
const frameIndex =
|
||||
splitImageId[1] !== undefined ? Number(splitImageId[1]) : 0;
|
||||
|
||||
const imagePath = [
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
frameIndex,
|
||||
].join('_');
|
||||
|
||||
return {
|
||||
PatientID,
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
frameIndex,
|
||||
imagePath,
|
||||
};
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import studyMetadataManager from '../../utils/studyMetadataManager';
|
||||
|
||||
export default function(imagePath, thumbnail = false) {
|
||||
const [
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
frameIndex,
|
||||
] = imagePath.split('_');
|
||||
const studyMetadata = studyMetadataManager.get(StudyInstanceUID);
|
||||
const series = studyMetadata.getSeriesByUID(SeriesInstanceUID);
|
||||
const instance = series.getInstanceByUID(SOPInstanceUID);
|
||||
return instance.getImageId(frameIndex, thumbnail);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
export default function(measurement) {
|
||||
if (!measurement) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (measurement.toolType) {
|
||||
case 'Bidirectional':
|
||||
case 'TargetCR':
|
||||
case 'TargetNE':
|
||||
case 'TargetUN':
|
||||
return `Target ${measurement.lesionNamingNumber}`;
|
||||
case 'NonTarget':
|
||||
return `Non-Target ${measurement.lesionNamingNumber}`;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { targets } from './toolGroups/targets';
|
||||
import { nonTargets } from './toolGroups/nonTargets';
|
||||
import { temp } from './toolGroups/temp';
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
|
||||
const ltTools = cloneDeep([targets, nonTargets, temp]);
|
||||
|
||||
ltTools.forEach(toolGroup => {
|
||||
toolGroup.childTools.forEach(tool => {
|
||||
tool.toolGroup = toolGroup.id;
|
||||
});
|
||||
});
|
||||
|
||||
export default ltTools;
|
||||
@@ -1,98 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import { MeasurementApi } from '../classes';
|
||||
import log from '../../log';
|
||||
import user from '../../user';
|
||||
import getImageAttributes from '../lib/getImageAttributes';
|
||||
import getLabel from '../lib/getLabel';
|
||||
|
||||
export default function({ eventData, tool, toolGroupId, toolGroup }) {
|
||||
const measurementApi = MeasurementApi.Instance;
|
||||
if (!measurementApi) {
|
||||
log.warn('Measurement API is not initialized');
|
||||
}
|
||||
|
||||
const { measurementData } = eventData;
|
||||
|
||||
const collection = measurementApi.tools[tool.parentTool];
|
||||
|
||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||
if (!collection) return;
|
||||
|
||||
// Stop here if there's no measurement data or if it was cancelled
|
||||
if (!measurementData || measurementData.cancelled) return;
|
||||
|
||||
log.info('CornerstoneToolsMeasurementAdded');
|
||||
|
||||
const imageAttributes = getImageAttributes(eventData.element);
|
||||
|
||||
const additionalProperties = Object.assign(imageAttributes, {
|
||||
userId: user.getUserId(),
|
||||
});
|
||||
|
||||
const childMeasurement = Object.assign(
|
||||
{},
|
||||
measurementData,
|
||||
additionalProperties
|
||||
);
|
||||
|
||||
const parentMeasurement = collection.find(
|
||||
t =>
|
||||
t.toolType === tool.parentTool &&
|
||||
t.PatientID === imageAttributes.PatientID &&
|
||||
t[tool.attribute] === null
|
||||
);
|
||||
|
||||
// Check if a measurement to fit this child tool already exists
|
||||
if (parentMeasurement) {
|
||||
const key = tool.attribute;
|
||||
|
||||
// Add the createdAt attribute
|
||||
childMeasurement.createdAt = new Date();
|
||||
|
||||
// Update the parent measurement
|
||||
parentMeasurement[key] = childMeasurement;
|
||||
parentMeasurement.childToolsCount =
|
||||
(parentMeasurement.childToolsCount || 0) + 1;
|
||||
measurementApi.updateMeasurement(tool.parentTool, parentMeasurement);
|
||||
|
||||
// Update the measurementData ID and lesionNamingNumber
|
||||
measurementData._id = parentMeasurement._id;
|
||||
measurementData.lesionNamingNumber = parentMeasurement.lesionNamingNumber;
|
||||
} else {
|
||||
const measurement = {
|
||||
toolType: tool.parentTool,
|
||||
lesionNamingNumber: measurementData.lesionNamingNumber,
|
||||
userId: user.getUserId(),
|
||||
PatientID: imageAttributes.PatientID,
|
||||
StudyInstanceUID: imageAttributes.StudyInstanceUID,
|
||||
};
|
||||
|
||||
measurement[tool.attribute] = Object.assign(
|
||||
{},
|
||||
measurementData,
|
||||
additionalProperties
|
||||
);
|
||||
|
||||
const addedMeasurement = measurementApi.addMeasurement(
|
||||
tool.parentTool,
|
||||
measurement
|
||||
);
|
||||
Object.assign(measurementData, addedMeasurement);
|
||||
}
|
||||
|
||||
const measurementLabel = getLabel(measurementData);
|
||||
if (measurementLabel) {
|
||||
measurementData.labels = [measurementLabel];
|
||||
}
|
||||
|
||||
// TODO: This is very hacky, but will work for now
|
||||
cornerstone.getEnabledElements().forEach(enabledElement => {
|
||||
cornerstone.updateImage(enabledElement.element);
|
||||
});
|
||||
|
||||
// TODO: Notify about the last activated measurement
|
||||
|
||||
if (MeasurementApi.isToolIncluded(tool)) {
|
||||
// TODO: Notify that viewer suffered changes
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import { MeasurementApi } from '../classes';
|
||||
import log from '../../log';
|
||||
|
||||
export default function({ eventData, tool, toolGroupId, toolGroup }) {
|
||||
const measurementApi = MeasurementApi.Instance;
|
||||
if (!measurementApi) {
|
||||
log.warn('Measurement API is not initialized');
|
||||
}
|
||||
|
||||
const { measurementData } = eventData;
|
||||
|
||||
const collection = measurementApi.tools[tool.parentTool];
|
||||
|
||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||
if (!collection) return;
|
||||
|
||||
log.info('CornerstoneToolsMeasurementModified');
|
||||
|
||||
const measurement = collection.find(t => t._id === measurementData._id);
|
||||
let childMeasurement = measurement && measurement[tool.attribute];
|
||||
|
||||
// Stop here if the measurement is already deleted
|
||||
if (!childMeasurement) return;
|
||||
|
||||
childMeasurement = Object.assign(childMeasurement, measurementData);
|
||||
childMeasurement.viewport = cornerstone.getViewport(eventData.element);
|
||||
|
||||
// Update the parent measurement
|
||||
measurement[tool.attribute] = childMeasurement;
|
||||
measurementApi.updateMeasurement(tool.parentTool, measurement);
|
||||
|
||||
// TODO: Notify about the last activated measurement
|
||||
|
||||
if (MeasurementApi.isToolIncluded(tool)) {
|
||||
// TODO: Notify that viewer suffered changes
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import { MeasurementApi } from '../classes';
|
||||
import log from '../../log';
|
||||
|
||||
export default function({ eventData, tool, toolGroupId, toolGroup }) {
|
||||
log.info('CornerstoneToolsMeasurementRemoved');
|
||||
const { measurementData } = eventData;
|
||||
|
||||
const measurementApi = MeasurementApi.Instance;
|
||||
if (!measurementApi) {
|
||||
log.warn('Measurement API is not initialized');
|
||||
}
|
||||
|
||||
const collection = measurementApi.tools[tool.parentTool];
|
||||
|
||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||
if (!collection) return;
|
||||
|
||||
const measurementIndex = collection.findIndex(
|
||||
t => t._id === measurementData._id
|
||||
);
|
||||
const measurement =
|
||||
measurementIndex > -1 ? collection[measurementIndex] : null;
|
||||
|
||||
// Stop here if the measurement is already gone or never existed
|
||||
if (!measurement) return;
|
||||
|
||||
if (measurement.childToolsCount === 1) {
|
||||
// Remove the measurement
|
||||
collection.splice(measurementIndex, 1);
|
||||
measurementApi.onMeasurementRemoved(tool.parentTool, measurement);
|
||||
} else {
|
||||
// Update the measurement
|
||||
measurement[tool.attribute] = null;
|
||||
measurement.childToolsCount = (measurement.childToolsCount || 0) - 1;
|
||||
measurementApi.updateMeasurement(tool.parentTool, measurement);
|
||||
}
|
||||
|
||||
// TODO: This is very hacky, but will work for now
|
||||
cornerstone.getEnabledElements().forEach(enabledElement => {
|
||||
cornerstone.updateImage(enabledElement.element);
|
||||
});
|
||||
|
||||
if (MeasurementApi.isToolIncluded(tool)) {
|
||||
// TODO: Notify that viewer suffered changes
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import { MeasurementApi } from '../classes';
|
||||
import log from '../../log';
|
||||
import user from '../../user';
|
||||
import getImageAttributes from '../lib/getImageAttributes';
|
||||
import getLabel from '../lib/getLabel';
|
||||
|
||||
export default function handleSingleMeasurementAdded({ eventData, tool }) {
|
||||
const measurementApi = MeasurementApi.Instance;
|
||||
if (!measurementApi) {
|
||||
log.warn('Measurement API is not initialized');
|
||||
}
|
||||
|
||||
const { measurementData, toolType } = eventData;
|
||||
|
||||
const collection = measurementApi.tools[toolType];
|
||||
|
||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||
if (!collection) return;
|
||||
|
||||
// Stop here if there's no measurement data or if it was cancelled
|
||||
if (!measurementData || measurementData.cancelled) return;
|
||||
|
||||
log.info('CornerstoneToolsMeasurementAdded');
|
||||
|
||||
const imageAttributes = getImageAttributes(eventData.element);
|
||||
const measurement = Object.assign({}, measurementData, imageAttributes, {
|
||||
lesionNamingNumber: measurementData.lesionNamingNumber,
|
||||
userId: user.getUserId(),
|
||||
toolType,
|
||||
});
|
||||
|
||||
const addedMeasurement = measurementApi.addMeasurement(toolType, measurement);
|
||||
Object.assign(measurementData, addedMeasurement);
|
||||
|
||||
const measurementLabel = getLabel(measurementData);
|
||||
if (measurementLabel) {
|
||||
measurementData.labels = [measurementLabel];
|
||||
}
|
||||
|
||||
// TODO: This is very hacky, but will work for now
|
||||
cornerstone.getEnabledElements().forEach(enabledElement => {
|
||||
cornerstone.updateImage(enabledElement.element);
|
||||
});
|
||||
|
||||
// TODO: Notify about the last activated measurement
|
||||
|
||||
if (MeasurementApi.isToolIncluded(tool)) {
|
||||
// TODO: Notify that viewer suffered changes
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import { MeasurementApi } from '../classes';
|
||||
import log from '../../log';
|
||||
|
||||
export default function({ eventData, tool, toolGroupId, toolGroup }) {
|
||||
const measurementApi = MeasurementApi.Instance;
|
||||
if (!measurementApi) {
|
||||
log.warn('Measurement API is not initialized');
|
||||
}
|
||||
|
||||
const { measurementData, toolType } = eventData;
|
||||
|
||||
const collection = measurementApi.tools[toolType];
|
||||
|
||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||
if (!collection) return;
|
||||
|
||||
log.info('CornerstoneToolsMeasurementModified');
|
||||
let measurement = collection.find(t => t._id === measurementData._id);
|
||||
|
||||
// Stop here if the measurement is already deleted
|
||||
if (!measurement) return;
|
||||
|
||||
measurement = Object.assign(measurement, measurementData);
|
||||
measurement.viewport = cornerstone.getViewport(eventData.element);
|
||||
|
||||
measurementApi.updateMeasurement(toolType, measurement);
|
||||
|
||||
// TODO: Notify about the last activated measurement
|
||||
|
||||
if (MeasurementApi.isToolIncluded(tool)) {
|
||||
// TODO: Notify that viewer suffered changes
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import { MeasurementApi } from '../classes';
|
||||
import log from '../../log';
|
||||
|
||||
export default function handleSingleMeasurementRemoved({
|
||||
eventData,
|
||||
tool,
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
}) {
|
||||
log.info('CornerstoneToolsMeasurementRemoved');
|
||||
const { measurementData, toolType } = eventData;
|
||||
|
||||
const measurementApi = MeasurementApi.Instance;
|
||||
if (!measurementApi) {
|
||||
log.warn('Measurement API is not initialized');
|
||||
}
|
||||
|
||||
const collection = measurementApi.tools[toolType];
|
||||
|
||||
// Stop here if the tool data shall not be persisted (e.g. temp tools)
|
||||
if (!collection) return;
|
||||
|
||||
const measurementTypeId = measurementApi.toolsGroupsMap[toolType];
|
||||
const measurement = collection.find(t => t._id === measurementData._id);
|
||||
|
||||
// Stop here if the measurement is already gone or never existed
|
||||
if (!measurement) return;
|
||||
|
||||
// Remove all the measurements with the given type and number
|
||||
const { lesionNamingNumber, timepointId } = measurement;
|
||||
measurementApi.deleteMeasurements(toolType, measurementTypeId, {
|
||||
lesionNamingNumber,
|
||||
timepointId,
|
||||
});
|
||||
|
||||
// TODO: This is very hacky, but will work for now
|
||||
cornerstone.getEnabledElements().forEach(enabledElement => {
|
||||
cornerstone.updateImage(enabledElement.element);
|
||||
});
|
||||
|
||||
if (MeasurementApi.isToolIncluded(tool)) {
|
||||
// TODO: Notify that viewer suffered changes
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
import { MeasurementApi } from '../classes';
|
||||
import handleSingleMeasurementAdded from './handleSingleMeasurementAdded';
|
||||
import handleChildMeasurementAdded from './handleChildMeasurementAdded';
|
||||
import handleSingleMeasurementModified from './handleSingleMeasurementModified';
|
||||
import handleChildMeasurementModified from './handleChildMeasurementModified';
|
||||
import handleSingleMeasurementRemoved from './handleSingleMeasurementRemoved';
|
||||
import handleChildMeasurementRemoved from './handleChildMeasurementRemoved';
|
||||
|
||||
const getEventData = event => {
|
||||
const eventData = event.detail;
|
||||
if (eventData.toolName) {
|
||||
eventData.toolType = eventData.toolName;
|
||||
}
|
||||
|
||||
return eventData;
|
||||
};
|
||||
|
||||
const MeasurementHandlers = {
|
||||
handleSingleMeasurementAdded,
|
||||
handleChildMeasurementAdded,
|
||||
handleSingleMeasurementModified,
|
||||
handleChildMeasurementModified,
|
||||
handleSingleMeasurementRemoved,
|
||||
handleChildMeasurementRemoved,
|
||||
|
||||
onAdded(event) {
|
||||
const eventData = getEventData(event);
|
||||
const { toolType } = eventData;
|
||||
const {
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
tool,
|
||||
} = MeasurementApi.getToolConfiguration(toolType);
|
||||
const params = {
|
||||
eventData,
|
||||
tool,
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
};
|
||||
|
||||
if (!tool) return;
|
||||
|
||||
if (tool.parentTool) {
|
||||
handleChildMeasurementAdded(params);
|
||||
} else {
|
||||
handleSingleMeasurementAdded(params);
|
||||
}
|
||||
},
|
||||
|
||||
onModified(event) {
|
||||
const eventData = getEventData(event);
|
||||
const { toolType } = eventData;
|
||||
const {
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
tool,
|
||||
} = MeasurementApi.getToolConfiguration(toolType);
|
||||
const params = {
|
||||
eventData,
|
||||
tool,
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
};
|
||||
|
||||
if (!tool) return;
|
||||
|
||||
if (tool.parentTool) {
|
||||
handleChildMeasurementModified(params);
|
||||
} else {
|
||||
handleSingleMeasurementModified(params);
|
||||
}
|
||||
},
|
||||
|
||||
onRemoved(event) {
|
||||
const eventData = getEventData(event);
|
||||
const { toolType } = eventData;
|
||||
const {
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
tool,
|
||||
} = MeasurementApi.getToolConfiguration(toolType);
|
||||
const params = {
|
||||
eventData,
|
||||
tool,
|
||||
toolGroupId,
|
||||
toolGroup,
|
||||
};
|
||||
|
||||
if (!tool) return;
|
||||
|
||||
if (tool.parentTool) {
|
||||
handleChildMeasurementRemoved(params);
|
||||
} else {
|
||||
handleSingleMeasurementRemoved(params);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default MeasurementHandlers;
|
||||
@@ -1,16 +0,0 @@
|
||||
import * as tools from '../tools';
|
||||
|
||||
const childTools = [];
|
||||
Object.keys(tools).forEach(key => childTools.push(tools[key]));
|
||||
|
||||
export const allTools = {
|
||||
id: 'allTools',
|
||||
name: 'Measurements',
|
||||
childTools: childTools,
|
||||
options: {
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import { nonTarget } from '../tools';
|
||||
|
||||
export const nonTargets = {
|
||||
id: 'nonTargets',
|
||||
name: 'Non-Targets',
|
||||
childTools: [nonTarget],
|
||||
options: {
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import { bidirectional, targetCR, targetUN, targetNE } from '../tools';
|
||||
|
||||
export const targets = {
|
||||
id: 'targets',
|
||||
name: 'Targets',
|
||||
childTools: [bidirectional, targetCR, targetUN, targetNE],
|
||||
options: {
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { length, ellipticalRoi } from '../tools';
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
|
||||
const childTools = cloneDeep([length, ellipticalRoi]);
|
||||
|
||||
// Exclude temp tools from case progress
|
||||
childTools.forEach(childTool => {
|
||||
childTool.options = Object.assign({}, childTool.options, {
|
||||
caseProgress: {
|
||||
include: false,
|
||||
evaluate: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
export const temp = {
|
||||
id: 'temp',
|
||||
name: 'Temporary',
|
||||
childTools,
|
||||
options: {
|
||||
caseProgress: {
|
||||
include: false,
|
||||
evaluate: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
let text = '';
|
||||
if (data.rAngle && !isNaN(data.rAngle)) {
|
||||
text = data.rAngle.toFixed(2) + String.fromCharCode(parseInt('00B0', 16));
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
export const angle = {
|
||||
id: 'Angle',
|
||||
name: 'Angle',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'Angle',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
return data.text || '';
|
||||
};
|
||||
|
||||
export const arrowAnnotate = {
|
||||
id: 'ArrowAnnotate',
|
||||
name: 'ArrowAnnotate',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'ArrowAnnotate',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
if (data.shortestDiameter) {
|
||||
// TODO: Make this check criteria again to see if we should display shortest x longest
|
||||
return data.longestDiameter + ' x ' + data.shortestDiameter;
|
||||
}
|
||||
|
||||
return data.longestDiameter;
|
||||
};
|
||||
|
||||
export const bidirectional = {
|
||||
id: 'Bidirectional',
|
||||
name: 'Target',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'Bidirectional',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
let meanValue = '';
|
||||
const { cachedStats } = data;
|
||||
if (cachedStats && cachedStats.mean && !isNaN(cachedStats.mean)) {
|
||||
meanValue = cachedStats.mean.toFixed(2) + ' HU';
|
||||
}
|
||||
return meanValue;
|
||||
};
|
||||
|
||||
export const circleRoi = {
|
||||
id: 'CircleRoi',
|
||||
name: 'Circle',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'CircleRoi',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
let meanValue = '';
|
||||
const { cachedStats } = data;
|
||||
if (cachedStats && cachedStats.mean && !isNaN(cachedStats.mean)) {
|
||||
meanValue = cachedStats.mean.toFixed(2) + ' HU';
|
||||
}
|
||||
return meanValue;
|
||||
};
|
||||
|
||||
export const ellipticalRoi = {
|
||||
id: 'EllipticalRoi',
|
||||
name: 'Ellipse',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'EllipticalRoi',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
let meanValue = '';
|
||||
if (data.meanStdDev && data.meanStdDev.mean && !isNaN(data.meanStdDev.mean)) {
|
||||
meanValue = data.meanStdDev.mean.toFixed(2) + ' HU';
|
||||
}
|
||||
return meanValue;
|
||||
};
|
||||
|
||||
export const freehandMouse = {
|
||||
id: 'FreehandMouse',
|
||||
name: 'Freehand',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'FreehandMouse',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
import { arrowAnnotate } from './arrowAnnotate';
|
||||
import { bidirectional } from './bidirectional';
|
||||
import { ellipticalRoi } from './ellipticalRoi';
|
||||
import { circleRoi } from './circleRoi';
|
||||
import { freehandMouse } from './freehandMouse';
|
||||
import { length } from './length';
|
||||
import { nonTarget } from './nonTarget';
|
||||
import { rectangleRoi } from './rectangleRoi';
|
||||
import { angle } from './angle';
|
||||
import { targetCR } from './targetCR';
|
||||
import { targetNE } from './targetNE';
|
||||
import { targetUN } from './targetUN';
|
||||
|
||||
export {
|
||||
arrowAnnotate,
|
||||
bidirectional,
|
||||
ellipticalRoi,
|
||||
circleRoi,
|
||||
freehandMouse,
|
||||
length,
|
||||
nonTarget,
|
||||
rectangleRoi,
|
||||
angle,
|
||||
targetCR,
|
||||
targetNE,
|
||||
targetUN,
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
let lengthValue = '';
|
||||
if (data.length && !isNaN(data.length)) {
|
||||
lengthValue = data.length.toFixed(2) + ' mm';
|
||||
}
|
||||
return lengthValue;
|
||||
};
|
||||
|
||||
export const length = {
|
||||
id: 'Length',
|
||||
name: 'Length',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'Length',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
export const nonTarget = {
|
||||
id: 'NonTarget',
|
||||
name: 'Non-Target',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'NonTarget',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction: data => data.response,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
const displayFunction = data => {
|
||||
let meanValue = '';
|
||||
const { cachedStats } = data;
|
||||
if (cachedStats && cachedStats.mean && !isNaN(cachedStats.mean)) {
|
||||
meanValue = cachedStats.mean.toFixed(2) + ' HU';
|
||||
}
|
||||
return meanValue;
|
||||
};
|
||||
|
||||
export const rectangleRoi = {
|
||||
id: 'RectangleRoi',
|
||||
name: 'Rectangle',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'RectangleRoi',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
export const targetCR = {
|
||||
id: 'TargetCR',
|
||||
name: 'CR Target',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'TargetCR',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction: data => data.response,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
export const targetNE = {
|
||||
id: 'TargetNE',
|
||||
name: 'NE Target',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'TargetNE',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction: data => data.response,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
export const targetUN = {
|
||||
id: 'TargetUN',
|
||||
name: 'UN Target',
|
||||
toolGroup: 'allTools',
|
||||
cornerstoneToolType: 'TargetUN',
|
||||
options: {
|
||||
measurementTable: {
|
||||
displayFunction: data => data.response,
|
||||
},
|
||||
caseProgress: {
|
||||
include: true,
|
||||
evaluate: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user