Fixes for current case status and Lesion Tracker measurement table behaviour (LT-248)

This commit is contained in:
Erik Ziegler committed 2016-08-15 11:29:49 +02:00
1 parent d70439c12d
commit 62f102617f
17 files changed
+244 -92

No files matched your search

@@ -0,0 +1,102 @@
const hasValueAtTimepoint = timepointId => {
return measurement => {
if (measurement.timepoints[timepointId]) {
return true;
}
};
};
const hasNoValueAtTimepoint = timepointId => {
return measurement => {
if (measurement.timepoints[timepointId] === undefined) {
return true;
}
};
};
export const MeasurementApi = {
sortOptions: {
sort: {
lesionNumberAbsolute: 1
}
},
// Return all Measurements
all(withPriors=false) {
let data = Measurements.find({}, this.sortOptions).fetch();
// If we don't have a prior for this Timepoint,
// this filter, we should just return all of the
// available Non-Targets measurements
if (this.priorTimepointId && withPriors === true) {
return data.filter(hasValueAtTimepoint(this.priorTimepointId))
}
return data;
},
unmarked() {
const withPriors = true;
return this.all(withPriors).filter(hasNoValueAtTimepoint(this.currentTimepointId));;
},
unmarkedTargets() {
const withPriors = true;
return this.targets(withPriors).filter(hasNoValueAtTimepoint(this.currentTimepointId));;
},
unmarkedNonTargets() {
const withPriors = true;
return this.nonTargets(withPriors).filter(hasNoValueAtTimepoint(this.currentTimepointId));;
},
// Return only Target Measurements
targets(withPriors=false) {
let data = Measurements.find({
isTarget: true
}, this.sortOptions).fetch();
// If we don't have a prior for this Timepoint,
// this filter, we should just return all of the
// available Non-Targets measurements
if (this.priorTimepointId && withPriors === true) {
return data.filter(hasValueAtTimepoint(this.priorTimepointId))
}
return data;
},
// Return only Non-Target Measurements
nonTargets(withPriors=false) {
let data = Measurements.find({
isTarget: false
}, this.sortOptions).fetch();
// If we don't have a prior for this Timepoint,
// this filter, we should just return all of the
// available Non-Targets measurements
if (this.priorTimepointId && withPriors === true) {
return data.filter(hasValueAtTimepoint(this.priorTimepointId))
}
return data;
},
// Return only New Lesions
newLesions() {
// If we are current editing a Baseline we won't have any priors, so newLesions
// should return an empty array.
if (!this.priorTimepointId) {
return [];
}
// Find only lesions that have no value at the previous timepoint
return this.all().filter(hasNoValueAtTimepoint(this.priorTimepointId));
},
firstLesion() {
return Measurements.findOne({
target: true
}, this.sortOptions);
}
};
@@ -0,0 +1,118 @@
class TimepointApi {
constructor() {
// Run this computation every time the timepoints are changed
Tracker.autorun(() => {
// Get all the timepoints and store it
this.timepoints = new Mongo.Collection(null);
const timepoints = Timepoints.find({}, {
sort: {
latestDate: -1
}
}).fetch();
_.each(timepoints, timepoint => this.timepoints.insert(timepoint));
});
}
// Return all timepoints
all() {
return this.timepoints.find().fetch();
}
// Return only the current timepoint
current() {
return this.timepoints.findOne({
timepointId: this.currentTimepointId
});
}
prior() {
const latestDate = this.current().latestDate;
return this.timepoints.findOne({
latestDate: {
$lt: latestDate
}
}, {
sort: {
latestDate: -1
},
});
}
// Return only the current and prior Timepoints
currentAndPrior() {
let timepoints = [this.current()];
const prior = this.prior();
if (prior) {
timepoints.push(prior);
}
return timepoints;
}
// Return only the baseline timepoint
baseline() {
return this.timepoints.findOne({
timepointType: 'baseline'
});
}
// 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);
// Get all the timepoints
const all = this.all();
// 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);
}
});
// Return the resulting timepoints
return result.find().fetch();
}
// 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);
// 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);
}
});
// Return the resulting timepoints
return result.find().fetch();
}
// Build the timepoint title based on its date
title(timepoint) {
const timepointName = getTimepointName(timepoint);
const all = this.all();
let index = -1;
_.each(all, (currentTimepoint, currentIndex) => {
if (currentTimepoint.timepointId === timepoint.timepointId) {
index = currentIndex;
}
});
const states = {
0: '(Current)',
1: '(Prior)'
};
// TODO: [design] find out how to define the nadir timepoint
const parenthesis = states[index] || '';
return `${timepointName} ${parenthesis}`;
}
}
export { TimepointApi };
@@ -1,45 +1,37 @@
import { MeasurementApi } from 'meteor/lesiontracker/client/api/measurement';
Template.caseProgress.onCreated(() => {
const instance = Template.instance();
instance.progressPercent = new ReactiveVar();
instance.progressText = new ReactiveVar();
instance.isLocked = new ReactiveVar();
if (!instance.data.currentTimepointId) {
const current = instance.data.timepointApi.current();
if (!current.timepointId) {
console.warn('Case has no timepointId');
return;
}
const currentTimepointId = instance.data.currentTimepointId;
const timepoint = Timepoints.findOne({
timepointId: currentTimepointId
});
instance.isLocked.set(current.isLocked);
const timepointType = timepoint.timepointType;
// Retrieve the initial number of targets left to measure at this
// follow-up. Note that this is done outside of the reactive function
// below so that new lesions don't change the initial target count.
const withPriors = true;
const totalTargets = MeasurementApi.targets(withPriors).length;
instance.isLocked.set(timepoint.isLocked);
if (timepointType === 'baseline') {
// If we're currently reviewing a Baseline timepoint, don't do any
// progress measurement.
if (current.timepointType === 'baseline') {
instance.progressPercent.set(100);
} else {
// Retrieve the initial number of targets left to measure at this
// follow-up. Note that this is done outside of the reactive function
// below so that new lesions don't change the initial target count.
const totalTargets = Measurements.find({
isTarget: true
}).count();
// Setup a reactive function to update the progress whenever
// a measurement is made
instance.autorun(() => {
// Obtain the number of Measurements for which the current Timepoint has
// no Measurement data
let numRemainingMeasurements = 0;
Measurements.find().forEach(measurement => {
if (!measurement.timepoints[currentTimepointId]) {
numRemainingMeasurements++;
}
});
const numRemainingMeasurements = MeasurementApi.unmarked().length;
// Update the Case Progress text with the remaining measurement count
instance.progressText.set(numRemainingMeasurements);
@@ -67,7 +59,7 @@ Template.caseProgress.helpers({
},
progressComplete() {
let progressPercent = Template.instance().progressPercent.get();
const progressPercent = Template.instance().progressPercent.get();
return progressPercent === 100;
}
});
@@ -1,3 +1,5 @@
import { MeasurementApi } from 'meteor/lesiontracker/client/api/measurement';
Template.lesionTable.onCreated(() => {
const instance = Template.instance();
@@ -13,7 +15,7 @@ Template.lesionTable.onCreated(() => {
if (tableLayout === 'key') {
timepoints = instance.data.timepointApi.key();
} else {
timepoints = instance.data.timepointApi.latest();
timepoints = instance.data.timepointApi.currentAndPrior();
}
// Return key timepoints
@@ -47,14 +49,10 @@ Session.setDefault('NewSeriesLoaded', false);
Template.lesionTable.onRendered(() => {
// Find the first measurement by Lesion Number
var firstLesion = Measurements.findOne({}, {
sort: {
lesionNumber: 1
}
});
const firstLesion = MeasurementApi.firstLesion();
// Create an object to store the ContentId inside
var templateData = {
const templateData = {
contentId: Session.get('activeContentId')
};
@@ -1,7 +1,7 @@
Template.lesionTableHUD.onCreated(() => {
const instance = Template.instance();
instance.data.timepoints = new ReactiveVar(instance.data.timepointApi.latest());
instance.data.timepoints = new ReactiveVar(instance.data.timepointApi.currentAndPrior());
});
Template.lesionTableHUD.onRendered(() => {
@@ -1,14 +1,16 @@
<template name="lesionTableHeaderRow">
<div class="lesionTableHeaderRow">
{{ #if anyUnmarkedLesionsLeft}}
<div class="add js-setTool">
<svg>
<use xlink:href=/packages/viewerbase/assets/icons.svg#icon-ui-add></use>
</svg>
</div>
{{ /if }}
<div class="type">
{{type}}
</div>
<div class="max">
<div class="max {{ # if gt numberOfLesions maxNumLesions }}warning{{/if}}">
{{ #if maxNumLesions }}
<p class="maxNumLesions">
Max {{maxNumLesions}}
@@ -1,3 +1,5 @@
import { MeasurementApi } from 'meteor/lesiontracker/client/api/measurement';
const toolTypesById = {
target: 'bidirectional',
nonTarget: 'nonTarget',
@@ -14,21 +16,14 @@ Template.lesionTableHeaderRow.onCreated(() => {
const instance = Template.instance();
instance.maxNumLesions = new ReactiveVar();
const current = instance.data.timepointApi.current();
const timepointType = current.timepointType;
if (!instance.data.currentTimepointId) {
console.warn('Case has no timepointId');
return;
}
// Give the header a proper name
instance.data.type = namesById[instance.data.id];
const currentTimepointId = instance.data.currentTimepointId;
const timepoint = Timepoints.findOne({
timepointId: currentTimepointId
});
const timepointType = timepoint.timepointType;
// TODO: Check if we have criteria where maximum limits are applied to
// Non-Targets and/or New Lesions
if (timepointType === 'baseline' && instance.data.id === 'target') {
@@ -57,17 +52,35 @@ Template.lesionTableHeaderRow.onCreated(() => {
});
Template.lesionTableHeaderRow.helpers({
numberOfLesions: function() {
const instance = Template.instance();
return instance.data.measurements.count();
type() {
// Give the header a proper name
const id = Template.instance().data.id;
return namesById[id];
},
maxNumLesions: function() {
numberOfLesions() {
return Template.instance().data.measurements.length;
},
maxNumLesions() {
return Template.instance().maxNumLesions.get();
},
anyUnmarkedLesionsLeft() {
const id = Template.instance().data.id;
if (id === 'target') {
return MeasurementApi.unmarkedTargets().length;
} else if (id === 'nonTarget') {
return MeasurementApi.unmarkedNonTargets().length;
}
// Keep the 'Add' button for the New Lesions header row
return true;
}
});
Template.lesionTableHeaderRow.events({
'click .js-setTool': function(event, instance) {
'click .js-setTool'(event, instance) {
const id = instance.data.id;
const toolType = toolTypesById[id];
toolManager.setActiveTool(toolType);
@@ -63,7 +63,7 @@ $headerRowHeight = 63px
text-align: right
.maxNumLesions
background-color: $textSecondaryColor;
background-color: $textSecondaryColor
border-radius: 3px
color: black
display: table
@@ -75,3 +75,9 @@ $headerRowHeight = 63px
margin-top: 22px
padding: 2px 6px 0
text-transform: uppercase
transition($sidebarTransition)
&.warning
.maxNumLesions
color: $textPrimaryColor
background-color: $uiYellow
@@ -1,17 +1,26 @@
<template name="lesionTableView">
<div class="lesionTableView scrollArea">
{{>lesionTableHeaderRow id="target" measurements=targets currentTimepointId=currentTimepointId}}
{{>lesionTableHeaderRow id="target"
measurements=targets
currentTimepointId=currentTimepointId
timepointApi=timepointApi}}
{{#each target in targets}}
{{>lesionTableRow (clone this rowItem=target)}}
{{/each}}
{{>lesionTableHeaderRow id="nonTarget" measurements=nonTargets currentTimepointId=currentTimepointId}}
{{>lesionTableHeaderRow id="nonTarget"
measurements=nonTargets
currentTimepointId=currentTimepointId
timepointApi=timepointApi}}
{{#each nonTarget in nonTargets}}
{{>lesionTableRow (clone this rowItem=nonTarget)}}
{{/each}}
{{#if gt this.timepoints.get.length 1}}
{{>lesionTableHeaderRow id="newLesion" measurements=newLesions currentTimepointId=currentTimepointId}}
{{>lesionTableHeaderRow id="newLesion"
measurements=newLesions
currentTimepointId=currentTimepointId
timepointApi=timepointApi}}
{{#each newLesion in newLesions}}
{{>lesionTableRow (clone this rowItem=newLesion)}}
{{/each}}
@@ -1,32 +1,23 @@
import { MeasurementApi } from 'meteor/lesiontracker/client/api/measurement';
Template.lesionTableView.helpers({
targets() {
// All Targets shall be listed first followed by Non-Targets
return Measurements.find({
isTarget: true
}, {
sort: {
lesionNumberAbsolute: 1
}
});
const withPriors = true;
return MeasurementApi.targets(withPriors);
},
nonTargets() {
return Measurements.find({
isTarget: false
}, {
sort: {
lesionNumberAbsolute: 1
}
});
const withPriors = true;
return MeasurementApi.nonTargets(withPriors);
},
newLesions() {
return Measurements.find({
saved: false
}, {
sort: {
lesionNumberAbsolute: 1
}
});
return MeasurementApi.newLesions();
},
isFollowup() {
const instance = Template.instance();
const current = instance.data.timepointApi.current();
return (current && current.timepointType === 'followup');
}
});
@@ -28,7 +28,7 @@ $circleSize = 46px
font-weight: 700
font-size: 17px
text-align: center
color: $textColorActive
color: $activeColor
top: 0
svg
@@ -9,7 +9,7 @@
</div>
</div>
<table class="table table-striped">
<table class="table table-responsive">
<thead>
<tr>
<th class="center">Include Study?</th>
@@ -133,19 +133,16 @@ Template.toolbarSection.helpers({
return buttonData;
}
});
Template.toolbarSection.events({
'click #toggleHUD'(event, instance) {
'click #toggleHUD'() {
const state = Session.get('lesionTableHudOpen');
Session.set('lesionTableHudOpen', !state);
}
});
Template.toolbarSection.onRendered(function() {
const instance = Template.instance();
// Set disabled/enabled tool buttons that are set in toolManager
const states = toolManager.getToolDefaultStates();
const disabledToolButtons = states.disabledToolButtons;
@@ -1,5 +1,6 @@
import { OHIF } from 'meteor/ohif:core';
import { TimepointApi } from 'meteor/lesiontracker/lib/api/timepoint';
import { TimepointApi } from 'meteor/lesiontracker/client/api/timepoint';
import { MeasurementApi } from 'meteor/lesiontracker/client/api/measurement';
OHIF.viewer = OHIF.viewer || {};
OHIF.viewer.loadIndicatorDelay = 3000;
@@ -18,8 +19,6 @@ Session.setDefault('rightSidebar', null);
Template.viewer.onCreated(() => {
const instance = Template.instance();
instance.data.timepointApi = new TimepointApi();
ValidationErrors.remove({});
instance.data.state = new ReactiveDict();
@@ -91,6 +90,17 @@ Template.viewer.onCreated(() => {
// Set buttons as enabled/disabled when Timepoints collection is ready
timepointAutoCheck(dataContext);
// Wait until the Timepoint subscription is ready to initialize the TimepointApi
instance.data.timepointApi = new TimepointApi();
instance.data.timepointApi.currentTimepointId = instance.data.currentTimepointId;
// Provide the necessary data to the Measurement API
MeasurementApi.currentTimepointId = instance.data.currentTimepointId;
const prior = instance.data.timepointApi.prior();
if (prior) {
MeasurementApi.priorTimepointId = prior.timepointId;
}
TrialResponseCriteria.validateAllDelayed();
ViewerStudies.find().observe({