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,10 +1,9 @@
|
||||
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 = {
|
||||
@ -12,7 +11,7 @@ const newMeasurementTool = {
|
||||
name: 'New Lesions'
|
||||
};
|
||||
|
||||
MeasurementsConfiguration.setConfiguration({
|
||||
OHIF.measurements.MeasurementApi.setConfiguration({
|
||||
measurementTools: measurementTools,
|
||||
newMeasurementTool: newMeasurementTool,
|
||||
dataExchange: {
|
||||
@ -24,7 +23,7 @@ MeasurementsConfiguration.setConfiguration({
|
||||
}
|
||||
});
|
||||
|
||||
TimepointsConfiguration.setConfiguration({
|
||||
OHIF.measurements.TimepointApi.setConfiguration({
|
||||
dataExchange: {
|
||||
retrieve: retrieveTimepoints,
|
||||
store: storeTimepoints
|
||||
|
||||
@ -4,7 +4,7 @@ export const retrieveMeasurements = () => {
|
||||
console.log('retrieveMeasurements');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("retrieveMeasurements", (error, response) => {
|
||||
Meteor.call('retrieveMeasurements', (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
@ -26,7 +26,7 @@ export const storeMeasurements = (measurementData) => {
|
||||
// Here is where we should do any required data transformation and API calls
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("storeMeasurements", measurementData, (error, response) => {
|
||||
Meteor.call('storeMeasurements', measurementData, (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
@ -40,7 +40,7 @@ export const retrieveTimepoints = () => {
|
||||
console.log('retrieveTimepoints');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("retrieveTimepoints", (error, response) => {
|
||||
Meteor.call('retrieveTimepoints', (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
@ -55,7 +55,7 @@ export const storeTimepoints = (timepointData) => {
|
||||
console.log(timepointData);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.call("storeTimepoints", timepointData, (error, response) => {
|
||||
Meteor.call('storeTimepoints', timepointData, (error, response) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
|
||||
@ -1,22 +1,32 @@
|
||||
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) {
|
||||
static getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
constructor(currentTimepointId, configuration) {
|
||||
if (currentTimepointId) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
}
|
||||
|
||||
this.config = configuration || MeasurementApi.getConfiguration();
|
||||
|
||||
this.config.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
|
||||
this[measurementTypeId] = new Mongo.Collection(null);
|
||||
this[measurementTypeId].attachSchema(tool.schema);
|
||||
});
|
||||
}
|
||||
|
||||
retrieveMeasurements(timepointId) {
|
||||
@ -24,13 +34,15 @@ function getMeasurementsApi() {
|
||||
timepointId = this.currentTimepointId;
|
||||
}
|
||||
|
||||
const retrievalFn = config.dataExchange.retrieve;
|
||||
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);
|
||||
|
||||
@ -40,7 +52,7 @@ function getMeasurementsApi() {
|
||||
measurements.forEach(measurement => {
|
||||
delete measurement._id;
|
||||
this[measurementTypeId].insert(measurement);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
resolve();
|
||||
@ -49,13 +61,13 @@ function getMeasurementsApi() {
|
||||
}
|
||||
|
||||
storeMeasurements(timepointId) {
|
||||
const storeFn = config.dataExchange.store;
|
||||
const storeFn = this.config.dataExchange.store;
|
||||
if (!_.isFunction(storeFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let measurementData = {};
|
||||
config.measurementTools.forEach(tool => {
|
||||
this.config.measurementTools.forEach(tool => {
|
||||
const measurementTypeId = tool.id;
|
||||
measurementData[measurementTypeId] = this[measurementTypeId].find().fetch();
|
||||
});
|
||||
@ -66,29 +78,22 @@ function getMeasurementsApi() {
|
||||
}
|
||||
|
||||
validateMeasurements() {
|
||||
const validateFn = config.dataValidation.validateMeasurements;
|
||||
const validateFn = this.config.dataValidation.validateMeasurements;
|
||||
if (validateFn && validateFn instanceof Function) {
|
||||
validateFn();
|
||||
}
|
||||
}
|
||||
|
||||
syncMeasurementsAndToolData() {
|
||||
config.measurementTools.forEach(tool => {
|
||||
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;
|
||||
|
||||
MeasurementApi.prototype[measurementTypeId] = new Mongo.Collection(null);
|
||||
MeasurementApi.prototype[measurementTypeId].attachSchema(tool.schema);
|
||||
|
||||
MeasurementApi.prototype.fetch = (measurementTypeId, selector, options) => {
|
||||
fetch(measurementTypeId, selector, options) {
|
||||
if (!this[measurementTypeId]) {
|
||||
throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId;
|
||||
}
|
||||
@ -96,14 +101,7 @@ function getMeasurementsApi() {
|
||||
selector = selector || {};
|
||||
options = options || {};
|
||||
return this[measurementTypeId].find(selector, options).fetch();
|
||||
};
|
||||
});
|
||||
|
||||
return MeasurementApi;
|
||||
}
|
||||
}
|
||||
|
||||
export const MeasurementsConfiguration = {
|
||||
setConfiguration: setConfiguration,
|
||||
getConfiguration: getConfiguration,
|
||||
getMeasurementsApi: getMeasurementsApi
|
||||
};
|
||||
OHIF.measurements.MeasurementApi = MeasurementApi;
|
||||
|
||||
@ -1,25 +1,27 @@
|
||||
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 = {};
|
||||
let configuration = {};
|
||||
|
||||
function setConfiguration(config) {
|
||||
Configuration = config;
|
||||
}
|
||||
class TimepointApi {
|
||||
static setConfiguration(config) {
|
||||
configuration = config;
|
||||
}
|
||||
|
||||
function getConfiguration() {
|
||||
return Configuration;
|
||||
}
|
||||
static getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
||||
function getTimepointsApi() {
|
||||
console.log('OHIF-Measurements: Defining TimepointsApi');
|
||||
const config = Configuration;
|
||||
|
||||
class TimepointApi {
|
||||
constructor(currentTimepointId) {
|
||||
constructor(currentTimepointId, configuration) {
|
||||
if (currentTimepointId) {
|
||||
this.currentTimepointId = currentTimepointId;
|
||||
}
|
||||
|
||||
this.config = configuration || MeasurementApi.getConfiguration();
|
||||
}
|
||||
|
||||
retrieveTimepoints() {
|
||||
@ -27,7 +29,7 @@ function getTimepointsApi() {
|
||||
this.timepoints.attachSchema(TimepointSchema);
|
||||
this.timepoints._debugName = 'Timepoints';
|
||||
|
||||
const retrievalFn = config.dataExchange.retrieve;
|
||||
const retrievalFn = this.config.dataExchange.retrieve;
|
||||
if (!_.isFunction(retrievalFn)) {
|
||||
return;
|
||||
}
|
||||
@ -47,7 +49,7 @@ function getTimepointsApi() {
|
||||
}
|
||||
|
||||
storeTimepoints() {
|
||||
const storeFn = config.dataExchange.store;
|
||||
const storeFn = this.config.dataExchange.store;
|
||||
if (!_.isFunction(storeFn)) {
|
||||
return;
|
||||
}
|
||||
@ -218,13 +220,6 @@ function getTimepointsApi() {
|
||||
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() {
|
||||
@ -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() {
|
||||
@ -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;
|
||||
});
|
||||
@ -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;
|
||||
});
|
||||
|
||||
@ -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;
|
||||
});
|
||||
@ -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,11 +1,11 @@
|
||||
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({
|
||||
OHIF.measurements.MeasurementApi.setConfiguration({
|
||||
measurementTools: measurementTools,
|
||||
dataExchange: {
|
||||
retrieve: retrieveMeasurements,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user