From 956e6da0b3d1ef82f48e742e4a9271d47500cbe3 Mon Sep 17 00:00:00 2001 From: Bruno Alves de Faria Date: Fri, 6 Oct 2017 08:22:08 -0300 Subject: [PATCH] Preventing all timepoint studies from being loaded at once --- .../both/configuration/timepoints.js | 14 +++--- .../both/schema/timepoints.js | 31 ++++++++++++ .../client/lib/retrieveStudiesMetadata.js | 16 +++--- .../client/lib/prepareViewerData.js | 50 +++++++++++-------- 4 files changed, 74 insertions(+), 37 deletions(-) diff --git a/Packages/ohif-measurements/both/configuration/timepoints.js b/Packages/ohif-measurements/both/configuration/timepoints.js index b176e99fd..90dc89fc7 100644 --- a/Packages/ohif-measurements/both/configuration/timepoints.js +++ b/Packages/ohif-measurements/both/configuration/timepoints.js @@ -193,8 +193,7 @@ class TimepointApi { // 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); + const result = []; // Get all the timepoints const all = this.all(); @@ -202,28 +201,27 @@ class TimepointApi { // 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); + result.push(timepoint); } }); // Return the resulting timepoints - return result.find().fetch(); + return result; } // 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); + const result = []; // 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); + result.push(timepoint); } }); // Return the resulting timepoints - return result.find().fetch(); + return result; } // Return the timepoint's name diff --git a/Packages/ohif-measurements/both/schema/timepoints.js b/Packages/ohif-measurements/both/schema/timepoints.js index 41ea0f233..627bb6fbf 100644 --- a/Packages/ohif-measurements/both/schema/timepoints.js +++ b/Packages/ohif-measurements/both/schema/timepoints.js @@ -1,5 +1,31 @@ import { SimpleSchema } from 'meteor/aldeed:simple-schema'; +const StudiesData = new SimpleSchema({ + studyInstanceUid: { + type: String, + label: 'Study Instance Uid' + }, + description: { + type: String, + label: 'Study Description', + optional: true + }, + date: { + type: Date, + label: 'Study Date' + }, + modality: { + type: String, + label: 'Study Modality' + }, + loaded: { + type: Boolean, + label: 'Defines if the Study is already loaded', + optional: true, + defaultValue: false + } +}); + export const schema = new SimpleSchema({ patientId: { type: String, @@ -36,5 +62,10 @@ export const schema = new SimpleSchema({ type: Number, label: 'Number of patient\'s visit', optional: true + }, + studiesData: { + type: [StudiesData], + label: 'Studies minimal data to allow lazy loading', + optional: true } }); diff --git a/Packages/ohif-study-list/client/lib/retrieveStudiesMetadata.js b/Packages/ohif-study-list/client/lib/retrieveStudiesMetadata.js index d1c390dc6..86f68751a 100644 --- a/Packages/ohif-study-list/client/lib/retrieveStudiesMetadata.js +++ b/Packages/ohif-study-list/client/lib/retrieveStudiesMetadata.js @@ -10,14 +10,14 @@ import { OHIF } from 'meteor/ohif:core'; * @return Promise */ OHIF.studylist.retrieveStudiesMetadata = (studyInstanceUids, seriesInstanceUids, doneCallback, failCallback) => { - // Check to make sure studyInstanceUids were actually input - if (!studyInstanceUids || !studyInstanceUids.length) { - if (failCallback && typeof failCallback === 'function') { - failCallback('No studyInstanceUids were input'); - } - - return; - } + // // Check to make sure studyInstanceUids were actually input + // if (!studyInstanceUids || !studyInstanceUids.length) { + // if (failCallback && typeof failCallback === 'function') { + // failCallback('No studyInstanceUids were input'); + // } + // + // return; + // } // Create an empty array to store the Promises for each metaData retrieval call const promises = []; diff --git a/Packages/ohif-viewerbase/client/lib/prepareViewerData.js b/Packages/ohif-viewerbase/client/lib/prepareViewerData.js index 7252ebf3a..c8ac2384a 100644 --- a/Packages/ohif-viewerbase/client/lib/prepareViewerData.js +++ b/Packages/ohif-viewerbase/client/lib/prepareViewerData.js @@ -1,3 +1,4 @@ +import { _ } from 'meteor/underscore'; import { OHIF } from 'meteor/ohif:core'; /** @@ -9,32 +10,37 @@ import { OHIF } from 'meteor/ohif:core'; * @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, seriesInstanceUids, timepointId, timepointsFilter={}}) => { +export const prepareViewerData = ({ studyInstanceUids, seriesInstanceUids, timepointId, timepointsFilter={} }) => { // Clear the cornerstone tool data to sync the measurements with the measurements API cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState({}); // Retrieve the studies metadata const promise = new Promise((resolve, reject) => { const processData = viewerData => { - OHIF.studylist.retrieveStudiesMetadata(viewerData.studyInstanceUids, viewerData.seriesInstanceUids).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); + const studies = []; + resolve({ + studies, + viewerData + }); + // OHIF.studylist.retrieveStudiesMetadata(viewerData.studyInstanceUids, viewerData.seriesInstanceUids).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 @@ -79,7 +85,7 @@ const buildViewerDataFromTimepointId = timepointId => { * @returns {Object} An object containing the related studies UIDs and timepoint IDs */ const getDataFromTimepoint = timepoint => { - let relatedStudies = timepoint.studyInstanceUids; + let relatedStudies = _.clone(timepoint.studyInstanceUids); // If this is the baseline, we should stop here and return the relevant studies if (isBaseline(timepoint)) { @@ -117,6 +123,8 @@ const getDataFromTimepoint = timepoint => { timepointIds.push(prior.timepointId); } + relatedStudies = _.uniq(relatedStudies); + timepointIds.push(timepoint.timepointId); return {