Fixes for current case status and Lesion Tracker measurement table behaviour (LT-248)
This commit is contained in:
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 };
|
||||
Reference in new issue
Block a user