Skip to content

Commit

Permalink
feat: add onNewImage callback prop
Browse files Browse the repository at this point in the history
* Add a callback call on new image updates

* Prevent js to break if metaData is not provided
  • Loading branch information
galelis authored and dannyrb committed Dec 17, 2019
1 parent 939bb63 commit 50e33ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/CornerstoneViewport/CornerstoneViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CornerstoneViewport extends Component {
frameRate: PropTypes.number, // Between 1 and ?
//
setViewportActive: PropTypes.func, // Called when viewport should be set to active?
onNewImage: PropTypes.func,
viewportOverlayComponent: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
Expand Down Expand Up @@ -595,14 +596,22 @@ class CornerstoneViewport extends Component {
};

onNewImage = event => {
const newImageId = event.detail.image.imageId;
const newImageIdIndex = this.props.imageIds.indexOf(newImageId);
const { imageId } = event.detail.image;
const { sopInstanceUid } =
cornerstone.metaData.get('generalImageModule', imageId) || {};
const currentImageIdIndex = this.props.imageIds.indexOf(imageId);

// TODO: Should we grab and set some imageId specific metadata here?
// Could prevent cornerstone dependencies in child components.
this.setState({
imageIdIndex: newImageIdIndex,
imageIdIndex: currentImageIdIndex,
});

if (this.props.onNewImage) {
this.props.onNewImage({
sopInstanceUid,
});
}
};

onImageLoaded = () => {
Expand Down
1 change: 1 addition & 0 deletions src/metadataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function wadoRsMetaDataProvider(type, imageId) {

if (type === 'generalImageModule') {
return {
sopInstanceUid: getValue(metaData['00080018']),
instanceNumber: getNumberValue(metaData['00200013']),
lossyImageCompression: getValue(metaData['00282110']),
lossyImageCompressionRatio: getValue(metaData['00282112']),
Expand Down

0 comments on commit 50e33ba

Please sign in to comment.