From de86d4141f570484f6fde334e6d9c2dc22baebe9 Mon Sep 17 00:00:00 2001 From: Erik Ziegler Date: Tue, 15 Nov 2016 19:03:05 +0100 Subject: [PATCH] LT-323: First measurement is activated on Case Load --- .../client/components/viewer/viewer.js | 56 +++++++++++++++++++ .../measurementTable/measurementTable.js | 39 ------------- .../client/lib/jumpToRowItem.js | 4 +- .../viewer/viewerMain/viewerMain.js | 2 + 4 files changed, 60 insertions(+), 41 deletions(-) diff --git a/LesionTracker/client/components/viewer/viewer.js b/LesionTracker/client/components/viewer/viewer.js index 40ed639a8..74a10e0d8 100644 --- a/LesionTracker/client/components/viewer/viewer.js +++ b/LesionTracker/client/components/viewer/viewer.js @@ -2,6 +2,7 @@ import { Template } from 'meteor/templating'; import { Session } from 'meteor/session'; import { OHIF } from 'meteor/ohif:core'; +Session.set('ViewerMainReady', false); Session.set('TimepointsReady', false); Session.set('MeasurementsReady', false); @@ -116,6 +117,55 @@ Template.viewer.onCreated(() => { // Disable Lesion Tracker Tools if the opened study is not associated OHIF.lesiontracker.toggleLesionTrackerToolsButtons(false); } + + instance.autorun(() => { + if (!Session.get('TimepointsReady') || + !Session.get('MeasurementsReady') || + !Session.get('ViewerMainReady')) { + return; + } + + // Find and activate the first measurement by Lesion Number + // NOTE: This is inefficient, we should be using a hanging protocol + // to hang the first measurement's imageId immediately, rather + // than changing images after initial loading... + const config = OHIF.measurements.MeasurementApi.getConfiguration(); + const measurementTypeId = config.measurementTools[0].id; + const measurementApi = instance.data.measurementApi; + const timepointApi = instance.data.timepointApi; + + const collection = measurementApi[measurementTypeId]; + const sorting = { + sort: { + measurementNumber: -1 + } + }; + + const data = collection.find({}, sorting).fetch(); + + let timepoints = [timepointApi.current()]; + const prior = timepointApi.prior(); + if (prior) { + timepoints.push(prior); + } + + // TODO: Clean this up, it's probably an inefficient way to get what we need + const groupObject = _.groupBy(data, m => m.measurementNumber); + + // Reformat the data + const rows = Object.keys(groupObject).map(key => ({ + measurementTypeId: measurementTypeId, + measurementNumber: key, + entries: groupObject[key] + })); + + const rowItem = rows[0]; + + // Activate the first lesion + if (rowItem) { + OHIF.measurements.jumpToRowItem(rowItem, timepoints); + } + }) }); Template.viewer.helpers({ @@ -138,3 +188,9 @@ Template.viewer.events({ OHIF.measurements.MeasurementHandlers.onRemoved(event, instance, eventData); } }); + +Template.viewer.onDestroyed(() => { + Session.set('ViewerMainReady', false); + Session.set('TimepointsReady', false); + Session.set('MeasurementsReady', false); +}); \ No newline at end of file diff --git a/Packages/ohif-measurements/client/components/measurementTable/measurementTable.js b/Packages/ohif-measurements/client/components/measurementTable/measurementTable.js index 7b6e6ad6b..706001c09 100644 --- a/Packages/ohif-measurements/client/components/measurementTable/measurementTable.js +++ b/Packages/ohif-measurements/client/components/measurementTable/measurementTable.js @@ -48,45 +48,6 @@ Template.measurementTable.onRendered(() => { }); }); -Template.measurementTable.onRendered(() => { - // Find and activate the first measurement by Lesion Number - // NOTE: This is inefficient, we should be using a hanging protocol - // to hang the first measurement's imageId immediately, rather - // than changing images after initial loading... - const instance = Template.instance(); - - const config = OHIF.measurements.MeasurementApi.getConfiguration(); - const measurementTypeId = config.measurementTools[0].id; - const measurementApi = instance.data.measurementApi; - const collection = measurementApi[measurementTypeId]; - const sorting = { - sort: { - measurementNumber: -1 - } - }; - - const data = collection.find({}, sorting).fetch(); - - const timepoints = instance.data.timepoints.get(); - - // TODO: Clean this up, it's probably an inefficient way to get what we need - const groupObject = _.groupBy(data, entry => entry.measurementNumber); - - // Reformat the data - const rows = Object.keys(groupObject).map(key => ({ - measurementTypeId: measurementTypeId, - measurementNumber: key, - entries: groupObject[key] - })); - - const rowItem = rows[0]; - - // Activate the first lesion - if (rowItem) { - OHIF.measurements.jumpToRowItem(rowItem, timepoints); - } -}); - Template.measurementTable.helpers({ buttonGroupData() { const instance = Template.instance(); diff --git a/Packages/ohif-measurements/client/lib/jumpToRowItem.js b/Packages/ohif-measurements/client/lib/jumpToRowItem.js index e9af4af7f..4ed6c6a08 100644 --- a/Packages/ohif-measurements/client/lib/jumpToRowItem.js +++ b/Packages/ohif-measurements/client/lib/jumpToRowItem.js @@ -71,11 +71,11 @@ OHIF.measurements.jumpToRowItem = (rowItem, timepoints) => { // Retrieve the timepoints that are currently being displayed in the // Measurement Table - const numTimepoints = timepoints.length; + const numTimepoints = Math.max(timepoints.length, 1); // Retrieve the list of available viewports const $viewports = $('.imageViewerViewport'); - const numViewports = $viewports.length; + const numViewports = Math.max($viewports.length, 1); /* Two Timepoints, Two measurements, load Followup (FU and BA), display FU in left and BA in right diff --git a/Packages/ohif-viewerbase/client/components/viewer/viewerMain/viewerMain.js b/Packages/ohif-viewerbase/client/components/viewer/viewerMain/viewerMain.js index ae7599487..3d160ee01 100644 --- a/Packages/ohif-viewerbase/client/components/viewer/viewerMain/viewerMain.js +++ b/Packages/ohif-viewerbase/client/components/viewer/viewerMain/viewerMain.js @@ -37,6 +37,8 @@ Template.viewerMain.onRendered(() => { // Enable hotkeys enableHotkeys(); + + Session.set('ViewerMainReady', Random.id()); }); });