* fix: 🐛 Update ohif pdf extension to optionally use pdfjs Update ohif pdf extension of optionally use pdfjs Closes: #1049 * Update branch and fix scrolling * Dynamically import component * Fix wrong file change * Fix import * Add multi opened pdf configuration * Refactor connected component * Specify worker explicitly * Specify worker explicitly * CR Update: Remove dead code * CR Update: Refactor state * CR Update: use refs * CR Update: use refs
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
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 { DicomLoaderService } = OHIF.utils;
|
|
|
|
class OHIFDicomPDFViewport extends Component {
|
|
static propTypes = {
|
|
studies: PropTypes.object,
|
|
displaySet: PropTypes.object,
|
|
viewportIndex: PropTypes.number,
|
|
viewportData: PropTypes.object,
|
|
activeViewportIndex: PropTypes.number,
|
|
setViewportActive: PropTypes.func,
|
|
};
|
|
|
|
state = {
|
|
byteArray: null,
|
|
error: null,
|
|
};
|
|
|
|
static id = 'DicomPDFViewportPDF';
|
|
|
|
static init() {
|
|
console.log('DicomPDFViewport init()');
|
|
}
|
|
|
|
static destroy() {
|
|
console.log('DicomPDFViewport destroy()');
|
|
}
|
|
|
|
componentDidMount() {
|
|
const { displaySet, studies } = this.props.viewportData;
|
|
DicomLoaderService.findDicomDataPromise(displaySet, studies).then(
|
|
data => this.setState({ byteArray: new Uint8Array(data) }),
|
|
error => {
|
|
this.setState({ error });
|
|
throw new Error(error);
|
|
}
|
|
);
|
|
}
|
|
|
|
render() {
|
|
const {
|
|
setViewportActive,
|
|
viewportIndex,
|
|
activeViewportIndex,
|
|
} = this.props;
|
|
const { byteArray, error } = this.state;
|
|
const { id, init, destroy } = OHIFDicomPDFViewport;
|
|
const pluginProps = { id, init, destroy };
|
|
|
|
return (
|
|
<OHIFComponentPlugin {...pluginProps}>
|
|
{byteArray && (
|
|
<DicomPDFViewport
|
|
byteArray={byteArray}
|
|
setViewportActive={setViewportActive}
|
|
viewportIndex={viewportIndex}
|
|
activeViewportIndex={activeViewportIndex}
|
|
/>
|
|
)}
|
|
{error && <h2>{JSON.stringify(error)}</h2>}
|
|
</OHIFComponentPlugin>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default OHIFDicomPDFViewport;
|