* Move DICOMSR to @ohif/core * refactor: 💡 Move DICOMSR code to @ohif/core project We've just merged support for DICOM Structured Reports. Today, support for this feature lives in the @ohif/viewer project in it's lib folder. Ideally, it should be moved to @ohif/core and given a clear public API and unit tests. Closes: #1282 * Update imports * CR Update: Update imports
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
import * as dcmjs from 'dcmjs';
|
|
import cornerstone from 'cornerstone-core';
|
|
|
|
import log from '../log';
|
|
import measurements from '../measurements';
|
|
import isToolSupported from './utils/isToolSupported';
|
|
|
|
/**
|
|
* Function to parse OHIF viewer measurementData into a dcmjs MeasurementReport
|
|
*
|
|
* @param {Object} measurementsData - OHIF measurementData object
|
|
* @returns {Object} Dataset: measurement report from dcmjs
|
|
*/
|
|
const parseMeasurementsData = measurementsData => {
|
|
const { MeasurementReport } = dcmjs.adapters.Cornerstone;
|
|
const { getImageIdForImagePath } = measurements;
|
|
|
|
const toolState = {};
|
|
const unsupportedTools = [];
|
|
|
|
Object.keys(measurementsData).forEach(measurementType => {
|
|
const annotations = measurementsData[measurementType];
|
|
|
|
annotations.forEach(annotation => {
|
|
const { toolType, imagePath } = annotation;
|
|
|
|
if (isToolSupported(toolType)) {
|
|
const imageId = getImageIdForImagePath(imagePath);
|
|
toolState[imageId] = toolState[imageId] || {};
|
|
toolState[imageId][toolType] = toolState[imageId][toolType] || {
|
|
data: [],
|
|
};
|
|
|
|
toolState[imageId][toolType].data.push(annotation);
|
|
} else {
|
|
unsupportedTools.push(toolType);
|
|
}
|
|
});
|
|
});
|
|
|
|
if (unsupportedTools.length > 0) {
|
|
log.warn(
|
|
`[DICOMSR] Tooltypes not supported: ${unsupportedTools.join(', ')}`
|
|
);
|
|
}
|
|
|
|
const report = MeasurementReport.generateReport(
|
|
toolState,
|
|
cornerstone.metaData
|
|
);
|
|
|
|
return {
|
|
dataset: report.dataset,
|
|
};
|
|
};
|
|
|
|
export default parseMeasurementsData;
|