* feat: 🎸 DICOM SR STOW on MeasurementAPI Closes: #758 * feat: 🎸 Adding the dataExchance from DICOM SR * feat: 🎸 Fix some issues and get the retrieve measurements working * feat: 🎸 Preventing measurement tool helpers to broke because the data is not Number (it comes as string from dcmjs) * feat: 🎸 Adding a button to start testing SATE functionality * feat: 🎸Small fixes into the code * feat: 🎸 MAke sure we get latest SR in the study, even on lazyLoad mode * Revert "feat: 🎸 Preventing measurement tool helpers to broke because the data is not Number (it comes as string from dcmjs)" This reverts commit 4b3a1efb5810487d2319826fd59c03d779882b5e. * feat: 🎸 Make sure after sync we update the viewports and also that annotation tools are set to passive, so it can be drawn in the viewports * feat: 🎸 Remove console logs and start using OHIF.log * feat: 🎸 Refactor measurement table to use Snackbar service of messages and make sure we only show save button if server type is dicomWeb * feat: 🎸 Refactor to remove mocked wadoRoot and use server * Fix to expose error once we can't save the SR * Update DCMJS into latest dev version * Update dcmjs with latest fixes * Fix PR callouts * Logging error on MeasurementReport creation * Preventing from breaking on non supported tools and also warning that some toolType is not sopported * Small error message update * Expose better the errors and when we have unsopported tools into the measurements * Renaming variable * Expose dcmjs tool support check * Change the way we warn the unsupportedTools * Adding style to the button * Small change on button style * Fix git conflicts * Fix after merge with latest master * Fix after merge with master, btn was not clickable * Fixing callouts * Adding util functions into files and refactor with JSDocs * Refactoring code, adding some basic JSDocs * Bump dcmjs with latest version and fixes * JSDocs and small refactors * yarn lock file after dcmjs update * Remove unused parameters * Registering a plain copy of server into measurementAPI * Small refactor * Start changing from toolType to toolName * Rename a function to get instanceMetadata * Adding error if server is not DICOMWeb on retrieve * Move snackbar outside of UI component and use UINotificationService * Refactor and JSDocs * Small fixes on JSDocs (style) * Remove unused import * Improve JSDocs on MeasurementApi * Remove refactor leftover * Improve JSDocs and propTypes * JSDocs and small refactors
143 lines
4.7 KiB
JavaScript
143 lines
4.7 KiB
JavaScript
import OHIF from '@ohif/core';
|
|
import cornerstone from 'cornerstone-core';
|
|
import csTools from 'cornerstone-tools';
|
|
import initCornerstoneTools from './initCornerstoneTools.js';
|
|
import queryString from 'query-string';
|
|
import { SimpleDialog } from '@ohif/ui';
|
|
import merge from 'lodash.merge';
|
|
|
|
function fallbackMetaDataProvider(type, imageId) {
|
|
if (!imageId.includes('wado?requestType=WADO')) {
|
|
return;
|
|
}
|
|
|
|
// If you call for an WADO-URI imageId and get no
|
|
// metadata, try reformatting to WADO-RS imageId
|
|
const qs = queryString.parse(imageId);
|
|
const wadoRoot = window.store.getState().servers.servers[0].wadoRoot;
|
|
const wadoRsImageId = `wadors:${wadoRoot}/studies/${qs.studyUID}/series/${
|
|
qs.seriesUID
|
|
}/instances/${qs.objectUID}/frames/${qs.frame || 1}`;
|
|
|
|
return cornerstone.metaData.get(type, wadoRsImageId);
|
|
}
|
|
|
|
// Add this fallback provider with a low priority so it is handled last
|
|
cornerstone.metaData.addProvider(fallbackMetaDataProvider, -1);
|
|
|
|
/**
|
|
*
|
|
* @param {Object} servicesManager
|
|
* @param {Object} configuration
|
|
* @param {Object|Array} configuration.csToolsConfig
|
|
*/
|
|
export default function init({ servicesManager, configuration }) {
|
|
const callInputDialog = (data, event, callback) => {
|
|
const { UIDialogService } = servicesManager.services;
|
|
|
|
if (UIDialogService) {
|
|
let dialogId = UIDialogService.create({
|
|
centralize: true,
|
|
isDraggable: false,
|
|
content: SimpleDialog.InputDialog,
|
|
useLastPosition: false,
|
|
showOverlay: true,
|
|
contentProps: {
|
|
title: 'Enter your annotation',
|
|
label: 'New label',
|
|
measurementData: data ? { description: data.text } : {},
|
|
onClose: () => UIDialogService.dismiss({ id: dialogId }),
|
|
onSubmit: value => {
|
|
callback(value);
|
|
UIDialogService.dismiss({ id: dialogId });
|
|
},
|
|
},
|
|
});
|
|
}
|
|
};
|
|
|
|
const { csToolsConfig } = configuration;
|
|
const { StackManager } = OHIF.utils;
|
|
const metadataProvider = new OHIF.cornerstone.MetadataProvider();
|
|
|
|
// ~~ Set our MetadataProvider
|
|
cornerstone.metaData.addProvider(
|
|
metadataProvider.provider.bind(metadataProvider)
|
|
);
|
|
|
|
StackManager.setMetadataProvider(metadataProvider);
|
|
|
|
// ~~
|
|
const defaultCsToolsConfig = csToolsConfig || {
|
|
globalToolSyncEnabled: true,
|
|
showSVGCursors: true,
|
|
autoResizeViewports: false,
|
|
};
|
|
|
|
initCornerstoneTools(defaultCsToolsConfig);
|
|
|
|
// ~~ Toooools 🙌
|
|
const tools = [
|
|
csTools.PanTool,
|
|
csTools.ZoomTool,
|
|
csTools.WwwcTool,
|
|
csTools.MagnifyTool,
|
|
csTools.StackScrollTool,
|
|
csTools.StackScrollMouseWheelTool,
|
|
// Touch
|
|
csTools.PanMultiTouchTool,
|
|
csTools.ZoomTouchPinchTool,
|
|
// Annotations
|
|
csTools.ArrowAnnotateTool,
|
|
csTools.EraserTool,
|
|
csTools.BidirectionalTool,
|
|
csTools.LengthTool,
|
|
csTools.AngleTool,
|
|
csTools.FreehandRoiTool,
|
|
csTools.EllipticalRoiTool,
|
|
csTools.DragProbeTool,
|
|
csTools.RectangleRoiTool,
|
|
// Segmentation
|
|
csTools.BrushTool,
|
|
];
|
|
|
|
/* Add extension tools configuration here. */
|
|
const internalToolsConfig = {
|
|
ArrowAnnotate: {
|
|
configuration: {
|
|
getTextCallback: (callback, eventDetails) =>
|
|
callInputDialog(null, eventDetails, callback),
|
|
changeTextCallback: (data, eventDetails, callback) =>
|
|
callInputDialog(data, eventDetails, callback),
|
|
},
|
|
},
|
|
};
|
|
|
|
/* Add tools with its custom props through extension configuration. */
|
|
tools.forEach(tool => {
|
|
const toolName = tool.name.replace('Tool', '');
|
|
const externalToolsConfig = configuration.tools || {};
|
|
const externalToolProps = externalToolsConfig[toolName] || {};
|
|
const internalToolProps = internalToolsConfig[toolName] || {};
|
|
const props = merge(internalToolProps, externalToolProps);
|
|
csTools.addTool(tool, props);
|
|
});
|
|
|
|
// TODO -> We need a better way to do this with maybe global tool state setting all tools passive.
|
|
const BaseAnnotationTool = csTools.importInternal('base/BaseAnnotationTool');
|
|
tools.forEach(tool => {
|
|
if (tool.prototype instanceof BaseAnnotationTool) {
|
|
// BaseAnnotationTool would likely come from csTools lib exports
|
|
const toolName = new tool().name;
|
|
csTools.setToolPassive(toolName); // there may be a better place to determine name; may not be on uninstantiated class
|
|
}
|
|
});
|
|
|
|
csTools.setToolActive('Pan', { mouseButtonMask: 4 });
|
|
csTools.setToolActive('Zoom', { mouseButtonMask: 2 });
|
|
csTools.setToolActive('Wwwc', { mouseButtonMask: 1 });
|
|
csTools.setToolActive('StackScrollMouseWheel', {}); // TODO: Empty options should not be required
|
|
csTools.setToolActive('PanMultiTouch', { pointers: 2 }); // TODO: Better error if no options
|
|
csTools.setToolActive('ZoomTouchPinch', {});
|
|
}
|