init
This commit is contained in:
70
extensions/dicom-pdf/src/getSopClassHandlerModule.js
Normal file
70
extensions/dicom-pdf/src/getSopClassHandlerModule.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import { SOPClassHandlerId } from './id';
|
||||
import { utils, classes } from '@ohif/core';
|
||||
|
||||
const { ImageSet } = classes;
|
||||
|
||||
const SOP_CLASS_UIDS = {
|
||||
ENCAPSULATED_PDF: '1.2.840.10008.5.1.4.1.1.104.1',
|
||||
};
|
||||
|
||||
const sopClassUids = Object.values(SOP_CLASS_UIDS);
|
||||
|
||||
const _getDisplaySetsFromSeries = (instances, servicesManager, extensionManager) => {
|
||||
const dataSource = extensionManager.getActiveDataSource()[0];
|
||||
return instances.map(instance => {
|
||||
const { Modality, SOPInstanceUID } = instance;
|
||||
const { SeriesDescription = 'PDF', MIMETypeOfEncapsulatedDocument } = instance;
|
||||
const { SeriesNumber, SeriesDate, SeriesInstanceUID, StudyInstanceUID, SOPClassUID } = instance;
|
||||
const pdfUrl = dataSource.retrieve.directURL({
|
||||
instance,
|
||||
tag: 'EncapsulatedDocument',
|
||||
defaultType: MIMETypeOfEncapsulatedDocument || 'application/pdf',
|
||||
singlepart: 'pdf',
|
||||
});
|
||||
|
||||
const displaySet = {
|
||||
//plugin: id,
|
||||
Modality,
|
||||
displaySetInstanceUID: utils.guid(),
|
||||
SeriesDescription,
|
||||
SeriesNumber,
|
||||
SeriesDate,
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
StudyInstanceUID,
|
||||
SOPClassHandlerId,
|
||||
SOPClassUID,
|
||||
referencedImages: null,
|
||||
measurements: null,
|
||||
pdfUrl,
|
||||
instances: [instance],
|
||||
thumbnailSrc: dataSource.retrieve.directURL({
|
||||
instance,
|
||||
defaultPath: '/thumbnail',
|
||||
defaultType: 'image/jpeg',
|
||||
tag: 'Absent',
|
||||
}),
|
||||
isDerivedDisplaySet: true,
|
||||
isLoaded: false,
|
||||
sopClassUids,
|
||||
numImageFrames: 0,
|
||||
numInstances: 1,
|
||||
instance,
|
||||
};
|
||||
return displaySet;
|
||||
});
|
||||
};
|
||||
|
||||
export default function getSopClassHandlerModule({ servicesManager, extensionManager }) {
|
||||
const getDisplaySetsFromSeries = instances => {
|
||||
return _getDisplaySetsFromSeries(instances, servicesManager, extensionManager);
|
||||
};
|
||||
|
||||
return [
|
||||
{
|
||||
name: 'dicom-pdf',
|
||||
sopClassUids,
|
||||
getDisplaySetsFromSeries,
|
||||
},
|
||||
];
|
||||
}
|
||||
6
extensions/dicom-pdf/src/id.js
Normal file
6
extensions/dicom-pdf/src/id.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import packageJson from '../package.json';
|
||||
|
||||
const id = packageJson.name;
|
||||
const SOPClassHandlerId = `${id}.sopClassHandlerModule.dicom-pdf`;
|
||||
|
||||
export { id, SOPClassHandlerId };
|
||||
47
extensions/dicom-pdf/src/index.tsx
Normal file
47
extensions/dicom-pdf/src/index.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import getSopClassHandlerModule from './getSopClassHandlerModule';
|
||||
import { id } from './id.js';
|
||||
|
||||
const Component = React.lazy(() => {
|
||||
return import(/* webpackPrefetch: true */ './viewports/OHIFCornerstonePdfViewport');
|
||||
});
|
||||
|
||||
const OHIFCornerstonePdfViewport = props => {
|
||||
return (
|
||||
<React.Suspense fallback={<div>Loading...</div>}>
|
||||
<Component {...props} />
|
||||
</React.Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const dicomPDFExtension = {
|
||||
/**
|
||||
* Only required property. Should be a unique value across all extensions.
|
||||
*/
|
||||
id,
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {object} [configuration={}]
|
||||
* @param {object|array} [configuration.csToolsConfig] - Passed directly to `initCornerstoneTools`
|
||||
*/
|
||||
getViewportModule({ servicesManager, extensionManager }) {
|
||||
const ExtendedOHIFCornerstonePdfViewport = props => {
|
||||
return (
|
||||
<OHIFCornerstonePdfViewport
|
||||
servicesManager={servicesManager}
|
||||
extensionManager={extensionManager}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
return [{ name: 'dicom-pdf', component: ExtendedOHIFCornerstonePdfViewport }];
|
||||
},
|
||||
getSopClassHandlerModule,
|
||||
};
|
||||
|
||||
export default dicomPDFExtension;
|
||||
@@ -0,0 +1,11 @@
|
||||
.pdf-no-click {
|
||||
pointer-events: none;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.pdf-yes-click {
|
||||
pointer-events: auto;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import './OHIFCornerstonePdfViewport.css';
|
||||
|
||||
function OHIFCornerstonePdfViewport({ displaySets }) {
|
||||
const [url, setUrl] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
document.body.addEventListener('drag', makePdfDropTarget);
|
||||
return function cleanup() {
|
||||
document.body.removeEventListener('drag', makePdfDropTarget);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const [style, setStyle] = useState('pdf-yes-click');
|
||||
|
||||
const makePdfScrollable = () => {
|
||||
setStyle('pdf-yes-click');
|
||||
};
|
||||
|
||||
const makePdfDropTarget = () => {
|
||||
setStyle('pdf-no-click');
|
||||
};
|
||||
|
||||
if (displaySets && displaySets.length > 1) {
|
||||
throw new Error(
|
||||
'OHIFCornerstonePdfViewport: only one display set is supported for dicom pdf right now'
|
||||
);
|
||||
}
|
||||
|
||||
const { pdfUrl } = displaySets[0];
|
||||
|
||||
useEffect(() => {
|
||||
const load = async () => {
|
||||
setUrl(await pdfUrl);
|
||||
};
|
||||
|
||||
load();
|
||||
}, [pdfUrl]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="bg-primary-black h-full w-full text-white"
|
||||
onClick={makePdfScrollable}
|
||||
>
|
||||
<object
|
||||
data={url}
|
||||
type="application/pdf"
|
||||
className={style}
|
||||
>
|
||||
<div>No online PDF viewer installed</div>
|
||||
</object>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
OHIFCornerstonePdfViewport.propTypes = {
|
||||
displaySets: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
};
|
||||
|
||||
export default OHIFCornerstonePdfViewport;
|
||||
Reference in New Issue
Block a user