Skip to content

Commit

Permalink
Add metadata class for structured report documents
Browse files Browse the repository at this point in the history
  • Loading branch information
hackermd committed Dec 7, 2020
1 parent 4f75f39 commit 00c42dd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/dicom-microscopy-viewer.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -46,6 +50,7 @@ const viewer = {
const metadata = {
formatMetadata,
VLWholeSlideMicroscopyImage,
Comprehensive3DSR,
};

/** Namespace for 3-dimensional spatial coordinates (SCOORD3D).
Expand All @@ -58,7 +63,7 @@ const scoord3d = {
Polyline,
Polygon,
Ellipsoid,
Ellipse
Ellipse,
};

/** Namespace for regions of interest (ROI).
Expand Down
44 changes: 38 additions & 6 deletions src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,19 @@ 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;
}

return dataset;
}


/** 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
Expand All @@ -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,
};

0 comments on commit 00c42dd

Please sign in to comment.