Keep toolData and Measurements in sync (LT-149)
This commit is contained in:
1 parent
5b07ec372c
commit
f7e24b8b10
8 files changed
+139
-78
No files matched your search
@@ -1,75 +1,95 @@
|
||||
syncMeasurementAndToolData = function(data) {
|
||||
syncMeasurementAndToolData = function(measurement) {
|
||||
console.log('syncMeasurementAndToolData');
|
||||
|
||||
// Check what toolType we should be adding this to, based on the isTarget value
|
||||
// of the stored Measurement
|
||||
var toolType = data.isTarget ? 'lesion' : 'nonTarget';
|
||||
var toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
var toolType = measurement.isTarget ? 'lesion' : 'nonTarget';
|
||||
|
||||
// Loop through the timepoint data for this measurement
|
||||
Object.keys(data.timepoints).forEach(function(key) {
|
||||
var storedData = data.timepoints[key];
|
||||
var imageId = storedData.imageId;
|
||||
Object.keys(measurement.timepoints).forEach(function(key) {
|
||||
var timepointData = measurement.timepoints[key];
|
||||
var imageId = timepointData.imageId;
|
||||
|
||||
if (!toolState[imageId]) {
|
||||
toolState[imageId] = {};
|
||||
}
|
||||
|
||||
// This is probably not the best approach to prevent duplicates
|
||||
if (toolState[imageId][toolType] && toolState[imageId][toolType].data) {
|
||||
var measurementHasNoIdYet = false;
|
||||
toolState[imageId][toolType].data.forEach(function(measurement) {
|
||||
if (measurement.id === 'notready') {
|
||||
measurementHasNoIdYet = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Stop here if it appears that we are creating this measurement right now,
|
||||
// and would not like this function to add another copy of it to the toolData
|
||||
if (measurementHasNoIdYet === true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!toolState[imageId][toolType]) {
|
||||
toolState[imageId][toolType] = {
|
||||
data: []
|
||||
};
|
||||
} else {
|
||||
var alreadyExists = false;
|
||||
if (toolState[imageId][toolType].data.length) {
|
||||
toolState[imageId][toolType].data.forEach(function(measurement) {
|
||||
if (measurement.id === data._id) {
|
||||
alreadyExists = true;
|
||||
|
||||
// Update the toolData lesionNumber from the Measurement
|
||||
measurement.lesionNumber = data.lesionNumber;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (alreadyExists === true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Create measurementData structure based on the lesion data at this timepoint
|
||||
// We will add this into the toolData for this imageId
|
||||
var measurementData = storedData;
|
||||
measurementData.isTarget = data.isTarget;
|
||||
measurementData.lesionNumber = data.lesionNumber;
|
||||
measurementData.measurementText = data.measurementText;
|
||||
measurementData.isDeleted = data.isDeleted;
|
||||
measurementData.location = data.location;
|
||||
measurementData.locationUID = data.locationUID;
|
||||
measurementData.patientId = data.patientId;
|
||||
measurementData.visible = data.visible;
|
||||
measurementData.active = data.active;
|
||||
measurementData.uid = data.uid;
|
||||
measurementData.id = data._id;
|
||||
|
||||
toolState[imageId][toolType].data.push(measurementData);
|
||||
|
||||
TrialResponseCriteria.validateSingleMeasurement(measurementData);
|
||||
syncTimepointDataWithToolData(measurement, timepointData, imageId, toolType);
|
||||
});
|
||||
};
|
||||
|
||||
function syncTimepointDataWithToolData(measurement, timepointData, imageId, toolType) {
|
||||
var toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
|
||||
if (!toolState[imageId]) {
|
||||
toolState[imageId] = {};
|
||||
}
|
||||
|
||||
// This is probably not the best approach to prevent duplicates
|
||||
if (toolState[imageId][toolType] && toolState[imageId][toolType].data) {
|
||||
var measurementHasNoIdYet = false;
|
||||
toolState[imageId][toolType].data.forEach(function(measurement) {
|
||||
if (measurement.id !== 'notready') {
|
||||
return;
|
||||
}
|
||||
|
||||
measurementHasNoIdYet = true;
|
||||
return false;
|
||||
});
|
||||
|
||||
// Stop here if it appears that we are creating this measurement right now,
|
||||
// and would not like this function to add another copy of it to the toolData
|
||||
if (measurementHasNoIdYet === true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (toolState[imageId][toolType]) {
|
||||
var alreadyExists = false;
|
||||
var toolData = toolState[imageId][toolType].data;
|
||||
if (!toolData.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
toolData.forEach(function(tool) {
|
||||
if (tool.id !== measurement._id) {
|
||||
return;
|
||||
}
|
||||
|
||||
alreadyExists = true;
|
||||
|
||||
// Update the toolData lesionNumber from the Measurement
|
||||
tool.lesionNumber = measurement.lesionNumber;
|
||||
tool.isTarget = measurement.isTarget;
|
||||
|
||||
tool.active = timepointData.active;
|
||||
tool.visible = timepointData.visible;
|
||||
tool.isDeleted = timepointData.isDeleted;
|
||||
tool.handles = timepointData.handles;
|
||||
return false;
|
||||
});
|
||||
|
||||
if (alreadyExists === true) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
toolState[imageId][toolType] = {
|
||||
data: []
|
||||
};
|
||||
}
|
||||
|
||||
// Create measurementData structure based on the lesion data at this timepoint
|
||||
// We will add this into the toolData for this imageId
|
||||
var measurementData = timepointData;
|
||||
measurementData.isTarget = measurement.isTarget;
|
||||
measurementData.lesionNumber = measurement.lesionNumber;
|
||||
measurementData.measurementText = measurement.measurementText;
|
||||
measurementData.isDeleted = measurement.isDeleted;
|
||||
measurementData.location = measurement.location;
|
||||
measurementData.locationUID = measurement.locationUID;
|
||||
measurementData.patientId = measurement.patientId;
|
||||
measurementData.visible = measurement.visible;
|
||||
measurementData.active = measurement.active;
|
||||
measurementData.uid = measurement.uid;
|
||||
measurementData.id = measurement._id;
|
||||
|
||||
toolState[imageId][toolType].data.push(measurementData);
|
||||
|
||||
TrialResponseCriteria.validateSingleMeasurement(measurementData);
|
||||
}
|
||||
Reference in new issue
Block a user