Building the viewer data inside routes
This commit is contained in:
1 parent
7718d31a77
commit
9ccebb76bd
9 files changed
+193
-94
No files matched your search
@@ -92,6 +92,14 @@ Viewerbase.imageViewerViewportData = imageViewerViewportData;
|
||||
import { panelNavigation } from './lib/panelNavigation';
|
||||
Viewerbase.panelNavigation = panelNavigation;
|
||||
|
||||
// prepareViewerData
|
||||
import { prepareViewerData } from './lib/prepareViewerData';
|
||||
Viewerbase.prepareViewerData = prepareViewerData;
|
||||
|
||||
// renderViewer
|
||||
import { renderViewer } from './lib/renderViewer';
|
||||
Viewerbase.renderViewer = renderViewer;
|
||||
|
||||
// WLPresets.*
|
||||
import { WLPresets } from './lib/WLPresets';
|
||||
Viewerbase.wlPresets = WLPresets;
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
/**
|
||||
* Prepare the studies data to render the viewer template
|
||||
*
|
||||
* @param {Array} studyInstanceUids List of studies that will be loaded into viewer
|
||||
* @param {String} timepointId ID of the current timepoint to get the studies from
|
||||
* @param {Object} timepointsFilter An object containing the filter to retrieve the timepoints
|
||||
* @return {Promise} Promise that will be resolved with the studies when the metadata is loaded
|
||||
*/
|
||||
export const prepareViewerData = ({ studyInstanceUids, timepointId, timepointsFilter={} }) => {
|
||||
// Clear the cornerstone tool data to sync the measurements with the measurements API
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager = cornerstoneTools.newImageIdSpecificToolStateManager();
|
||||
|
||||
// Retrieve the studies metadata
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const processData = viewerData => {
|
||||
OHIF.studylist.retrieveStudiesMetadata(viewerData.studyInstanceUids).then(studies => {
|
||||
// Add additional metadata to our study from the studylist
|
||||
studies.forEach(study => {
|
||||
const studylistStudy = OHIF.studylist.collections.Studies.findOne({
|
||||
studyInstanceUid: study.studyInstanceUid
|
||||
});
|
||||
|
||||
if (!studylistStudy) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.assign(study, studylistStudy);
|
||||
});
|
||||
|
||||
resolve({
|
||||
studies,
|
||||
viewerData
|
||||
});
|
||||
}).catch(reject);
|
||||
};
|
||||
|
||||
// Check if the studies are already given and ignore the timepoint ID if so
|
||||
if (studyInstanceUids && studyInstanceUids.length) {
|
||||
const viewerData = { studyInstanceUids };
|
||||
processData(viewerData);
|
||||
} else {
|
||||
// Find the timepoint by ID and load the studies from it
|
||||
OHIF.studylist.timepointApi.retrieveTimepoints(timepointsFilter).then(() => {
|
||||
const viewerData = buildViewerDataFromTimepointId(timepointId);
|
||||
processData(viewerData);
|
||||
}).catch(reject);
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
const buildViewerDataFromTimepointId = timepointId => {
|
||||
const timepoint = OHIF.studylist.timepointApi.timepoints.findOne({ timepointId });
|
||||
if (!timepoint) {
|
||||
throw new Error('Unable to find a time point with the given ID');
|
||||
}
|
||||
|
||||
// Get the relevant studyInstanceUids given the timepoints
|
||||
const data = getDataFromTimepoint(timepoint);
|
||||
if (!data.studyInstanceUids) {
|
||||
throw new Error('No studies found that are related to this timepoint');
|
||||
}
|
||||
|
||||
// Build the viewer data and return it
|
||||
return Object.assign(data, { currentTimepointId: timepointId });
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves related studies given a Baseline or Follow-up Timepoint
|
||||
*
|
||||
* @param {Object} timepoint A document from the Timepoints Collection
|
||||
* @returns {Object} An object containing the related studies UIDs and timepoint IDs
|
||||
*/
|
||||
const getDataFromTimepoint = timepoint => {
|
||||
let relatedStudies = timepoint.studyInstanceUids;
|
||||
|
||||
// If this is the baseline, we should stop here and return the relevant studies
|
||||
if (isBaseline(timepoint)) {
|
||||
return {
|
||||
studyInstanceUids: relatedStudies,
|
||||
timepointIds: [timepoint.timepointId]
|
||||
};
|
||||
}
|
||||
|
||||
// Otherwise, this is a follow-up exam, so we should also find the baseline timepoint,
|
||||
// and all studies related to it. We also enforce that the Baseline should have a studyDate
|
||||
// prior to the latest studyDate in the current (Follow-up) Timepoint.
|
||||
const Timepoints = OHIF.studylist.timepointApi.timepoints;
|
||||
const baseline = Timepoints.findOne({
|
||||
timepointType: 'baseline',
|
||||
patientId: timepoint.patientId,
|
||||
latestDate: {
|
||||
$lte: timepoint.latestDate
|
||||
}
|
||||
});
|
||||
|
||||
let timepointIds = [];
|
||||
if (baseline) {
|
||||
relatedStudies = relatedStudies.concat(baseline.studyInstanceUids);
|
||||
timepointIds.push(baseline.timepointId);
|
||||
} else {
|
||||
OHIF.log.warn('No Baseline found while opening a Follow-up Timepoint');
|
||||
}
|
||||
|
||||
timepointIds.push(timepoint.timepointId);
|
||||
|
||||
return {
|
||||
studyInstanceUids: relatedStudies,
|
||||
timepointIds: timepointIds
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a Timepoints is a baseline or not
|
||||
*
|
||||
* @param {Object} timepoint A document from the Timepoints Collection
|
||||
* @returns {boolean} Whether or not the timepoint is stored as a Baseline
|
||||
*/
|
||||
const isBaseline = timepoint => timepoint.timepointType === 'baseline';
|
||||
@@ -0,0 +1,26 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
/**
|
||||
* Render the viewer with the given routing context and parameters
|
||||
*
|
||||
* @param {Context} context Context of the router
|
||||
* @param {Object} params Parameters that will be used to prepare the viewer data
|
||||
*/
|
||||
export const renderViewer = (context, params) => {
|
||||
// Wait until the viewer data is ready to render it
|
||||
const promise = OHIF.viewerbase.prepareViewerData(params);
|
||||
|
||||
// Show loading state while preparing the viewer data
|
||||
OHIF.ui.showDialog('dialogLoading', { promise });
|
||||
|
||||
// Render the viewer when the data is ready
|
||||
promise.then(({ studies, viewerData }) => {
|
||||
context.render('app', {
|
||||
data: {
|
||||
template: 'viewer',
|
||||
studies,
|
||||
viewerData
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user