diff --git a/src/dicom-microscopy-viewer.js b/src/dicom-microscopy-viewer.js index d564c02a..8ba5f7be 100644 --- a/src/dicom-microscopy-viewer.js +++ b/src/dicom-microscopy-viewer.js @@ -1,5 +1,9 @@ import EVENTS from './events.js'; -import { VLWholeSlideMicroscopyImage, formatMetadata } from './metadata.js'; +import { + Comprehensive3DSR, + VLWholeSlideMicroscopyImage, + formatMetadata, +} from './metadata.js'; import { ROI } from './roi.js'; import { Point, @@ -46,6 +50,7 @@ const viewer = { const metadata = { formatMetadata, VLWholeSlideMicroscopyImage, + Comprehensive3DSR, }; /** Namespace for 3-dimensional spatial coordinates (SCOORD3D). @@ -58,7 +63,7 @@ const scoord3d = { Polyline, Polygon, Ellipsoid, - Ellipse + Ellipse, }; /** Namespace for regions of interest (ROI). diff --git a/src/metadata.js b/src/metadata.js index add04c9e..808de8db 100644 --- a/src/metadata.js +++ b/src/metadata.js @@ -106,7 +106,10 @@ function formatMetadata(metadata) { // The top level (lowest resolution) image may be a single frame image in // which case the "NumberOfFrames" attribute is optional. We include it for // consistency. - if (!('NumberOfFrames' in dataset)) { + if (dataset === undefined) { + throw new Error('Could not format metadata: ', metadata) + } + if (!('NumberOfFrames' in dataset) && (dataset.Modality === 'SM')) { dataset.NumberOfFrames = 1; } @@ -114,7 +117,8 @@ function formatMetadata(metadata) { } -/** DICOM VL Whole Slide Microscopy Image instance. +/** DICOM VL Whole Slide Microscopy Image instance + * (without Pixel Data or any other bulk data). * * @class * @memberof metadata @@ -126,17 +130,45 @@ class VLWholeSlideMicroscopyImage { * @params {Object} options.metadata - Metadata in DICOM JSON format */ constructor(options) { - const sopClassUID = options.metadata['00080016']['Value'][0]; - if (sopClassUID !== '1.2.840.10008.5.1.4.1.1.77.1.6') { + const dataset = formatMetadata(options.metadata); + if (dataset.SOPClassUID !== '1.2.840.10008.5.1.4.1.1.77.1.6') { throw new Error( 'Cannot construct VL Whole Slide Microscopy Image instance ' + - `given dataset with SOP Class UID "${sopClassUID}"` + `given dataset with SOP Class UID "${dataset.SOPClassUID}"` ); } + Object.assign(this, dataset); + } +} + +/** DICOM Comprehensive 3D SR instance. + * + * @class + * @memberof metadata + */ +class Comprehensive3DSR { + + /** + * @params {Object} options + * @params {Object} options.metadata - Metadata in DICOM JSON format + */ + constructor(options) { const dataset = formatMetadata(options.metadata); + if (dataset.SOPClassUID !== '1.2.840.10008.5.1.4.1.1.88.34') { + throw new Error( + 'Cannot construct Comprehensive 3D SR instance ' + + `given dataset with SOP Class UID "${dataset.SOPClassUID}"` + ); + } + Object.assign(this, dataset); } } -export { VLWholeSlideMicroscopyImage, formatMetadata, getFrameMapping }; +export { + Comprehensive3DSR, + formatMetadata, + getFrameMapping, + VLWholeSlideMicroscopyImage, +};