[WIP] Moving ViewerStudies collection to TypeSafeCollection implementation + Fixing sorting bug in findAllBy method in TypeSafeCollection
This commit is contained in:
1 parent
a4e7aa86ab
commit
d25141f336
18 files changed
+143
-77
No files matched your search
@@ -1,8 +1,12 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from '../namespace';
|
||||
import { TypeSafeCollection } from './lib/classes/TypeSafeCollection';
|
||||
|
||||
Studies = new TypeSafeCollection();
|
||||
// Create main Studies collection which will be used across the entire viewer...
|
||||
const Studies = new TypeSafeCollection();
|
||||
|
||||
ViewerStudies = new Meteor.Collection(null);
|
||||
ViewerStudies._debugName = 'ViewerStudies';
|
||||
// Make it publicly available on "OHIF.viewer" namespace...
|
||||
OHIF.viewer.Studies = Studies;
|
||||
|
||||
// Subscriptions...
|
||||
Meteor.subscribe('studyImportStatus');
|
||||
+6
-1
@@ -1,6 +1,11 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.studyBrowser.helpers({
|
||||
studies() {
|
||||
return ViewerStudies.find({
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
return OHIF.viewer.Studies.findAllBy({
|
||||
selected: true
|
||||
});
|
||||
}
|
||||
|
||||
+6
-9
@@ -585,14 +585,9 @@ Template.imageViewerViewport.onRendered(function() {
|
||||
return;
|
||||
}
|
||||
|
||||
// @TODO: Reconcile ViewerStudies and Studies Collection.
|
||||
// const study = Studies.findBy({ studyInstanceUid });
|
||||
|
||||
// Look through the ViewerStudies collection for a
|
||||
// study with this studyInstanceUid
|
||||
const study = ViewerStudies.findOne({
|
||||
studyInstanceUid: this.data.studyInstanceUid
|
||||
});
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
const study = OHIF.viewer.Studies.findBy({ studyInstanceUid });
|
||||
|
||||
data.study = study;
|
||||
setDisplaySet(data, displaySetInstanceUid, templateData);
|
||||
@@ -669,7 +664,9 @@ Template.imageViewerViewport.events({
|
||||
// Set the active viewport as the previous zoomed viewport
|
||||
viewportIndexToZoom = layoutManager.zoomedViewportIndex || 0;
|
||||
}
|
||||
setActiveViewport($('.imageViewerViewport').get(viewportIndexToZoom));
|
||||
// Set zoomed viewport as active...
|
||||
const element = $('.imageViewerViewport').get(viewportIndexToZoom);
|
||||
setActiveViewport(element);
|
||||
});
|
||||
}
|
||||
});
|
||||
+5
-3
@@ -4,7 +4,6 @@ import { Session } from 'meteor/session';
|
||||
import { $ } from 'meteor/jquery';
|
||||
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import 'meteor/ohif:viewerbase';
|
||||
|
||||
Template.studySeriesQuickSwitch.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
@@ -29,13 +28,16 @@ Template.studySeriesQuickSwitch.onCreated(() => {
|
||||
|
||||
const viewportData = instance.getViewportData(viewportIndex);
|
||||
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
|
||||
if (viewportData) {
|
||||
// Finds the current study and return it
|
||||
instance.study = ViewerStudies.findOne({
|
||||
instance.study = OHIF.viewer.Studies.findBy({
|
||||
studyInstanceUid: viewportData.studyInstanceUid
|
||||
});
|
||||
} else {
|
||||
instance.study = ViewerStudies.findOne();
|
||||
instance.study = OHIF.viewer.Studies.getElementByIndex(0);
|
||||
}
|
||||
|
||||
if (!instance.study) {
|
||||
|
||||
+5
-1
@@ -1,4 +1,5 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.studyTimepoint.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
@@ -39,9 +40,12 @@ Template.studyTimepoint.events({
|
||||
// Defines where will be the studies searched
|
||||
let $studiesTarget = instance.$('.studyTimepoint');
|
||||
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
|
||||
if (changed.isQuickSwitch) {
|
||||
// Changes the current quick switch study
|
||||
const study = ViewerStudies.findOne({
|
||||
const study = OHIF.viewer.Studies.findBy({
|
||||
studyInstanceUid: changed.studyInstanceUid
|
||||
});
|
||||
instance.data.currentStudy.set(study);
|
||||
|
||||
+6
-3
@@ -2,7 +2,7 @@ import { Template } from 'meteor/templating';
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import { _ } from 'meteor/underscore';
|
||||
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { OHIFError } from '../../../lib/classes/OHIFError';
|
||||
|
||||
Template.studyTimepointBrowser.onCreated(() => {
|
||||
@@ -21,8 +21,11 @@ Template.studyTimepointBrowser.onCreated(() => {
|
||||
|
||||
// Get the studies for a specific timepoint
|
||||
instance.getStudies = timepoint => {
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
|
||||
if (!timepoint) {
|
||||
return ViewerStudies.find().fetch();
|
||||
return OHIF.viewer.Studies.all();
|
||||
}
|
||||
|
||||
return timepoint.studyInstanceUids.map(studyInstanceUid => {
|
||||
@@ -31,7 +34,7 @@ Template.studyTimepointBrowser.onCreated(() => {
|
||||
studyInstanceUid: studyInstanceUid
|
||||
};
|
||||
|
||||
const loadedStudy = ViewerStudies.findOne(query);
|
||||
const loadedStudy = OHIF.viewer.Studies.findBy(query);
|
||||
if (loadedStudy) {
|
||||
return loadedStudy;
|
||||
}
|
||||
|
||||
+11
-8
@@ -3,6 +3,7 @@ import { Template } from 'meteor/templating';
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { sortingManager } from '../../../lib/sortingManager';
|
||||
|
||||
Template.studyTimepointStudy.onCreated(() => {
|
||||
@@ -97,10 +98,12 @@ Template.studyTimepointStudy.events({
|
||||
|
||||
const isQuickSwitch = !_.isUndefined(instance.data.viewportIndex);
|
||||
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
// Check if the study already has series data,
|
||||
// and if not, retrieve it.
|
||||
if (!studyData.seriesList) {
|
||||
const alreadyLoaded = ViewerStudies.findOne({ _id });
|
||||
const alreadyLoaded = OHIF.viewer.Studies.findBy({ studyInstanceUid });
|
||||
|
||||
if (!alreadyLoaded) {
|
||||
const $studies = instance.getStudyElement(true);
|
||||
@@ -108,12 +111,10 @@ Template.studyTimepointStudy.events({
|
||||
getStudyMetadata(studyInstanceUid, study => {
|
||||
study.displaySets = sortingManager.getDisplaySets(study);
|
||||
instance.data.study = study;
|
||||
ViewerStudies.insert(study, () => {
|
||||
// To make sure studies are rendered in the DOM
|
||||
// use minimongo insert callback
|
||||
$studies.trigger('loadEnded');
|
||||
instance.select(isQuickSwitch);
|
||||
});
|
||||
OHIF.viewer.Studies.insert(study);
|
||||
// make sure studies are rendered in the DOM
|
||||
$studies.trigger('loadEnded');
|
||||
instance.select(isQuickSwitch);
|
||||
});
|
||||
} else {
|
||||
studyData.seriesList = alreadyLoaded.seriesList;
|
||||
@@ -126,9 +127,11 @@ Template.studyTimepointStudy.events({
|
||||
|
||||
Template.studyTimepointStudy.helpers({
|
||||
isLoading() {
|
||||
// @TypeSafeStudies
|
||||
debugger;
|
||||
const instance = Template.instance();
|
||||
const studyData = instance.data.study;
|
||||
const alreadyLoaded = ViewerStudies.findOne({ _id: studyData._id });
|
||||
const alreadyLoaded = OHIF.viewer.Studies.findBy({ studyInstanceUid: studyData.studyInstanceUid });
|
||||
return instance.loading.get() && !alreadyLoaded;
|
||||
},
|
||||
modalities() {
|
||||
|
||||
+7
-4
@@ -1,5 +1,6 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
import { Session } from 'meteor/session';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { viewportOverlayUtils } from '../../../lib/viewportOverlayUtils';
|
||||
import { getElementIfNotEmpty } from '../../../lib/getElementIfNotEmpty';
|
||||
import { getStackDataIfNotEmpty } from '../../../lib/getStackDataIfNotEmpty';
|
||||
@@ -217,17 +218,19 @@ Template.viewportOverlay.helpers({
|
||||
return;
|
||||
}
|
||||
|
||||
// @TypeSafeStudies
|
||||
debugger
|
||||
// Make sure there are more than two studies loaded in the viewer
|
||||
const viewportStudies = ViewerStudies.find();
|
||||
if (viewportStudies.count() < 2) {
|
||||
const viewportStudies = OHIF.viewer.Studies.all();
|
||||
if (viewportStudies.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Here we sort the collection in ascending order by study date, so
|
||||
// that we can obtain the oldest study as the first element of the array
|
||||
//
|
||||
// TODO= Find out if we should encode studyDate as a Date in the ViewerStudies Collection
|
||||
const viewportStudiesArray = _.sortBy(viewportStudies.fetch(), function(study) {
|
||||
// TODO= Find out if we should encode studyDate as a Date in the OHIF.viewer.Studies Collection
|
||||
const viewportStudiesArray = _.sortBy(viewportStudies, function(study) {
|
||||
return viewportOverlayUtils.formatDateTime(study.studyDate, study.studyTime);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { Viewerbase } from '../namespace';
|
||||
|
||||
/**
|
||||
* Imports file with side effects only (files that do not export anything...)
|
||||
*/
|
||||
|
||||
import './collections';
|
||||
import './lib/stackImagePositionOffsetSynchronizer.js';
|
||||
import './lib/debugReactivity';
|
||||
|
||||
/**
|
||||
* Exported Functions
|
||||
*/
|
||||
@@ -192,10 +200,3 @@ Viewerbase.TypeSafeCollection = TypeSafeCollection;
|
||||
// OHIFError
|
||||
import { OHIFError } from './lib/classes/OHIFError';
|
||||
Viewerbase.OHIFError = OHIFError;
|
||||
|
||||
/**
|
||||
* Imports for Side Effects Only (Files that do not export anything...)
|
||||
*/
|
||||
|
||||
import './lib/stackImagePositionOffsetSynchronizer.js';
|
||||
import './lib/debugReactivity';
|
||||
@@ -67,6 +67,21 @@ export class TypeSafeCollection {
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
// [WIP]...
|
||||
static compareToPropertyMapStrict(propertyMap, object) {
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
const getPropertyValue = TypeSafeCollection.getPropertyValue;
|
||||
for (let propertyName in propertyMap) {
|
||||
if (hasOwnProperty.call(propertyMap, propertyName)) {
|
||||
const propertyValue = getPropertyValue(object, propertyName);
|
||||
if (propertyMap[propertyName] !== propertyValue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a sorting specifier is valid.
|
||||
* A valid sorting specifier consists of an array of arrays being each subarray a pair
|
||||
@@ -194,7 +209,7 @@ export class TypeSafeCollection {
|
||||
}
|
||||
|
||||
remove(propertyMap) {
|
||||
let found = this.findAllBy(propertyMap),
|
||||
let found = this.findAllEntriesBy(propertyMap),
|
||||
foundCount = found.length,
|
||||
removed = [];
|
||||
if (foundCount > 0) {
|
||||
@@ -267,13 +282,11 @@ export class TypeSafeCollection {
|
||||
* Find all elements that match a specified property map.
|
||||
* Attention!!! The reactive source will not be notified if no valid property map is supplied...
|
||||
* @param {Object} propertyMap A property map that will be macthed against all collection elements.
|
||||
* @param {Object} options A set of options. Currently only "options.sort" option is supported.
|
||||
* @param {Object.SortingSpecifier} options.sort An optional sorting specifier. If a sorting specifier is supplied
|
||||
* but it's not valid, an exception will be thrown.
|
||||
* @returns {Array} An array with all elements stored in the collection.
|
||||
* @returns {Array} An array of entries of all elements that match the given criteria. Each set in
|
||||
* in the array has the following format: [ elementData, elementId, elementIndex ].
|
||||
*/
|
||||
findAllBy(propertyMap, options) {
|
||||
let found = [];
|
||||
findAllEntriesBy(propertyMap) {
|
||||
const found = [];
|
||||
if (typeof propertyMap === OBJECT && propertyMap !== null) {
|
||||
const hasOwn = Object.prototype.hasOwnProperty;
|
||||
this._elements().forEach((item, index) => {
|
||||
@@ -289,6 +302,20 @@ export class TypeSafeCollection {
|
||||
found.push([ payload, item.id, index ]);
|
||||
});
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all elements that match a specified property map.
|
||||
* Attention!!! The reactive source will not be notified if no valid property map is supplied...
|
||||
* @param {Object} propertyMap A property map that will be macthed against all collection elements.
|
||||
* @param {Object} options A set of options. Currently only "options.sort" option is supported.
|
||||
* @param {Object.SortingSpecifier} options.sort An optional sorting specifier. If a sorting specifier is supplied
|
||||
* but it's not valid, an exception will be thrown.
|
||||
* @returns {Array} An array with all elements that match the given criteria and sorted in the specified sorting order.
|
||||
*/
|
||||
findAllBy(propertyMap, options) {
|
||||
const found = this.findAllEntriesBy(propertyMap).map(item => item[0]); // Only payload is relevant...
|
||||
if (options instanceof Object && 'sort' in options) {
|
||||
TypeSafeCollection.sortListBy(found, options.sort);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user