Merge pull request #555 from OHIF/cornerstone-extension-update
refactor(@ohif/extension-cornerstone): Error handling and removal of …
This commit is contained in:
commit
5a0d37ff64
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ohif/extension-cornerstone",
|
||||
"version": "0.0.34",
|
||||
"version": "0.0.36",
|
||||
"description": "OHIF extension for Cornerstone",
|
||||
"author": "OHIF",
|
||||
"license": "MIT",
|
||||
|
||||
@ -47,10 +47,6 @@ const mapDispatchToProps = (dispatch, ownProps) => {
|
||||
dispatch(setViewportSpecificData(viewportIndex, data));
|
||||
},
|
||||
|
||||
clearViewportSpecificData: () => {
|
||||
dispatch(clearViewportSpecificData(viewportIndex));
|
||||
},
|
||||
|
||||
/**
|
||||
* Our component "enables" the underlying dom element on "componentDidMount"
|
||||
* It listens for that event, and then emits the enabledElement. We can grab
|
||||
|
||||
@ -54,31 +54,60 @@ class OHIFCornerstoneViewport extends Component {
|
||||
StackManager.clearStacks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the CornerstoneTools Stack for the specified display set.
|
||||
*
|
||||
* @param {Object[]} studies
|
||||
* @param {String} studyInstanceUid
|
||||
* @param {String} displaySetInstanceUid
|
||||
* @param {String} [sopInstanceUid]
|
||||
* @param {Number} [frameIndex=1]
|
||||
* @return {Object} CornerstoneTools Stack
|
||||
*/
|
||||
static getCornerstoneStack(
|
||||
studies,
|
||||
studyInstanceUid,
|
||||
displaySetInstanceUid,
|
||||
sopInstanceUid,
|
||||
frameIndex
|
||||
frameIndex = 0
|
||||
) {
|
||||
if (!studies || !studies.length) {
|
||||
throw new Error('Studies not provided.');
|
||||
}
|
||||
|
||||
if (!studyInstanceUid) {
|
||||
throw new Error('StudyInstanceUID not provided.')
|
||||
}
|
||||
|
||||
if (!displaySetInstanceUid) {
|
||||
throw new Error('StudyInstanceUID not provided.')
|
||||
}
|
||||
|
||||
// Create shortcut to displaySet
|
||||
const study = studies.find(
|
||||
study => study.studyInstanceUid === studyInstanceUid
|
||||
);
|
||||
|
||||
if (!study) {
|
||||
throw new Error('Study not found.');
|
||||
}
|
||||
|
||||
const displaySet = study.displaySets.find(set => {
|
||||
return set.displaySetInstanceUid === displaySetInstanceUid;
|
||||
});
|
||||
|
||||
if (!displaySet) {
|
||||
throw new Error('Display Set not found.');
|
||||
}
|
||||
|
||||
// Get stack from Stack Manager
|
||||
const storedStack = StackManager.findOrCreateStack(study, displaySet);
|
||||
|
||||
// Clone the stack here so we don't mutate it
|
||||
const stack = Object.assign({}, storedStack);
|
||||
stack.currentImageIdIndex = frameIndex;
|
||||
|
||||
if (frameIndex !== undefined) {
|
||||
stack.currentImageIdIndex = frameIndex;
|
||||
} else if (sopInstanceUid) {
|
||||
if (sopInstanceUid) {
|
||||
const index = stack.imageIds.findIndex(imageId => {
|
||||
const sopCommonModule = cornerstone.metaData.get(
|
||||
'sopCommonModule',
|
||||
@ -94,10 +123,8 @@ class OHIFCornerstoneViewport extends Component {
|
||||
if (index > -1) {
|
||||
stack.currentImageIdIndex = index;
|
||||
} else {
|
||||
stack.currentImageIdIndex = 0;
|
||||
console.warn('SOPInstanceUID provided was not found in specified DisplaySet');
|
||||
}
|
||||
} else {
|
||||
stack.currentImageIdIndex = 0;
|
||||
}
|
||||
|
||||
return stack;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user