2020-06-25 18:13:31 +02:00
|
|
|
import SUPPORTED_TOOLS from './constants/supportedTools';
|
|
|
|
|
import getHandlesFromPoints from './utils/getHandlesFromPoints';
|
|
|
|
|
import getPointsFromHandles from './utils/getPointsFromHandles';
|
|
|
|
|
import getSOPInstanceAttributes from './utils/getSOPInstanceAttributes';
|
|
|
|
|
|
|
|
|
|
const Length = {
|
|
|
|
|
toAnnotation: (measurement, definition) => {
|
|
|
|
|
const {
|
|
|
|
|
id,
|
|
|
|
|
label,
|
|
|
|
|
description,
|
|
|
|
|
points,
|
|
|
|
|
unit,
|
|
|
|
|
SOPInstanceUID,
|
|
|
|
|
FrameOfReferenceUID,
|
|
|
|
|
referenceSeriesUID,
|
|
|
|
|
} = measurement;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
toolName: definition,
|
|
|
|
|
measurementData: {
|
|
|
|
|
sopInstanceUid: SOPInstanceUID,
|
|
|
|
|
frameOfReferenceUID: FrameOfReferenceUID,
|
|
|
|
|
SeriesInstanceUID: referenceSeriesUID,
|
|
|
|
|
unit,
|
|
|
|
|
text: label,
|
|
|
|
|
description,
|
|
|
|
|
handles: getHandlesFromPoints(points),
|
2020-07-01 11:08:56 +02:00
|
|
|
id,
|
2020-06-25 18:13:31 +02:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maps cornerstone annotation event data to measurement service format.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} cornerstone Cornerstone event data
|
|
|
|
|
* @return {Measurement} Measurement instance
|
|
|
|
|
*/
|
2020-07-22 19:40:40 +02:00
|
|
|
toMeasurement: (
|
|
|
|
|
csToolsAnnotation,
|
|
|
|
|
DisplaySetService,
|
|
|
|
|
getValueTypeFromToolType
|
|
|
|
|
) => {
|
2020-06-25 18:13:31 +02:00
|
|
|
const { element, measurementData } = csToolsAnnotation;
|
|
|
|
|
const tool =
|
|
|
|
|
csToolsAnnotation.toolType ||
|
|
|
|
|
csToolsAnnotation.toolName ||
|
|
|
|
|
measurementData.toolType;
|
|
|
|
|
|
|
|
|
|
const validToolType = toolName => SUPPORTED_TOOLS.includes(toolName);
|
|
|
|
|
|
|
|
|
|
if (!validToolType(tool)) {
|
|
|
|
|
throw new Error('Tool not supported');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
SOPInstanceUID,
|
|
|
|
|
FrameOfReferenceUID,
|
|
|
|
|
SeriesInstanceUID,
|
|
|
|
|
StudyInstanceUID,
|
|
|
|
|
} = getSOPInstanceAttributes(element);
|
|
|
|
|
|
2020-07-22 19:40:40 +02:00
|
|
|
const displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
|
|
|
|
SOPInstanceUID,
|
|
|
|
|
SeriesInstanceUID
|
|
|
|
|
);
|
|
|
|
|
|
2020-06-25 18:13:31 +02:00
|
|
|
return {
|
2020-07-01 11:08:56 +02:00
|
|
|
id: measurementData.id,
|
2020-06-25 18:13:31 +02:00
|
|
|
SOPInstanceUID: SOPInstanceUID,
|
|
|
|
|
FrameOfReferenceUID,
|
|
|
|
|
referenceSeriesUID: SeriesInstanceUID,
|
|
|
|
|
referenceStudyUID: StudyInstanceUID,
|
2020-07-22 19:40:40 +02:00
|
|
|
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
2020-06-25 18:13:31 +02:00
|
|
|
label: measurementData.text,
|
|
|
|
|
description: measurementData.description,
|
|
|
|
|
unit: measurementData.unit,
|
|
|
|
|
length: measurementData.length,
|
|
|
|
|
type: getValueTypeFromToolType(tool),
|
|
|
|
|
points: getPointsFromHandles(measurementData.handles),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Length;
|