fix(measurement-table): Set measurementId in table data
This commit is contained in:
parent
6f8b9ae593
commit
5fb95cc8a3
@ -5,23 +5,23 @@ import moment from 'moment';
|
|||||||
|
|
||||||
function groupBy(list, props) {
|
function groupBy(list, props) {
|
||||||
return list.reduce((a, b) => {
|
return list.reduce((a, b) => {
|
||||||
(a[b[props]] = a[b[props]] || []).push(b);
|
(a[b[props]] = a[b[props]] || []).push(b);
|
||||||
return a;
|
return a;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllTools() {
|
function getAllTools() {
|
||||||
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
const config = OHIF.measurements.MeasurementApi.getConfiguration();
|
||||||
let tools = [];
|
let tools = [];
|
||||||
config.measurementTools.forEach( toolGroup =>
|
config.measurementTools.forEach(
|
||||||
tools = tools.concat(toolGroup.childTools)
|
toolGroup => (tools = tools.concat(toolGroup.childTools))
|
||||||
);
|
);
|
||||||
|
|
||||||
return tools;
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMeasurementText(measurementData) {
|
function getMeasurementText(measurementData) {
|
||||||
const { location, description} = measurementData;
|
const { location, description } = measurementData;
|
||||||
let text = '...';
|
let text = '...';
|
||||||
if (location) {
|
if (location) {
|
||||||
text = location;
|
text = location;
|
||||||
@ -32,14 +32,18 @@ function getMeasurementText(measurementData) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDataForEachMeasurementNumber(measurementNumberList, timepoints, displayFunction) {
|
function getDataForEachMeasurementNumber(
|
||||||
|
measurementNumberList,
|
||||||
|
timepoints,
|
||||||
|
displayFunction
|
||||||
|
) {
|
||||||
const data = [];
|
const data = [];
|
||||||
// on each measurement number we should get each measurement data by available timepoint
|
// on each measurement number we should get each measurement data by available timepoint
|
||||||
measurementNumberList.forEach( measurement => {
|
measurementNumberList.forEach(measurement => {
|
||||||
timepoints.forEach( timepoint => {
|
timepoints.forEach(timepoint => {
|
||||||
const eachData = {
|
const eachData = {
|
||||||
displayText: '...'
|
displayText: '...'
|
||||||
}
|
};
|
||||||
if (measurement.timepointId === timepoint.timepointId) {
|
if (measurement.timepointId === timepoint.timepointId) {
|
||||||
eachData.displayText = displayFunction(measurement);
|
eachData.displayText = displayFunction(measurement);
|
||||||
}
|
}
|
||||||
@ -55,12 +59,12 @@ function convertMeasurementsToTableData(toolCollections, timepoints) {
|
|||||||
const toolGroups = config.measurementTools;
|
const toolGroups = config.measurementTools;
|
||||||
const tools = getAllTools();
|
const tools = getAllTools();
|
||||||
|
|
||||||
const tableMeasurements = toolGroups.map( toolGroup => {
|
const tableMeasurements = toolGroups.map(toolGroup => {
|
||||||
return {
|
return {
|
||||||
groupName: toolGroup.name,
|
groupName: toolGroup.name,
|
||||||
groupId: toolGroup.id,
|
groupId: toolGroup.id,
|
||||||
measurements: []
|
measurements: []
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(toolCollections).forEach(toolId => {
|
Object.keys(toolCollections).forEach(toolId => {
|
||||||
@ -71,20 +75,26 @@ function convertMeasurementsToTableData(toolCollections, timepoints) {
|
|||||||
// Group by measurementNumber so we can display then all in the same line
|
// Group by measurementNumber so we can display then all in the same line
|
||||||
const groupedMeasurements = groupBy(toolMeasurements, 'measurementNumber');
|
const groupedMeasurements = groupBy(toolMeasurements, 'measurementNumber');
|
||||||
|
|
||||||
Object.keys(groupedMeasurements).forEach( groupedMeasurementsIndex => {
|
Object.keys(groupedMeasurements).forEach(groupedMeasurementsIndex => {
|
||||||
const measurementNumberList = groupedMeasurements[groupedMeasurementsIndex];
|
const measurementNumberList =
|
||||||
|
groupedMeasurements[groupedMeasurementsIndex];
|
||||||
//check if all measurements with same measurementNumber will have same LABEL
|
//check if all measurements with same measurementNumber will have same LABEL
|
||||||
const tableMeasurement = {
|
const tableMeasurement = {
|
||||||
label: getMeasurementText(measurementNumberList[0]),
|
measurementId: measurementNumberList[0]._id,
|
||||||
|
label: getMeasurementText(measurementNumberList[0]),
|
||||||
hasWarnings: false, //TODO
|
hasWarnings: false, //TODO
|
||||||
warningTitle: '', //TODO
|
warningTitle: '', //TODO
|
||||||
isSplitLesion: false, //TODO
|
isSplitLesion: false, //TODO
|
||||||
warningList: [], //TODO
|
warningList: [], //TODO
|
||||||
data: getDataForEachMeasurementNumber(measurementNumberList, timepoints, displayFunction)
|
data: getDataForEachMeasurementNumber(
|
||||||
|
measurementNumberList,
|
||||||
|
timepoints,
|
||||||
|
displayFunction
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// find the group object for the tool
|
// find the group object for the tool
|
||||||
const toolGroupMeasurements = tableMeasurements.find( group => {
|
const toolGroupMeasurements = tableMeasurements.find(group => {
|
||||||
return group.groupId === tool.toolGroup;
|
return group.groupId === tool.toolGroup;
|
||||||
});
|
});
|
||||||
// inject the new measurement for this measurementNumer
|
// inject the new measurement for this measurementNumer
|
||||||
@ -112,7 +122,10 @@ const mapStateToProps = state => {
|
|||||||
const { timepoints, measurements } = state.timepointManager;
|
const { timepoints, measurements } = state.timepointManager;
|
||||||
return {
|
return {
|
||||||
timepoints: convertTimepointsToTableData(timepoints),
|
timepoints: convertTimepointsToTableData(timepoints),
|
||||||
measurementCollection: convertMeasurementsToTableData(measurements, timepoints)
|
measurementCollection: convertMeasurementsToTableData(
|
||||||
|
measurements,
|
||||||
|
timepoints
|
||||||
|
)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user