Moved the Cornerstone viewport code to an extension. Tons of changes to rollup and package.json files to make everything play nicely
This commit is contained in:
1 parent
9a0f417eec
commit
22202141b8
45 files changed
+6193
-208
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import React, { Component } from 'react';
|
||||
import dicomParser from 'dicom-parser';
|
||||
import TypedArrayProp from './TypedArrayProp';
|
||||
|
||||
// TODO: Should probably use dcmjs for this
|
||||
const SOP_CLASS_UIDS = {
|
||||
ENCAPSULATED_PDF: '1.2.840.10008.5.1.4.1.1.104.1'
|
||||
};
|
||||
|
||||
class DicomPDFViewport extends Component {
|
||||
state = {
|
||||
fileURL: null,
|
||||
error: null
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
byteArray: TypedArrayProp.uint8
|
||||
};
|
||||
|
||||
renderPDF = dataSet => {
|
||||
const sopClassUid = dataSet.string('x00080016');
|
||||
|
||||
if (sopClassUid !== SOP_CLASS_UIDS.ENCAPSULATED_PDF) {
|
||||
throw new Error('This is not a DICOM-encapsulated PDF');
|
||||
}
|
||||
|
||||
const fileTag = dataSet.elements.x00420011;
|
||||
const offset = fileTag.dataOffset;
|
||||
const remainder = offset + fileTag.length;
|
||||
const pdfByteArray = dataSet.byteArray.slice(offset, remainder);
|
||||
const PDF = new Blob([pdfByteArray], { type: 'application/pdf' });
|
||||
const fileURL = URL.createObjectURL(PDF);
|
||||
|
||||
this.setState({
|
||||
fileURL
|
||||
});
|
||||
};
|
||||
|
||||
parseByteArray = byteArray => {
|
||||
const options = {
|
||||
untilTag: ''
|
||||
};
|
||||
|
||||
let dataSet;
|
||||
|
||||
try {
|
||||
dataSet = dicomParser.parseDicom(byteArray, options);
|
||||
} catch (error) {
|
||||
this.setState({
|
||||
error
|
||||
});
|
||||
}
|
||||
|
||||
return dataSet;
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
const dataSet = this.parseByteArray(this.props.byteArray);
|
||||
|
||||
this.renderPDF(dataSet);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
className={'DicomPDFViewport'}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
>
|
||||
{this.state.fileURL && (
|
||||
<object
|
||||
data={this.state.fileURL}
|
||||
type="application/pdf"
|
||||
width="100%"
|
||||
height="100%"
|
||||
/>
|
||||
)}
|
||||
{this.state.error && <h2>{JSON.stringify(this.state.error)}</h2>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default DicomPDFViewport;
|
||||
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
function OHIFComponentPlugin(props) {
|
||||
return (<React.Fragment>{props.children}</React.Fragment>);
|
||||
}
|
||||
|
||||
OHIFComponentPlugin.propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
init: PropTypes.func.isRequired,
|
||||
destroy: PropTypes.func.isRequired,
|
||||
children: PropTypes.node
|
||||
};
|
||||
|
||||
export default OHIFComponentPlugin;
|
||||
@@ -0,0 +1,27 @@
|
||||
import OHIFDicomPDFViewport from './OHIFDicomPDFViewport.js';
|
||||
import OHIFDicomPDFSopClassHandler from './OHIFDicomPDFSopClassHandler.js';
|
||||
|
||||
export default class OHIFDicomPDFExtension {
|
||||
/**
|
||||
* Extension ID is a unique id, might be used for namespacing extension specific redux actions/reducers (?)
|
||||
*/
|
||||
getExtensionId() {
|
||||
return 'pdf';
|
||||
}
|
||||
|
||||
getViewportModule() {
|
||||
return OHIFDicomPDFViewport;
|
||||
}
|
||||
|
||||
getSopClassHandler() {
|
||||
return OHIFDicomPDFSopClassHandler;
|
||||
}
|
||||
|
||||
getPanelModuleDefinition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
getToolbarModuleDefinition() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import OHIF from "ohif-core";
|
||||
|
||||
const { plugins, utils } = OHIF;
|
||||
const { PLUGIN_TYPES } = plugins;
|
||||
|
||||
// TODO: Should probably use dcmjs for this
|
||||
const SOP_CLASS_UIDS = {
|
||||
ENCAPSULATED_PDF: '1.2.840.10008.5.1.4.1.1.104.1'
|
||||
};
|
||||
|
||||
const OHIFDicomPDFSopClassHandler = {
|
||||
id: 'OHIFDicomPDFSopClassHandlerPlugin',
|
||||
type: PLUGIN_TYPES.SOP_CLASS_HANDLER,
|
||||
sopClassUids: [
|
||||
SOP_CLASS_UIDS.ENCAPSULATED_PDF
|
||||
],
|
||||
getDisplaySetFromSeries(series, study, dicomWebClient, authorizationHeaders) {
|
||||
debugger;
|
||||
const instance = series.getFirstInstance();
|
||||
|
||||
return {
|
||||
plugin: 'pdf',
|
||||
displaySetInstanceUid: utils.guid(),
|
||||
wadoRoot: study.getData().wadoRoot,
|
||||
wadoUri: instance.getData().wadouri,
|
||||
sopInstanceUid: instance.getSOPInstanceUID(),
|
||||
seriesInstanceUid: series.getSeriesInstanceUID(),
|
||||
studyInstanceUid: study.getStudyInstanceUID(),
|
||||
authorizationHeaders: authorizationHeaders
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default OHIFDicomPDFSopClassHandler;
|
||||
@@ -0,0 +1,76 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import OHIF from 'ohif-core';
|
||||
import OHIFComponentPlugin from './OHIFComponentPlugin.js';
|
||||
import DicomPDFViewport from './DicomPDFViewport';
|
||||
|
||||
const { DICOMWeb } = OHIF;
|
||||
|
||||
class OHIFDicomPDFViewport extends Component {
|
||||
static propTypes = {
|
||||
studies: PropTypes.object,
|
||||
displaySet: PropTypes.object,
|
||||
viewportIndex: PropTypes.number
|
||||
};
|
||||
|
||||
state = {
|
||||
byteArray: null,
|
||||
error: null
|
||||
};
|
||||
|
||||
static id = 'DicomPDFViewportPDF';
|
||||
|
||||
static init() {
|
||||
console.log('DicomPDFViewport init()');
|
||||
}
|
||||
|
||||
static destroy() {
|
||||
console.log('DicomPDFViewport destroy()');
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { displaySet } = this.props.viewportData;
|
||||
const { studyInstanceUid, seriesInstanceUid, sopInstanceUid, wadoRoot, wadoUri, authorizationHeaders} = displaySet;
|
||||
|
||||
this.retrieveDicomData(studyInstanceUid, seriesInstanceUid, sopInstanceUid, wadoRoot, wadoUri, authorizationHeaders).then(byteArray => {
|
||||
this.setState({
|
||||
byteArray
|
||||
});
|
||||
}, error => {
|
||||
this.setState({
|
||||
error
|
||||
});
|
||||
|
||||
throw new Error(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
retrieveDicomData(studyInstanceUid, seriesInstanceUid, sopInstanceUid, wadoRoot, wadoUri, authorizationHeaders) {
|
||||
// TODO: Passing in a lot of data we aren't using
|
||||
|
||||
// TODO: Authorization header depends on the server. If we ever have multiple servers
|
||||
// we will need to figure out how / when to pass this information in.
|
||||
return fetch(wadoUri, {
|
||||
headers: authorizationHeaders
|
||||
}).then(response => response.arrayBuffer()).then(arraybuffer => {
|
||||
return new Uint8Array(arraybuffer);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { id, init, destroy } = OHIFDicomPDFViewport;
|
||||
const pluginProps = { id, init, destroy };
|
||||
|
||||
return (
|
||||
<OHIFComponentPlugin {...pluginProps}>
|
||||
{this.state.byteArray && (
|
||||
<DicomPDFViewport byteArray={this.state.byteArray} />
|
||||
)}
|
||||
{this.state.error && <h2>{JSON.stringify(this.state.error)}</h2>}
|
||||
</OHIFComponentPlugin>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default OHIFDicomPDFViewport;
|
||||
@@ -0,0 +1,137 @@
|
||||
// https://github.com/facebook/prop-types/issues/69
|
||||
|
||||
export const TypedArrayProp = {
|
||||
any: (props, propName, componentName) => {
|
||||
let obj = props[propName];
|
||||
if (!(obj instanceof Float64Array ||
|
||||
obj instanceof Float32Array ||
|
||||
obj instanceof Int32Array ||
|
||||
obj instanceof Int16Array ||
|
||||
obj instanceof Int8Array ||
|
||||
obj instanceof Uint32Array ||
|
||||
obj instanceof Uint16Array ||
|
||||
obj instanceof Uint8Array ||
|
||||
obj instanceof Uint8ClampedArray)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a typed array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
float64: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Float64Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Float64Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
float32: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Float32Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Float32Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
float: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Float64Array ||
|
||||
props[propName] instanceof Float32Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Float32Array or Float64Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
int32: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Int32Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected an Int32Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
int16: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Int16Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected an In16Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
int8: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Int8Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected an Int8Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
int: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Int32Array ||
|
||||
props[propName] instanceof Int16Array ||
|
||||
props[propName] instanceof Int8Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected an Int32Array, In16Array, or Int8Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
uint32: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Uint32Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Uint32Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
uint16: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Uint16Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Uint16Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
uint8: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Uint8Array)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Uint8Array.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
uint8clamped: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Uint8ClampedArray)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Uint8ClampedArray.'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
uint: (props, propName, componentName) => {
|
||||
if (!(props[propName] instanceof Uint32Array ||
|
||||
props[propName] instanceof Uint16Array ||
|
||||
props[propName] instanceof Uint8Array ||
|
||||
props[propName] instanceof Uint8ClampedArray)) {
|
||||
return new Error(
|
||||
'Invalid prop `' + propName + '` supplied to' +
|
||||
' `' + componentName + '`. Expected a Uint32Array, Uint16Array, Uint8Array, or Uint8ClampedArray.'
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export { TypedArrayProp as default };
|
||||
@@ -0,0 +1,3 @@
|
||||
import OHIFDicomPDFExtension from './OHIFDicomPDFExtension.js';
|
||||
|
||||
export default OHIFDicomPDFExtension;
|
||||
Reference in new issue
Block a user