PWV-3: Refactoring MeasurementConfiguration and TimepointsConfiguration
This commit is contained in:
parent
151837d8d1
commit
f3f32518c6
@ -1,16 +1,10 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { TimepointsConfiguration } from 'meteor/ohif:measurements/both/configuration/timepoints';
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { MeasurementHandlers } from 'meteor/ohif:measurements/client/lib/MeasurementHandlers';
|
||||
|
||||
Session.set('TimepointsReady', false);
|
||||
Session.set('MeasurementsReady', false);
|
||||
|
||||
Template.viewer.onCreated(() => {
|
||||
const TimepointApi = TimepointsConfiguration.getTimepointsApi();
|
||||
const MeasurementApi = MeasurementsConfiguration.getMeasurementsApi();
|
||||
|
||||
OHIF.viewer = OHIF.viewer || {};
|
||||
ViewerData = window.ViewerData || ViewerData;
|
||||
|
||||
const instance = Template.instance();
|
||||
@ -68,19 +62,19 @@ Template.viewer.onCreated(() => {
|
||||
});
|
||||
|
||||
if (instance.data.currentTimepointId) {
|
||||
instance.data.timepointApi = new TimepointApi(instance.data.currentTimepointId);
|
||||
instance.data.timepointApi = new OHIF.measurements.TimepointApi(instance.data.currentTimepointId);
|
||||
const timepointsPromise = instance.data.timepointApi.retrieveTimepoints();
|
||||
timepointsPromise.then(() => {
|
||||
Session.set('TimepointsReady', true);
|
||||
})
|
||||
});
|
||||
|
||||
instance.data.measurementApi = new MeasurementApi(instance.data.currentTimepointId);
|
||||
instance.data.measurementApi = new OHIF.measurements.MeasurementApi(instance.data.currentTimepointId);
|
||||
const measurementsPromise = instance.data.measurementApi.retrieveMeasurements();
|
||||
measurementsPromise.then(() => {
|
||||
Session.set('MeasurementsReady', true);
|
||||
|
||||
instance.data.measurementApi.syncMeasurementsAndToolData();
|
||||
})
|
||||
});
|
||||
|
||||
// Provide the necessary data to the Measurement API and Timepoint API
|
||||
const prior = instance.data.timepointApi.prior();
|
||||
@ -89,7 +83,7 @@ Template.viewer.onCreated(() => {
|
||||
}
|
||||
} else {
|
||||
console.warn('No current timepoint specified');
|
||||
instance.data.measurementApi = new MeasurementApi();
|
||||
instance.data.measurementApi = new OHIF.measurements.MeasurementApi();
|
||||
}
|
||||
});
|
||||
|
||||
@ -98,7 +92,7 @@ Template.viewer.helpers({
|
||||
// TODO: Find a better way to do this
|
||||
return Session.get('TimepointsReady') && Session.get('MeasurementsReady');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Template.viewer.events({
|
||||
'CornerstoneToolsMeasurementAdded .imageViewerViewport'(event, instance, eventData) {
|
||||
|
||||
@ -5,8 +5,6 @@ import { MeasurementHandlers } from 'meteor/ohif:measurements/client/lib/Measure
|
||||
Session.set('MeasurementsReady', false);
|
||||
|
||||
Template.viewer.onCreated(() => {
|
||||
const MeasurementApi = MeasurementsConfiguration.getMeasurementsApi();
|
||||
|
||||
OHIF.viewer = OHIF.viewer || {};
|
||||
|
||||
const instance = Template.instance();
|
||||
@ -39,7 +37,7 @@ Template.viewer.onCreated(() => {
|
||||
ViewerStudies.insert(study);
|
||||
});
|
||||
|
||||
instance.data.measurementApi = new MeasurementApi();
|
||||
instance.data.measurementApi = new OHIF.measurements.MeasurementApi();
|
||||
const measurementsPromise = instance.data.measurementApi.retrieveMeasurements();
|
||||
measurementsPromise.then(() => {
|
||||
Session.set('MeasurementsReady', true);
|
||||
|
||||
@ -2,7 +2,10 @@
|
||||
* Defines the base OHIF object
|
||||
*/
|
||||
|
||||
const OHIF = {};
|
||||
const OHIF = {
|
||||
viewer: {},
|
||||
measurements: {}
|
||||
};
|
||||
|
||||
// Expose the OHIF object to the client if it is on development mode
|
||||
if (Meteor.isDevelopment && Meteor.isClient) {
|
||||
|
||||
@ -1,32 +1,31 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
import { measurementTools } from './measurementTools';
|
||||
import { retrieveMeasurements, storeMeasurements, retrieveTimepoints, storeTimepoints } from './dataExchange';
|
||||
import { validateMeasurements } from './dataValidation';
|
||||
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { TimepointsConfiguration } from 'meteor/ohif:measurements/both/configuration/timepoints';
|
||||
|
||||
console.log('OHIF-LesionTracker: Defining Configuration for Measurements');
|
||||
|
||||
const newMeasurementTool = {
|
||||
id: 'newLesions',
|
||||
name: 'New Lesions'
|
||||
id: 'newLesions',
|
||||
name: 'New Lesions'
|
||||
};
|
||||
|
||||
MeasurementsConfiguration.setConfiguration({
|
||||
measurementTools: measurementTools,
|
||||
newMeasurementTool: newMeasurementTool,
|
||||
dataExchange: {
|
||||
retrieve: retrieveMeasurements,
|
||||
store: storeMeasurements
|
||||
},
|
||||
dataValidation: {
|
||||
validation: validateMeasurements
|
||||
}
|
||||
OHIF.measurements.MeasurementApi.setConfiguration({
|
||||
measurementTools: measurementTools,
|
||||
newMeasurementTool: newMeasurementTool,
|
||||
dataExchange: {
|
||||
retrieve: retrieveMeasurements,
|
||||
store: storeMeasurements
|
||||
},
|
||||
dataValidation: {
|
||||
validation: validateMeasurements
|
||||
}
|
||||
});
|
||||
|
||||
TimepointsConfiguration.setConfiguration({
|
||||
dataExchange: {
|
||||
retrieve: retrieveTimepoints,
|
||||
store: storeTimepoints
|
||||
}
|
||||
});
|
||||
OHIF.measurements.TimepointApi.setConfiguration({
|
||||
dataExchange: {
|
||||
retrieve: retrieveTimepoints,
|
||||
store: storeTimepoints
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,66 +1,66 @@
|
||||
import { measurementTools } from './measurementTools';
|
||||
|
||||
export const retrieveMeasurements = () => {
|
||||
console.log('retrieveMeasurements');
|
||||
console.log('retrieveMeasurements');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("retrieveMeasurements", (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
console.log(response);
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call('retrieveMeasurements', (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
console.log(response);
|
||||
|
||||
/*measurementTools.forEach(tool => {
|
||||
console.log('Retrieving tool: ' + tool.id);
|
||||
});*/
|
||||
/*measurementTools.forEach(tool => {
|
||||
console.log('Retrieving tool: ' + tool.id);
|
||||
});*/
|
||||
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const storeMeasurements = (measurementData) => {
|
||||
console.log('storeMeasurements');
|
||||
console.log('storeMeasurements');
|
||||
|
||||
// Here is where we should do any required data transformation and API calls
|
||||
// Here is where we should do any required data transformation and API calls
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("storeMeasurements", measurementData, (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call('storeMeasurements', measurementData, (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const retrieveTimepoints = () => {
|
||||
console.log('retrieveTimepoints');
|
||||
console.log('retrieveTimepoints');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("retrieveTimepoints", (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call('retrieveTimepoints', (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const storeTimepoints = (timepointData) => {
|
||||
console.log('storeTimepoints');
|
||||
console.log(timepointData);
|
||||
console.log('storeTimepoints');
|
||||
console.log(timepointData);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("storeTimepoints", timepointData, (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call('storeTimepoints', timepointData, (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
import { TimepointsConfiguration } from 'meteor/ohif:measurements/both/configuration/timepoints';
|
||||
const TimepointApi = TimepointsConfiguration.getTimepointsApi();
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Meteor.startup(function() {
|
||||
StudyList.callbacks['dblClickOnStudy'] = dblClickOnStudy;
|
||||
StudyList.callbacks['middleClickOnStudy'] = dblClickOnStudy;
|
||||
|
||||
StudyList.timepointApi = new TimepointApi();
|
||||
StudyList.timepointApi = new OHIF.measurements.TimepointApi();
|
||||
StudyList.timepointApi.retrieveTimepoints();
|
||||
});
|
||||
|
||||
@ -17,7 +16,7 @@ function dblClickOnStudy(data) {
|
||||
let title = formatPN(data.patientName);
|
||||
|
||||
const instance = Template.instance();
|
||||
|
||||
|
||||
// Find the relevant timepoint given the clicked-on study
|
||||
const timepointApi = StudyList.timepointApi;
|
||||
if (!timepointApi) {
|
||||
|
||||
@ -1,109 +1,107 @@
|
||||
let Configuration = {};
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { _ } from 'meteor/underscore';
|
||||
|
||||
function setConfiguration(config) {
|
||||
Configuration = config;
|
||||
}
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
function getConfiguration() {
|
||||
return Configuration;
|
||||
}
|
||||
let configuration = {};
|
||||
|
||||
function getMeasurementsApi() {
|
||||
console.log('OHIF-Measurements: Defining MeasurementApi');
|
||||
const config = Configuration;
|
||||
class MeasurementApi {
|
||||
static setConfiguration(config) {
|
||||
configuration = config;
|
||||
}
|
||||
|
||||
class MeasurementApi {
|
||||
constructor(currentTimepointId) {
|
||||
if (currentTimepointId) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
}
|
||||
}
|
||||
static getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
retrieveMeasurements(timepointId) {
|
||||
if (!timepointId) {
|
||||
timepointId = this.currentTimepointId;
|
||||
}
|
||||
constructor(currentTimepointId, configuration) {
|
||||
if (currentTimepointId) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
}
|
||||
|
||||
const retrievalFn = config.dataExchange.retrieve;
|
||||
if (!_.isFunction(retrievalFn)) {
|
||||
return;
|
||||
}
|
||||
this.config = configuration || MeasurementApi.getConfiguration();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
retrievalFn().then(measurementData => {
|
||||
console.log('Measurement data retrieval');
|
||||
console.log(measurementData);
|
||||
this.config.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
|
||||
Object.keys(measurementData).forEach(measurementTypeId => {
|
||||
const measurements = measurementData[measurementTypeId];
|
||||
this[measurementTypeId] = new Mongo.Collection(null);
|
||||
this[measurementTypeId].attachSchema(tool.schema);
|
||||
});
|
||||
}
|
||||
|
||||
measurements.forEach(measurement => {
|
||||
delete measurement._id;
|
||||
this[measurementTypeId].insert(measurement);
|
||||
})
|
||||
});
|
||||
retrieveMeasurements(timepointId) {
|
||||
if (!timepointId) {
|
||||
timepointId = this.currentTimepointId;
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
const retrievalFn = this.config.dataExchange.retrieve;
|
||||
if (!_.isFunction(retrievalFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
retrievalFn().then(measurementData => {
|
||||
// TODO: implement converter here
|
||||
|
||||
console.log('Measurement data retrieval');
|
||||
console.log(measurementData);
|
||||
|
||||
Object.keys(measurementData).forEach(measurementTypeId => {
|
||||
const measurements = measurementData[measurementTypeId];
|
||||
|
||||
measurements.forEach(measurement => {
|
||||
delete measurement._id;
|
||||
this[measurementTypeId].insert(measurement);
|
||||
});
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
storeMeasurements(timepointId) {
|
||||
const storeFn = config.dataExchange.store;
|
||||
if (!_.isFunction(storeFn)) {
|
||||
return;
|
||||
}
|
||||
storeMeasurements(timepointId) {
|
||||
const storeFn = this.config.dataExchange.store;
|
||||
if (!_.isFunction(storeFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let measurementData = {};
|
||||
config.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
measurementData[measurementTypeId] = this[measurementTypeId].find().fetch();
|
||||
});
|
||||
let measurementData = {};
|
||||
this.config.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
measurementData[measurementTypeId] = this[measurementTypeId].find().fetch();
|
||||
});
|
||||
|
||||
storeFn(measurementData).then(() => {
|
||||
console.log('Measurement storage completed');
|
||||
});
|
||||
}
|
||||
storeFn(measurementData).then(() => {
|
||||
console.log('Measurement storage completed');
|
||||
});
|
||||
}
|
||||
|
||||
validateMeasurements() {
|
||||
const validateFn = config.dataValidation.validateMeasurements;
|
||||
if (validateFn && validateFn instanceof Function) {
|
||||
validateFn();
|
||||
}
|
||||
}
|
||||
validateMeasurements() {
|
||||
const validateFn = this.config.dataValidation.validateMeasurements;
|
||||
if (validateFn && validateFn instanceof Function) {
|
||||
validateFn();
|
||||
}
|
||||
}
|
||||
|
||||
syncMeasurementsAndToolData() {
|
||||
config.measurementTools.forEach(tool => {
|
||||
const measurements = this[tool.id].find().fetch();
|
||||
measurements.forEach(measurement => {
|
||||
syncMeasurementAndToolData(measurement);
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
syncMeasurementsAndToolData() {
|
||||
this.config.measurementTools.forEach(tool => {
|
||||
const measurements = this[tool.id].find().fetch();
|
||||
measurements.forEach(measurement => {
|
||||
syncMeasurementAndToolData(measurement);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
config.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
fetch(measurementTypeId, selector, options) {
|
||||
if (!this[measurementTypeId]) {
|
||||
throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId;
|
||||
}
|
||||
|
||||
MeasurementApi.prototype[measurementTypeId] = new Mongo.Collection(null);
|
||||
MeasurementApi.prototype[measurementTypeId].attachSchema(tool.schema);
|
||||
|
||||
MeasurementApi.prototype.fetch = (measurementTypeId, selector, options) => {
|
||||
if (!this[measurementTypeId]) {
|
||||
throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId;
|
||||
}
|
||||
|
||||
selector = selector || {};
|
||||
options = options || {};
|
||||
return this[measurementTypeId].find(selector, options).fetch();
|
||||
};
|
||||
});
|
||||
|
||||
return MeasurementApi;
|
||||
selector = selector || {};
|
||||
options = options || {};
|
||||
return this[measurementTypeId].find(selector, options).fetch();
|
||||
}
|
||||
}
|
||||
|
||||
export const MeasurementsConfiguration = {
|
||||
setConfiguration: setConfiguration,
|
||||
getConfiguration: getConfiguration,
|
||||
getMeasurementsApi: getMeasurementsApi
|
||||
};
|
||||
OHIF.measurements.MeasurementApi = MeasurementApi;
|
||||
|
||||
@ -1,230 +1,225 @@
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { _ } from 'meteor/underscore';
|
||||
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
import { schema as TimepointSchema } from 'meteor/ohif:measurements/both/schema/timepoints';
|
||||
|
||||
let Configuration = {};
|
||||
|
||||
function setConfiguration(config) {
|
||||
Configuration = config;
|
||||
}
|
||||
|
||||
function getConfiguration() {
|
||||
return Configuration;
|
||||
}
|
||||
|
||||
|
||||
function getTimepointsApi() {
|
||||
console.log('OHIF-Measurements: Defining TimepointsApi');
|
||||
const config = Configuration;
|
||||
|
||||
class TimepointApi {
|
||||
constructor(currentTimepointId) {
|
||||
if (currentTimepointId) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
}
|
||||
}
|
||||
|
||||
retrieveTimepoints() {
|
||||
this.timepoints = new Mongo.Collection(null);
|
||||
this.timepoints.attachSchema(TimepointSchema);
|
||||
this.timepoints._debugName = 'Timepoints';
|
||||
|
||||
const retrievalFn = config.dataExchange.retrieve;
|
||||
if (!_.isFunction(retrievalFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
retrievalFn().then(timepointData => {
|
||||
console.log('Timepoint data retrieval');
|
||||
console.log(timepointData);
|
||||
timepointData.forEach(timepoint => {
|
||||
delete timepoint._id;
|
||||
this.timepoints.insert(timepoint);
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
storeTimepoints() {
|
||||
const storeFn = config.dataExchange.store;
|
||||
if (!_.isFunction(storeFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const timepointData = this.timepoints.find().fetch();
|
||||
console.log('Preparing to store timepoints');
|
||||
console.log(JSON.stringify(timepointData, null, 2));
|
||||
|
||||
storeFn(timepointData).then(() => {
|
||||
console.log('Timepoint storage completed');
|
||||
});
|
||||
}
|
||||
|
||||
// Return all timepoints
|
||||
all() {
|
||||
return this.timepoints.find().fetch();
|
||||
}
|
||||
|
||||
// Return only the current timepoint
|
||||
current() {
|
||||
return this.timepoints.findOne({
|
||||
timepointId: this.currentTimepointId
|
||||
});
|
||||
}
|
||||
|
||||
// Return the prior timepoint
|
||||
lock() {
|
||||
this.timepoints.update(current._id, {
|
||||
$set: {
|
||||
locked: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
prior() {
|
||||
const current = this.current();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const latestDate = current.latestDate;
|
||||
return this.timepoints.findOne({
|
||||
latestDate: {
|
||||
$lt: latestDate
|
||||
}
|
||||
}, {
|
||||
sort: {
|
||||
latestDate: -1
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 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._id !== current._id) {
|
||||
timepoints.push(prior);
|
||||
}
|
||||
|
||||
return timepoints;
|
||||
}
|
||||
|
||||
// Return only the baseline timepoint
|
||||
baseline() {
|
||||
return this.timepoints.findOne({
|
||||
timepointType: 'baseline'
|
||||
});
|
||||
}
|
||||
|
||||
// Return only the key timepoints (current, prior, nadir and baseline)
|
||||
key() {
|
||||
// Create a new Mini Mongo Collection to store the result
|
||||
const result = new Mongo.Collection(null);
|
||||
|
||||
// Get all the timepoints
|
||||
const all = this.all();
|
||||
|
||||
// Iterate over each timepoint and insert the key ones in the result
|
||||
_.each(all, (timepoint, index) => {
|
||||
if (index < 2 || index === (all.length - 1)) {
|
||||
result.insert(timepoint);
|
||||
}
|
||||
});
|
||||
|
||||
// Return the resulting timepoints
|
||||
return result.find().fetch();
|
||||
}
|
||||
|
||||
// Return only the timepoints for the given study
|
||||
study(studyInstanceUid) {
|
||||
// Create a new Mini Mongo Collection to store the result
|
||||
const result = new Mongo.Collection(null);
|
||||
|
||||
// Iterate over each timepoint and insert the key ones in the result
|
||||
_.each(this.all(), (timepoint, index) => {
|
||||
if (_.contains(timepoint.studyInstanceUids, studyInstanceUid)) {
|
||||
result.insert(timepoint);
|
||||
}
|
||||
});
|
||||
|
||||
// Return the resulting timepoints
|
||||
return result.find().fetch();
|
||||
}
|
||||
|
||||
// Return the timepoint's name
|
||||
name(timepoint) {
|
||||
// Check if this is a Baseline timepoint, if it is, return 'Baseline'
|
||||
if (timepoint.timepointType === 'baseline') {
|
||||
return 'Baseline';
|
||||
}
|
||||
|
||||
// Retrieve all of the relevant follow-up timepoints for this patient
|
||||
var followupTimepoints = this.timepoints.find({
|
||||
patientId: timepoint.patientId,
|
||||
timepointType: timepoint.timepointType
|
||||
}, {
|
||||
sort: {
|
||||
latestDate: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Create an array of just timepointIds, so we can use indexOf
|
||||
// on it to find the current timepoint's relative position
|
||||
var followupTimepointIds = followupTimepoints.map(function(timepoint) {
|
||||
return timepoint.timepointId;
|
||||
});
|
||||
|
||||
// Calculate the index of the current timepoint in the array of all
|
||||
// relevant follow-up timepoints
|
||||
var index = followupTimepointIds.indexOf(timepoint.timepointId) + 1;
|
||||
|
||||
// If index is 0, it means that the current timepoint was not in the list
|
||||
// Log a warning and return here
|
||||
if (!index) {
|
||||
log.warn('Current follow-up was not in the list of relevant follow-ups?');
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the timepoint name as 'Follow-up N'
|
||||
return 'Follow-up ' + index;
|
||||
}
|
||||
|
||||
// Build the timepoint title based on its date
|
||||
title(timepoint) {
|
||||
const timepointName = this.name(timepoint);
|
||||
|
||||
const all = this.all();
|
||||
let index = -1;
|
||||
_.each(all, (currentTimepoint, currentIndex) => {
|
||||
if (currentTimepoint.timepointId === timepoint.timepointId) {
|
||||
index = currentIndex;
|
||||
}
|
||||
});
|
||||
|
||||
const states = {
|
||||
0: '(Current)',
|
||||
1: '(Prior)'
|
||||
};
|
||||
// TODO: [design] find out how to define the nadir timepoint
|
||||
const parenthesis = states[index] || '';
|
||||
return `${timepointName} ${parenthesis}`;
|
||||
}
|
||||
let configuration = {};
|
||||
|
||||
class TimepointApi {
|
||||
static setConfiguration(config) {
|
||||
configuration = config;
|
||||
}
|
||||
|
||||
static getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
constructor(currentTimepointId, configuration) {
|
||||
if (currentTimepointId) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
}
|
||||
|
||||
this.config = configuration || MeasurementApi.getConfiguration();
|
||||
}
|
||||
|
||||
retrieveTimepoints() {
|
||||
this.timepoints = new Mongo.Collection(null);
|
||||
this.timepoints.attachSchema(TimepointSchema);
|
||||
this.timepoints._debugName = 'Timepoints';
|
||||
|
||||
const retrievalFn = this.config.dataExchange.retrieve;
|
||||
if (!_.isFunction(retrievalFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
retrievalFn().then(timepointData => {
|
||||
console.log('Timepoint data retrieval');
|
||||
console.log(timepointData);
|
||||
timepointData.forEach(timepoint => {
|
||||
delete timepoint._id;
|
||||
this.timepoints.insert(timepoint);
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
storeTimepoints() {
|
||||
const storeFn = this.config.dataExchange.store;
|
||||
if (!_.isFunction(storeFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const timepointData = this.timepoints.find().fetch();
|
||||
console.log('Preparing to store timepoints');
|
||||
console.log(JSON.stringify(timepointData, null, 2));
|
||||
|
||||
storeFn(timepointData).then(() => {
|
||||
console.log('Timepoint storage completed');
|
||||
});
|
||||
}
|
||||
|
||||
// Return all timepoints
|
||||
all() {
|
||||
return this.timepoints.find().fetch();
|
||||
}
|
||||
|
||||
// Return only the current timepoint
|
||||
current() {
|
||||
return this.timepoints.findOne({
|
||||
timepointId: this.currentTimepointId
|
||||
});
|
||||
}
|
||||
|
||||
// Return the prior timepoint
|
||||
lock() {
|
||||
this.timepoints.update(current._id, {
|
||||
$set: {
|
||||
locked: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
prior() {
|
||||
const current = this.current();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const latestDate = current.latestDate;
|
||||
return this.timepoints.findOne({
|
||||
latestDate: {
|
||||
$lt: latestDate
|
||||
}
|
||||
}, {
|
||||
sort: {
|
||||
latestDate: -1
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 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._id !== current._id) {
|
||||
timepoints.push(prior);
|
||||
}
|
||||
|
||||
return timepoints;
|
||||
}
|
||||
|
||||
// Return only the baseline timepoint
|
||||
baseline() {
|
||||
return this.timepoints.findOne({
|
||||
timepointType: 'baseline'
|
||||
});
|
||||
}
|
||||
|
||||
// Return only the key timepoints (current, prior, nadir and baseline)
|
||||
key() {
|
||||
// Create a new Mini Mongo Collection to store the result
|
||||
const result = new Mongo.Collection(null);
|
||||
|
||||
// Get all the timepoints
|
||||
const all = this.all();
|
||||
|
||||
// Iterate over each timepoint and insert the key ones in the result
|
||||
_.each(all, (timepoint, index) => {
|
||||
if (index < 2 || index === (all.length - 1)) {
|
||||
result.insert(timepoint);
|
||||
}
|
||||
});
|
||||
|
||||
// Return the resulting timepoints
|
||||
return result.find().fetch();
|
||||
}
|
||||
|
||||
// Return only the timepoints for the given study
|
||||
study(studyInstanceUid) {
|
||||
// Create a new Mini Mongo Collection to store the result
|
||||
const result = new Mongo.Collection(null);
|
||||
|
||||
// Iterate over each timepoint and insert the key ones in the result
|
||||
_.each(this.all(), (timepoint, index) => {
|
||||
if (_.contains(timepoint.studyInstanceUids, studyInstanceUid)) {
|
||||
result.insert(timepoint);
|
||||
}
|
||||
});
|
||||
|
||||
// Return the resulting timepoints
|
||||
return result.find().fetch();
|
||||
}
|
||||
|
||||
// Return the timepoint's name
|
||||
name(timepoint) {
|
||||
// Check if this is a Baseline timepoint, if it is, return 'Baseline'
|
||||
if (timepoint.timepointType === 'baseline') {
|
||||
return 'Baseline';
|
||||
}
|
||||
|
||||
// Retrieve all of the relevant follow-up timepoints for this patient
|
||||
var followupTimepoints = this.timepoints.find({
|
||||
patientId: timepoint.patientId,
|
||||
timepointType: timepoint.timepointType
|
||||
}, {
|
||||
sort: {
|
||||
latestDate: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Create an array of just timepointIds, so we can use indexOf
|
||||
// on it to find the current timepoint's relative position
|
||||
var followupTimepointIds = followupTimepoints.map(function(timepoint) {
|
||||
return timepoint.timepointId;
|
||||
});
|
||||
|
||||
// Calculate the index of the current timepoint in the array of all
|
||||
// relevant follow-up timepoints
|
||||
var index = followupTimepointIds.indexOf(timepoint.timepointId) + 1;
|
||||
|
||||
// If index is 0, it means that the current timepoint was not in the list
|
||||
// Log a warning and return here
|
||||
if (!index) {
|
||||
log.warn('Current follow-up was not in the list of relevant follow-ups?');
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the timepoint name as 'Follow-up N'
|
||||
return 'Follow-up ' + index;
|
||||
}
|
||||
|
||||
// Build the timepoint title based on its date
|
||||
title(timepoint) {
|
||||
const timepointName = this.name(timepoint);
|
||||
|
||||
const all = this.all();
|
||||
let index = -1;
|
||||
_.each(all, (currentTimepoint, currentIndex) => {
|
||||
if (currentTimepoint.timepointId === timepoint.timepointId) {
|
||||
index = currentIndex;
|
||||
}
|
||||
});
|
||||
|
||||
const states = {
|
||||
0: '(Current)',
|
||||
1: '(Prior)'
|
||||
};
|
||||
// TODO: [design] find out how to define the nadir timepoint
|
||||
const parenthesis = states[index] || '';
|
||||
return `${timepointName} ${parenthesis}`;
|
||||
}
|
||||
|
||||
return TimepointApi;
|
||||
}
|
||||
|
||||
export const TimepointsConfiguration = {
|
||||
setConfiguration: setConfiguration,
|
||||
getConfiguration: getConfiguration,
|
||||
getTimepointsApi: getTimepointsApi
|
||||
};
|
||||
OHIF.measurements.TimepointApi = TimepointApi;
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
|
||||
Template.caseProgress.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.measurementTableTimepointCell.helpers({
|
||||
hasDataAtThisTimepoint() {
|
||||
@ -9,14 +9,14 @@ Template.measurementTableTimepointCell.helpers({
|
||||
|
||||
if (this.timepointId) {
|
||||
const dataAtThisTimepoint = _.where(rowItem.entries, {timepointId: this.timepointId});
|
||||
return dataAtThisTimepoint.length > 0;
|
||||
return dataAtThisTimepoint.length > 0;
|
||||
} else {
|
||||
return rowItem.entries.length > 0;
|
||||
}
|
||||
},
|
||||
displayData() {
|
||||
const instance = Template.instance();
|
||||
|
||||
|
||||
const rowItem = instance.data.rowItem;
|
||||
let data;
|
||||
if (this.timepointId) {
|
||||
@ -29,7 +29,7 @@ Template.measurementTableTimepointCell.helpers({
|
||||
data = rowItem.entries[0];
|
||||
}
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const measurementTools = config.measurementTools;
|
||||
|
||||
const tool = _.where(measurementTools, {id: rowItem.measurementTypeId})[0];
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.measurementTableView.helpers({
|
||||
isFollowup() {
|
||||
@ -11,7 +11,7 @@ Template.measurementTableView.helpers({
|
||||
const api = Template.instance().data.measurementApi;
|
||||
const Collection = api[measurementTypeId];
|
||||
const data = Collection.find().fetch();
|
||||
|
||||
|
||||
const groupObject = _.groupBy(data, entry => { return entry.measurementNumber });
|
||||
|
||||
return Object.keys(groupObject).map(key => {
|
||||
@ -33,7 +33,7 @@ Template.measurementTableView.helpers({
|
||||
|
||||
const api = instance.data.measurementApi;
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const measurementTools = config.measurementTools;
|
||||
|
||||
// If this is a baseline, stop here since there are no new measurements to display
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.registerHelper('measurementConfiguration', () => {
|
||||
//console.log('helper:measurementTools');
|
||||
if (!MeasurementsConfiguration) {
|
||||
if (!OHIF.measurements.MeasurementApi) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
return config;
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { MeasurementManager } from 'meteor/ohif:measurements/client/lib/MeasurementManager';
|
||||
|
||||
let MeasurementHandlers = {};
|
||||
@ -6,7 +6,7 @@ let MeasurementHandlers = {};
|
||||
MeasurementHandlers.onAdded = (e, instance, eventData) => {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
@ -63,7 +63,7 @@ MeasurementHandlers.onAdded = (e, instance, eventData) => {
|
||||
const numCurrentMeasurementsInStudy = Collection.find({
|
||||
studyInstanceUid: study.studyInstanceUid
|
||||
}).count();
|
||||
measurement.measurementNumber = numCurrentMeasurementsInStudy + 1;
|
||||
measurement.measurementNumber = numCurrentMeasurementsInStudy + 1;
|
||||
}
|
||||
|
||||
// Clean the measurement according to the Schema
|
||||
@ -76,7 +76,7 @@ MeasurementHandlers.onAdded = (e, instance, eventData) => {
|
||||
MeasurementHandlers.onModified = (e, instance, eventData) => {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
const config = MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
@ -131,7 +131,7 @@ MeasurementHandlers.onModified = (e, instance, eventData) => {
|
||||
MeasurementHandlers.onRemoved = (e, instance, eventData) => {
|
||||
const measurementData = eventData.measurementData;
|
||||
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
@ -150,4 +150,4 @@ MeasurementHandlers.onRemoved = (e, instance, eventData) => {
|
||||
Collection.remove(measurementData.id);
|
||||
};
|
||||
|
||||
export { MeasurementHandlers };
|
||||
export { MeasurementHandlers };
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
export clearTools = () => {
|
||||
const config = MeasurementsConfiguration.getConfiguration();
|
||||
export const clearTools = () => {
|
||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||
const toolTypes = config.measurementTools.map(tool => {
|
||||
return tool.cornerstoneToolType;
|
||||
});
|
||||
@ -20,7 +20,7 @@ export clearTools = () => {
|
||||
if (!series) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
seriesInstanceUids.push(series.seriesInstanceUid);
|
||||
});
|
||||
|
||||
@ -39,7 +39,6 @@ export clearTools = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (seriesInstanceUids.indexOf(series.seriesInstanceUid) === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -116,6 +116,4 @@ Package.onUse(function(api) {
|
||||
api.addFiles('client/lib/getTimepointObject.js', 'client');
|
||||
|
||||
api.export('MeasurementSchemaTypes', ['client', 'server']);
|
||||
api.export('MeasurementsConfiguration', ['client', 'server']);
|
||||
api.export('TimepointsConfiguration', ['client', 'server']);
|
||||
});
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
import { measurementTools } from './measurementTools';
|
||||
import { retrieveMeasurements, storeMeasurements } from './dataExchange';
|
||||
import { validateMeasurements } from './dataValidation';
|
||||
|
||||
import { MeasurementsConfiguration } from 'meteor/ohif:measurements/both/configuration/measurements';
|
||||
|
||||
console.log('OHIF-PET SUV: Defining Configuration for Measurements');
|
||||
MeasurementsConfiguration.setConfiguration({
|
||||
measurementTools: measurementTools,
|
||||
dataExchange: {
|
||||
retrieve: retrieveMeasurements,
|
||||
store: storeMeasurements
|
||||
},
|
||||
dataValidation: {
|
||||
validation: validateMeasurements
|
||||
}
|
||||
});
|
||||
OHIF.measurements.MeasurementApi.setConfiguration({
|
||||
measurementTools: measurementTools,
|
||||
dataExchange: {
|
||||
retrieve: retrieveMeasurements,
|
||||
store: storeMeasurements
|
||||
},
|
||||
dataValidation: {
|
||||
validation: validateMeasurements
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user