Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const measurement = Object.assign({}, measurementData, imageAttributes, {
lesionNamingNumber: measurementData.lesionNamingNumber,
userId: user.getUserId(),
toolType,
});
const addedMeasurement = measurementApi.addMeasurement(toolType, measurement);
Object.assign(measurementData, addedMeasurement);
const measurementLabel = getLabel(measurementData);
if (measurementLabel) {
measurementData.labels = [measurementLabel];
}
// TODO: This is very hacky, but will work for now
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
// TODO: Notify about the last activated measurement
if (MeasurementApi.isToolIncluded(tool)) {
// TODO: Notify that viewer suffered changes
}
}
});
});
const measurementsToActive = measurementApi.tools[toolType].filter(
measurement => {
return measurement.measurementNumber === measurementNumber;
}
);
measurementsToActive.forEach(measurementToActive => {
measurementToActive.active = true;
});
measurementApi.syncMeasurementsAndToolData();
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
// Needs to update viewports.layout state to set layout
//const layout = actionData.layout;
//dispatch(setLayout(layout))
// Needs to update viewports.activeViewportIndex to the first updated viewport
//const viewportIndex = actionData.viewportIndex;
//dispatch(setViewportActive(viewportIndex));
// Needs to update timepointsManager.measurements state to set active measurementId
// TODO: Not yet implemented
//dispatch(setActiveMeasurement(measurementData.measurementId))
// (later): Needs to set some property on state.extensions.cornerstone to synchronize viewport scrolling
const measurementApi = OHIF.measurements.MeasurementApi.Instance;
const measurements = measurementApi.tools[toolType].filter(
m => m.measurementNumber === measurementNumber
);
measurements.forEach(measurement => {
measurement.location = location;
measurement.description = description;
measurementApi.updateMeasurement(measurement.toolType, measurement);
});
measurementApi.syncMeasurementsAndToolData();
// Update images in all active viewports
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
},
showContextMenu({ event }) {
const measurementApi = OHIF.measurements.MeasurementApi.Instance;
const measurements = measurementApi.tools[toolType].filter(
m => m.measurementNumber === measurementNumber
);
measurements.forEach(measurement => {
measurement.location = location;
measurement.description = description;
measurementApi.updateMeasurement(measurement.toolType, measurement);
});
measurementApi.syncMeasurementsAndToolData();
// Update images in all active viewports
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
}
const measurementTypeId = measurementApi.toolsGroupsMap[toolType];
const measurement = collection.find(t => t._id === measurementData._id);
// Stop here if the measurement is already gone or never existed
if (!measurement) return;
// Remove all the measurements with the given type and number
const { lesionNamingNumber, timepointId } = measurement;
measurementApi.deleteMeasurements(toolType, measurementTypeId, {
lesionNamingNumber,
timepointId,
});
// TODO: This is very hacky, but will work for now
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
if (MeasurementApi.isToolIncluded(tool)) {
// TODO: Notify that viewer suffered changes
}
}
// Stop here if the measurement is already gone or never existed
if (!measurement) return;
if (measurement.childToolsCount === 1) {
// Remove the measurement
collection.splice(measurementIndex, 1);
measurementApi.onMeasurementRemoved(tool.parentTool, measurement);
} else {
// Update the measurement
measurement[tool.attribute] = null;
measurement.childToolsCount = (measurement.childToolsCount || 0) - 1;
measurementApi.updateMeasurement(tool.parentTool, measurement);
}
// TODO: This is very hacky, but will work for now
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
if (MeasurementApi.isToolIncluded(tool)) {
// TODO: Notify that viewer suffered changes
}
}
const measurements = measurementData[measurementTypeId];
measurements.forEach(measurement => {
const { toolType } = measurement;
this.addMeasurement(toolType, measurement);
});
});
}
resolve();
// Synchronize the new tool data
this.syncMeasurementsAndToolData();
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
// Let others know that the measurements are updated
this.onMeasurementsUpdated();
}, reject);
});
);
const addedMeasurement = measurementApi.addMeasurement(
tool.parentTool,
measurement
);
Object.assign(measurementData, addedMeasurement);
}
const measurementLabel = getLabel(measurementData);
if (measurementLabel) {
measurementData.labels = [measurementLabel];
}
// TODO: This is very hacky, but will work for now
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
// TODO: Notify about the last activated measurement
if (MeasurementApi.isToolIncluded(tool)) {
// TODO: Notify that viewer suffered changes
}
}
const measurementApi = OHIF.measurements.MeasurementApi.Instance;
const measurements = measurementApi.tools[toolType].filter(
m => m.measurementNumber === measurementNumber
);
measurements.forEach(measurement => {
measurement.location = location;
measurement.description = description;
measurementApi.updateMeasurement(measurement.toolType, measurement);
});
measurementApi.syncMeasurementsAndToolData();
// Update images in all active viewports
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
}
dispatchEditDescription: (event, measurementData, viewportsState) => {
event.persist();
const activeViewportIndex =
(viewportsState && viewportsState.activeViewportIndex) || 0;
const enabledElements = cornerstone.getEnabledElements();
if (!enabledElements || enabledElements.length <= activeViewportIndex) {
OHIF.log.error('Failed to find the enabled element');
return;
}
const { toolType, measurementId } = measurementData;
const tool = MeasurementApi.Instance.tools[toolType].find(measurement => {
return measurement._id === measurementId;
});
if (ownProps.onEditDescription) {
ownProps.onEditDescription(tool);
}
},
dispatchJumpToRowItem: (