LT-363: Fixes for removing association and retrieving only applicable timepoints / measurements for the open case
This commit is contained in:
parent
2895ce84b1
commit
c9e607a21c
@ -72,11 +72,9 @@ Template.viewer.onCreated(() => {
|
|||||||
OHIF.viewer.timepointApi = instance.data.timepointApi;
|
OHIF.viewer.timepointApi = instance.data.timepointApi;
|
||||||
|
|
||||||
const patientId = instance.data.studies[0].patientId;
|
const patientId = instance.data.studies[0].patientId;
|
||||||
const filter = {
|
|
||||||
patientId
|
|
||||||
};
|
|
||||||
|
|
||||||
const timepointsPromise = instance.data.timepointApi.retrieveTimepoints(filter);
|
// TODO: Consider combining the retrieval calls into one?
|
||||||
|
const timepointsPromise = instance.data.timepointApi.retrieveTimepoints(patientId);
|
||||||
timepointsPromise.then(() => {
|
timepointsPromise.then(() => {
|
||||||
const timepoints = instance.data.timepointApi.all();
|
const timepoints = instance.data.timepointApi.all();
|
||||||
|
|
||||||
@ -95,14 +93,15 @@ Template.viewer.onCreated(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Session.set('TimepointsReady', true);
|
Session.set('TimepointsReady', true);
|
||||||
});
|
|
||||||
|
|
||||||
instance.data.measurementApi = new OHIF.measurements.MeasurementApi(instance.data.currentTimepointId);
|
const timepointIds = timepoints.map(t => t.timepointId);
|
||||||
const measurementsPromise = instance.data.measurementApi.retrieveMeasurements(filter);
|
instance.data.measurementApi = new OHIF.measurements.MeasurementApi(instance.data.currentTimepointId);
|
||||||
measurementsPromise.then(() => {
|
const measurementsPromise = instance.data.measurementApi.retrieveMeasurements(patientId, timepointIds);
|
||||||
Session.set('MeasurementsReady', true);
|
measurementsPromise.then(() => {
|
||||||
|
Session.set('MeasurementsReady', true);
|
||||||
|
|
||||||
instance.data.measurementApi.syncMeasurementsAndToolData();
|
instance.data.measurementApi.syncMeasurementsAndToolData();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Provide the necessary data to the Measurement API and Timepoint API
|
// Provide the necessary data to the Measurement API and Timepoint API
|
||||||
@ -148,7 +147,12 @@ Template.viewer.onCreated(() => {
|
|||||||
|
|
||||||
const data = collection.find({}, sorting).fetch();
|
const data = collection.find({}, sorting).fetch();
|
||||||
|
|
||||||
let timepoints = [timepointApi.current()];
|
const current = timepointApi.current();
|
||||||
|
if (!current) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let timepoints = [current];
|
||||||
const prior = timepointApi.prior();
|
const prior = timepointApi.prior();
|
||||||
if (prior) {
|
if (prior) {
|
||||||
timepoints.push(prior);
|
timepoints.push(prior);
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { measurementTools } from './measurementTools';
|
import { measurementTools } from './measurementTools';
|
||||||
|
|
||||||
export const retrieveMeasurements = (filter) => {
|
export const retrieveMeasurements = (patientId, timepointIds) => {
|
||||||
console.log('retrieveMeasurements');
|
console.log('retrieveMeasurements');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Meteor.call('retrieveMeasurements', filter, (error, response) => {
|
Meteor.call('retrieveMeasurements', patientId, timepointIds, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
@ -36,11 +36,11 @@ export const storeMeasurements = (measurementData, timepointIds) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const retrieveTimepoints = (filter) => {
|
export const retrieveTimepoints = (patientId) => {
|
||||||
console.log('retrieveTimepoints');
|
console.log('retrieveTimepoints');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Meteor.call('retrieveTimepoints', filter, (error, response) => {
|
Meteor.call('retrieveTimepoints', patientId, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
@ -81,12 +81,12 @@ export const updateTimepoint = (timepointData, query) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeTimepoint = timepointData => {
|
export const removeTimepoint = timepointId => {
|
||||||
console.log('removeTimepoint');
|
console.log('removeTimepoint');
|
||||||
console.log(timepointData);
|
console.log(timepointId);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Meteor.call('removeTimepoint', timepointData, (error, response) => {
|
Meteor.call('removeTimepoint', timepointId, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -79,10 +79,9 @@ Meteor.methods({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
removeTimepoint(timepointData) {
|
removeTimepoint(timepointId) {
|
||||||
OHIF.log.info('Removing Timepoint from the Server');
|
OHIF.log.info('Removing Timepoint from the Server');
|
||||||
OHIF.log.info(JSON.stringify(timepointData, null, 2));
|
Timepoints.remove({timepointId});
|
||||||
Timepoints.remove(timepointData);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTimepoint(timepointData, query) {
|
updateTimepoint(timepointData, query) {
|
||||||
@ -92,9 +91,15 @@ Meteor.methods({
|
|||||||
Timepoints.update(timepointData, query);
|
Timepoints.update(timepointData, query);
|
||||||
},
|
},
|
||||||
|
|
||||||
retrieveTimepoints(filter) {
|
retrieveTimepoints(patientId) {
|
||||||
OHIF.log.info('Retrieving Timepoints from the Server');
|
OHIF.log.info('Retrieving Timepoints from the Server');
|
||||||
return Timepoints.find(filter || {}).fetch();
|
|
||||||
|
const filter = {}
|
||||||
|
if (patientId) {
|
||||||
|
filter.patientId = patientId;
|
||||||
|
};
|
||||||
|
|
||||||
|
return Timepoints.find(filter).fetch();
|
||||||
},
|
},
|
||||||
|
|
||||||
storeMeasurements(measurementData, filter = {}) {
|
storeMeasurements(measurementData, filter = {}) {
|
||||||
@ -115,13 +120,23 @@ Meteor.methods({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
retrieveMeasurements(filter = {}) {
|
retrieveMeasurements(patientId, timepointIds) {
|
||||||
OHIF.log.info('Retrieving Measurements from the Server');
|
OHIF.log.info('Retrieving Measurements from the Server');
|
||||||
let measurementData = {};
|
let measurementData = {};
|
||||||
|
|
||||||
|
const filter = {}
|
||||||
|
if (patientId) {
|
||||||
|
filter.patientId = patientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timepointIds) {
|
||||||
|
filter.timepointId = {
|
||||||
|
$in: timepointIds
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
measurementTools.forEach(tool => {
|
measurementTools.forEach(tool => {
|
||||||
measurementData[tool.id] = MeasurementCollections[tool.id].find(filter || {}).fetch();
|
measurementData[tool.id] = MeasurementCollections[tool.id].find(filter).fetch();
|
||||||
});
|
});
|
||||||
|
|
||||||
return measurementData;
|
return measurementData;
|
||||||
|
|||||||
@ -28,18 +28,14 @@ class MeasurementApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
retrieveMeasurements(timepointId) {
|
retrieveMeasurements(patientId, timepointIds) {
|
||||||
if (!timepointId) {
|
|
||||||
timepointId = this.currentTimepointId;
|
|
||||||
}
|
|
||||||
|
|
||||||
const retrievalFn = configuration.dataExchange.retrieve;
|
const retrievalFn = configuration.dataExchange.retrieve;
|
||||||
if (!_.isFunction(retrievalFn)) {
|
if (!_.isFunction(retrievalFn)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
retrievalFn(timepointId).then(measurementData => {
|
retrievalFn(patientId, timepointIds).then(measurementData => {
|
||||||
|
|
||||||
OHIF.log.info('Measurement data retrieval');
|
OHIF.log.info('Measurement data retrieval');
|
||||||
OHIF.log.info(measurementData);
|
OHIF.log.info(measurementData);
|
||||||
@ -152,8 +148,27 @@ class MeasurementApi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let overallMeasurementNumber = 1;
|
let overallMeasurementNumber = 1;
|
||||||
|
let specificToolMeasurementNumber = 1;
|
||||||
|
|
||||||
|
|
||||||
|
const updateMeasurementNumber = (collection, toolType) => {
|
||||||
|
return data => {
|
||||||
|
const filter = {
|
||||||
|
measurementNumber: data.measurementNumber,
|
||||||
|
toolType
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.update(filter, {
|
||||||
|
$set: {
|
||||||
|
measurementNumber: specificToolMeasurementNumber
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Increment the overall measurement number
|
||||||
|
specificToolMeasurementNumber += 1;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// Given a Collection and a
|
|
||||||
const updateMeasurementNumberOverall = (collection, toolType) => {
|
const updateMeasurementNumberOverall = (collection, toolType) => {
|
||||||
return data => {
|
return data => {
|
||||||
const filter = {
|
const filter = {
|
||||||
@ -182,6 +197,24 @@ class MeasurementApi {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// First, update Measurement Number and the displayed Measurements
|
||||||
|
includedTools.forEach(tool => {
|
||||||
|
const collection = this[tool.id];
|
||||||
|
const toolType = tool.cornerstoneToolType;
|
||||||
|
const measurements = collection.find({toolType}).fetch();
|
||||||
|
const groupObject = _.groupBy(measurements, m => m.measurementNumber);
|
||||||
|
const sortedByMeasurementNumber = Object.keys(groupObject).map(summarizeMeasurement(groupObject, toolType));
|
||||||
|
sortedByMeasurementNumber.forEach(updateMeasurementNumber(collection, toolType))
|
||||||
|
|
||||||
|
measurements.forEach(measurement => {
|
||||||
|
OHIF.measurements.syncMeasurementAndToolData(measurement);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reset specificToolMeasurementNumber
|
||||||
|
specificToolMeasurementNumber = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Next, handle the overall measurement number.
|
||||||
// First, handle data that has a measurement at baseline
|
// First, handle data that has a measurement at baseline
|
||||||
includedTools.forEach(tool => {
|
includedTools.forEach(tool => {
|
||||||
const collection = this[tool.id];
|
const collection = this[tool.id];
|
||||||
@ -255,9 +288,10 @@ class MeasurementApi {
|
|||||||
syncFilter.measurementNumber = {
|
syncFilter.measurementNumber = {
|
||||||
$gt: measurementNumber - 1
|
$gt: measurementNumber - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
collection.find(syncFilter).forEach(measurement => {
|
collection.find(syncFilter).forEach(measurement => {
|
||||||
OHIF.measurements.syncMeasurementAndToolData(measurement);
|
OHIF.measurements.syncMeasurementAndToolData(measurement);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(measurementTypeId, selector, options) {
|
fetch(measurementTypeId, selector, options) {
|
||||||
|
|||||||
@ -26,14 +26,14 @@ class TimepointApi {
|
|||||||
this.timepoints._debugName = 'Timepoints';
|
this.timepoints._debugName = 'Timepoints';
|
||||||
}
|
}
|
||||||
|
|
||||||
retrieveTimepoints(filter) {
|
retrieveTimepoints(patientId) {
|
||||||
const retrievalFn = configuration.dataExchange.retrieve;
|
const retrievalFn = configuration.dataExchange.retrieve;
|
||||||
if (!_.isFunction(retrievalFn)) {
|
if (!_.isFunction(retrievalFn)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
retrievalFn(filter).then(timepointData => {
|
retrievalFn(patientId).then(timepointData => {
|
||||||
OHIF.log.info('Timepoint data retrieval');
|
OHIF.log.info('Timepoint data retrieval');
|
||||||
OHIF.log.info(timepointData);
|
OHIF.log.info(timepointData);
|
||||||
_.each(timepointData, timepoint => {
|
_.each(timepointData, timepoint => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user