Instance metadata/metadata providers overhaul (#1481)
* Instance metadata plus metadata provider overhaul. Fix consumption of wado-uri urls fallbacks + datatype agnosticism. WIP DICOMify things. fix various issues with naturalized variable naming migration. Remove metadata provider. Fix consumption of multiframe images and addition of CWIL metadata. Fix strange build issues. Fix CWIL style windowWidth to array from naturalized DICOM. Fix PT, CT, CR and DX issues for cornerstone + DX issues for vtkjs. Move color palette fetching down to the natuaralized JSON level. Remove unused StudyMetadataSummary Remove redundant dicom metadata dictionary. Working local + json routes. Fix SR read. Finished first round of testing + cleaned up debugging etc. * data => metadata for instance naturalizedJSON * Update dcmjs version * Correct github isssues. * Fix erroneously replaced files. * Danny's recommended changes. * Instance metadata plus metadata provider overhaul. Fix consumption of wado-uri urls fallbacks + datatype agnosticism. WIP DICOMify things. fix various issues with naturalized variable naming migration. Remove metadata provider. Fix consumption of multiframe images and addition of CWIL metadata. Fix strange build issues. Fix CWIL style windowWidth to array from naturalized DICOM. Fix PT, CT, CR and DX issues for cornerstone + DX issues for vtkjs. Move color palette fetching down to the natuaralized JSON level. Remove unused StudyMetadataSummary Remove redundant dicom metadata dictionary. Working local + json routes. Fix SR read. Finished first round of testing + cleaned up debugging etc. * data => metadata for instance naturalizedJSON * Update dcmjs version * Correct github isssues. * Fix erroneously replaced files. * Danny's recommended changes. * Update JSON CI * Update casing of import. * Fix jump for SR. * Fix unit tests for measurements service * Fix json CI test. * fix: update yarn lock * Fix local non-encapsulated pdf view * CI updated to new sucess message. Co-authored-by: Danny <danny.ri.brown@gmail.com>
This commit is contained in:
1 parent
8833731ad3
commit
1d85f7a74e
142 files changed
+5322
-8570
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,9 +1,9 @@
|
||||
import OHIFError from '../classes/OHIFError.js';
|
||||
import getImageId from './getImageId';
|
||||
import metadataProvider from '../classes/MetadataProvider.js';
|
||||
|
||||
let stackMap = {};
|
||||
let configuration = {};
|
||||
let stackManagerMetaDataProvider;
|
||||
const stackUpdatedCallbacks = [];
|
||||
|
||||
/**
|
||||
@@ -15,13 +15,7 @@ const stackUpdatedCallbacks = [];
|
||||
* @param {Object} displaySet The set of images to make the stack from
|
||||
* @return {Array} Array with image IDs
|
||||
*/
|
||||
function createAndAddStack(
|
||||
stackMap,
|
||||
study,
|
||||
displaySet,
|
||||
stackUpdatedCallbacks,
|
||||
metadataProvider
|
||||
) {
|
||||
function createAndAddStack(stackMap, study, displaySet, stackUpdatedCallbacks) {
|
||||
const images = displaySet.images;
|
||||
if (!images) {
|
||||
return;
|
||||
@@ -41,31 +35,56 @@ function createAndAddStack(
|
||||
imageIndex: imageIndex + 1,
|
||||
};
|
||||
|
||||
const numberOfFrames = image.numberOfFrames;
|
||||
if (numberOfFrames > 1) {
|
||||
for (let i = 0; i < numberOfFrames; i++) {
|
||||
const NumberOfFrames = image.NumberOfFrames;
|
||||
|
||||
if (NumberOfFrames > 1) {
|
||||
for (let i = 0; i < NumberOfFrames; i++) {
|
||||
metaData.frameNumber = i;
|
||||
imageId = getImageId(image, i);
|
||||
imageIds.push(imageId);
|
||||
metadataProvider.addMetadata(imageId, metaData);
|
||||
|
||||
const {
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
} = instance.getData().metadata;
|
||||
|
||||
metadataProvider.addImageIdToUIDs(imageId, {
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
metaData.frameNumber = 1;
|
||||
imageId = getImageId(image);
|
||||
imageIds.push(imageId);
|
||||
metadataProvider.addMetadata(imageId, metaData);
|
||||
|
||||
const naturalizedInstance = instance.getData().metadata;
|
||||
|
||||
const {
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
} = naturalizedInstance;
|
||||
|
||||
metadataProvider.addImageIdToUIDs(imageId, {
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const stack = {
|
||||
studyInstanceUid: study.studyInstanceUid,
|
||||
displaySetInstanceUid: displaySet.displaySetInstanceUid,
|
||||
StudyInstanceUID: study.StudyInstanceUID,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
imageIds,
|
||||
frameRate: displaySet.frameRate,
|
||||
isClip: displaySet.isClip,
|
||||
};
|
||||
|
||||
stackMap[displaySet.displaySetInstanceUid] = stack;
|
||||
stackMap[displaySet.displaySetInstanceUID] = stack;
|
||||
|
||||
return stack;
|
||||
}
|
||||
@@ -80,9 +99,6 @@ configuration = {
|
||||
* come in, you can register a callback with addStackUpdatedCallback.
|
||||
*/
|
||||
const StackManager = {
|
||||
setMetadataProvider(provider) {
|
||||
stackManagerMetaDataProvider = provider;
|
||||
},
|
||||
/**
|
||||
* Removes all current stacks
|
||||
*/
|
||||
@@ -96,27 +112,20 @@ const StackManager = {
|
||||
* @return {Array} Array with image IDs
|
||||
*/
|
||||
makeAndAddStack(study, displaySet) {
|
||||
if (!stackManagerMetaDataProvider) {
|
||||
throw new Error(
|
||||
'Please call StackManager.setMetadataProvider(provider) first.'
|
||||
);
|
||||
}
|
||||
|
||||
return configuration.createAndAddStack(
|
||||
stackMap,
|
||||
study,
|
||||
displaySet,
|
||||
stackUpdatedCallbacks,
|
||||
stackManagerMetaDataProvider
|
||||
stackUpdatedCallbacks
|
||||
);
|
||||
},
|
||||
/**
|
||||
* Find a stack from the currently created stacks.
|
||||
* @param displaySetInstanceUid The UID of the stack to find.
|
||||
* @param displaySetInstanceUID The UID of the stack to find.
|
||||
* @returns {*} undefined if not found, otherwise the stack object is returned.
|
||||
*/
|
||||
findStack(displaySetInstanceUid) {
|
||||
return stackMap[displaySetInstanceUid];
|
||||
findStack(displaySetInstanceUID) {
|
||||
return stackMap[displaySetInstanceUID];
|
||||
},
|
||||
/**
|
||||
* Find a stack or reate one if it has not been created yet
|
||||
@@ -125,7 +134,7 @@ const StackManager = {
|
||||
* @return {Array} Array with image IDs
|
||||
*/
|
||||
findOrCreateStack(study, displaySet) {
|
||||
let stack = this.findStack(displaySet.displaySetInstanceUid);
|
||||
let stack = this.findStack(displaySet.displaySetInstanceUID);
|
||||
|
||||
if (!stack || !stack.imageIds) {
|
||||
stack = this.makeAndAddStack(study, displaySet);
|
||||
@@ -134,9 +143,9 @@ const StackManager = {
|
||||
return stack;
|
||||
},
|
||||
/**
|
||||
* Gets the underlying map of displaySetInstanceUid to stack object.
|
||||
* Gets the underlying map of displaySetInstanceUID to stack object.
|
||||
* WARNING: Do not change this object. It directly affects the manager.
|
||||
* @returns {{}} map of displaySetInstanceUid -> stack.
|
||||
* @returns {{}} map of displaySetInstanceUID -> stack.
|
||||
*/
|
||||
getAllStacks() {
|
||||
return stackMap;
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
// {
|
||||
// getInstanceCount: jest.fn().mockReturnValue(1),
|
||||
// getData: jest.fn().mockReturnValue({
|
||||
// seriesDate: '2019-06-04',
|
||||
// SeriesDate: '2019-06-04',
|
||||
// }),
|
||||
// },
|
||||
// {
|
||||
// getInstanceCount: jest.fn().mockReturnValue(1),
|
||||
// getData: jest.fn().mockReturnValue({
|
||||
// seriesDate: '2018-06-04',
|
||||
// SeriesDate: '2018-06-04',
|
||||
// }),
|
||||
// },
|
||||
// ];
|
||||
@@ -25,7 +25,7 @@
|
||||
// getStudyInstanceUID: jest.fn(),
|
||||
// };
|
||||
|
||||
// it('sorts displaySets by seriesNumber, then by seriesDate', () => {
|
||||
// it('sorts displaySets by SeriesNumber, then by SeriesDate', () => {
|
||||
// const displaySets = createStacks(studyMetadata);
|
||||
|
||||
// expect(displaySets.length).toBe(2);
|
||||
|
||||
@@ -13,15 +13,15 @@ const getImageId = imageObj => {
|
||||
: imageObj.url;
|
||||
};
|
||||
|
||||
const findImageIdOnStudies = (studies, displaySetInstanceUid) => {
|
||||
const findImageIdOnStudies = (studies, displaySetInstanceUID) => {
|
||||
const study = studies.find(study => {
|
||||
const displaySet = study.displaySets.some(
|
||||
displaySet => displaySet.displaySetInstanceUid === displaySetInstanceUid
|
||||
displaySet => displaySet.displaySetInstanceUID === displaySetInstanceUID
|
||||
);
|
||||
return displaySet;
|
||||
});
|
||||
const { seriesList = [] } = study;
|
||||
const { instances = [] } = seriesList[0] || {};
|
||||
const { series = [] } = study;
|
||||
const { instances = [] } = series[0] || {};
|
||||
const instance = instances[0];
|
||||
|
||||
return getImageId(instance);
|
||||
@@ -85,7 +85,7 @@ const getImageLoaderType = imageId => {
|
||||
);
|
||||
};
|
||||
|
||||
const DicomLoaderService = new (class {
|
||||
class DicomLoaderService {
|
||||
getLocalData(dataset, studies) {
|
||||
if (dataset && dataset.localFile) {
|
||||
// Use referenced imageInstance
|
||||
@@ -94,7 +94,7 @@ const DicomLoaderService = new (class {
|
||||
|
||||
// or Try to get it from studies
|
||||
if (someInvalidStrings(imageId)) {
|
||||
imageId = findImageIdOnStudies(studies, dataset.displaySetInstanceUid);
|
||||
imageId = findImageIdOnStudies(studies, dataset.displaySetInstanceUID);
|
||||
}
|
||||
|
||||
if (!someInvalidStrings(imageId)) {
|
||||
@@ -155,9 +155,9 @@ const DicomLoaderService = new (class {
|
||||
|
||||
getDataByDatasetType(dataset) {
|
||||
const {
|
||||
studyInstanceUid,
|
||||
seriesInstanceUid,
|
||||
sopInstanceUid,
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
authorizationHeaders,
|
||||
wadoRoot,
|
||||
wadoUri,
|
||||
@@ -166,9 +166,9 @@ const DicomLoaderService = new (class {
|
||||
if (!someInvalidStrings(wadoRoot)) {
|
||||
return wadorsRetriever(
|
||||
wadoRoot,
|
||||
studyInstanceUid,
|
||||
seriesInstanceUid,
|
||||
sopInstanceUid,
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
authorizationHeaders
|
||||
);
|
||||
} else if (!someInvalidStrings(wadoUri)) {
|
||||
@@ -194,6 +194,8 @@ const DicomLoaderService = new (class {
|
||||
// in case of no valid loader
|
||||
throw new Error('Invalid dicom data loader');
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
export default DicomLoaderService;
|
||||
const dicomLoaderService = new DicomLoaderService();
|
||||
|
||||
export default dicomLoaderService;
|
||||
@@ -1,4 +1,3 @@
|
||||
import { DICOMTagDescriptions } from './DICOMTagDescriptions';
|
||||
import ObjectPath from './objectPath';
|
||||
import StackManager from './StackManager.js';
|
||||
import absoluteUrl from './absoluteUrl';
|
||||
@@ -6,7 +5,6 @@ import addServers from './addServers';
|
||||
import guid from './guid';
|
||||
import sortBy from './sortBy.js';
|
||||
import studyMetadataManager from './studyMetadataManager';
|
||||
import updateMetaDataManager from './updateMetaDataManager.js';
|
||||
import writeScript from './writeScript.js';
|
||||
import DicomLoaderService from './dicomLoaderService.js';
|
||||
import b64toBlob from './b64toBlob.js';
|
||||
@@ -24,9 +22,6 @@ const utils = {
|
||||
b64toBlob,
|
||||
StackManager,
|
||||
studyMetadataManager,
|
||||
// Updates WADO-RS metaDataManager
|
||||
updateMetaDataManager,
|
||||
DICOMTagDescriptions,
|
||||
DicomLoaderService,
|
||||
urlUtil,
|
||||
makeCancelable,
|
||||
@@ -43,9 +38,6 @@ export {
|
||||
b64toBlob,
|
||||
StackManager,
|
||||
studyMetadataManager,
|
||||
// Updates WADO-RS metaDataManager
|
||||
updateMetaDataManager,
|
||||
DICOMTagDescriptions,
|
||||
DicomLoaderService,
|
||||
urlUtil,
|
||||
makeCancelable,
|
||||
|
||||
@@ -12,9 +12,6 @@ describe('Top level exports', () => {
|
||||
'b64toBlob',
|
||||
'StackManager',
|
||||
'studyMetadataManager',
|
||||
// Updates WADO-RS metaDataManager
|
||||
'updateMetaDataManager',
|
||||
'DICOMTagDescriptions',
|
||||
'DicomLoaderService',
|
||||
'urlUtil',
|
||||
'makeCancelable',
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
/**
|
||||
* Checks if a series is reconstructable to a 3D volume.
|
||||
*
|
||||
* @param {Object} series The `OHIFSeriesMetadata` object.
|
||||
* @param {Object[]} instances The `OHIFInstanceMetadata` object
|
||||
* @param {Object[]} instances An array of `OHIFInstanceMetadata` objects.
|
||||
*/
|
||||
export default function isDisplaySetReconstructable(series, instances) {
|
||||
// Can't reconstruct if we only have one image.
|
||||
|
||||
const modality = series._data.modality; // TODO -> Is there a better way to get this?
|
||||
const isMultiframe = instances[0].getRawValue('x00280008') > 1;
|
||||
|
||||
if (!constructableModalities.includes(modality)) {
|
||||
export default function isDisplaySetReconstructable(instances) {
|
||||
if (!instances.length) {
|
||||
return { value: false };
|
||||
}
|
||||
|
||||
const firstInstance = instances[0].getData().metadata;
|
||||
|
||||
const Modality = firstInstance.Modality;
|
||||
const isMultiframe = firstInstance.NumberOfFrames > 1;
|
||||
|
||||
if (!constructableModalities.includes(Modality)) {
|
||||
return { value: false };
|
||||
}
|
||||
|
||||
// Can't reconstruct if we only have one image.
|
||||
if (!isMultiframe && instances.length === 1) {
|
||||
return { values: false };
|
||||
return { value: false };
|
||||
}
|
||||
|
||||
if (isMultiframe) {
|
||||
@@ -26,34 +30,36 @@ export default function isDisplaySetReconstructable(series, instances) {
|
||||
}
|
||||
|
||||
function processMultiframe(instance) {
|
||||
//TODO: deal with multriframe checks! return true for now.
|
||||
return { value: true };
|
||||
//TODO: deal with multriframe checks! return false for now as can't reconstruct.
|
||||
return { value: false };
|
||||
}
|
||||
|
||||
function processSingleframe(instances) {
|
||||
const firstImage = instances[0];
|
||||
const firstImageRows = firstImage.getTagValue('x00280010');
|
||||
const firstImageColumns = firstImage.getTagValue('x00280011');
|
||||
const firstImageSamplesPerPixel = firstImage.getTagValue('x00280002');
|
||||
// Note: No need to unpack iop, can compare string form.
|
||||
const firstImageOrientationPatient = firstImage.getTagValue('x00200037');
|
||||
const firstImage = instances[0].getData().metadata;
|
||||
const firstImageRows = firstImage.Rows;
|
||||
const firstImageColumns = firstImage.Columns;
|
||||
const firstImageSamplesPerPixel = firstImage.SamplesPerPixel;
|
||||
const firstImageOrientationPatient = firstImage.ImageOrientationPatient;
|
||||
const firstImagePositionPatient = firstImage.ImagePositionPatient;
|
||||
|
||||
// Can't reconstruct if we:
|
||||
// -- Have a different dimensions within a displaySet.
|
||||
// -- Have a different number of components within a displaySet.
|
||||
// -- Have different orientations within a displaySet.
|
||||
for (let i = 1; i < instances.length; i++) {
|
||||
const instance = instances[i];
|
||||
const rows = instance.getTagValue('x00280010');
|
||||
const columns = instance.getTagValue('x00280011');
|
||||
const samplesPerPixel = instance.getTagValue('x00280002');
|
||||
const imageOrientationPatient = instance.getTagValue('x00200037');
|
||||
const instance = instances[i].getData().metadata;
|
||||
const {
|
||||
Rows,
|
||||
Columns,
|
||||
SamplesPerPixel,
|
||||
ImageOrientationPatient,
|
||||
} = instance;
|
||||
|
||||
if (
|
||||
rows !== firstImageRows ||
|
||||
columns !== firstImageColumns ||
|
||||
samplesPerPixel !== firstImageSamplesPerPixel ||
|
||||
imageOrientationPatient !== firstImageOrientationPatient
|
||||
Rows !== firstImageRows ||
|
||||
Columns !== firstImageColumns ||
|
||||
SamplesPerPixel !== firstImageSamplesPerPixel ||
|
||||
!_isSameOrientation(ImageOrientationPatient, firstImageOrientationPatient)
|
||||
) {
|
||||
return { value: false };
|
||||
}
|
||||
@@ -61,28 +67,32 @@ function processSingleframe(instances) {
|
||||
|
||||
let missingFrames = 0;
|
||||
|
||||
// Check if frame spacing is approximately equal within a tolerance.
|
||||
// Check if frame spacing is approximately equal within a spacingTolerance.
|
||||
// If spacing is on a uniform grid but we are missing frames,
|
||||
// Allow reconstruction, but pass back the number of missing frames.
|
||||
if (instances.length > 2) {
|
||||
const firstIpp = _getImagePositionPatient(firstImage);
|
||||
const lastIpp = _getImagePositionPatient(instances[instances.length - 1]);
|
||||
const lastIpp = instances[instances.length - 1].getData().metadata
|
||||
.ImagePositionPatient;
|
||||
|
||||
// We can't reconstruct if we are missing imagePositionPatient values
|
||||
if (!firstIpp || !lastIpp) {
|
||||
// We can't reconstruct if we are missing ImagePositionPatient values
|
||||
if (!firstImagePositionPatient || !lastIpp) {
|
||||
return { value: false };
|
||||
}
|
||||
|
||||
const averageSpacingBetweenFrames =
|
||||
_getPerpendicularDistance(firstIpp, lastIpp) / (instances.length - 1);
|
||||
_getPerpendicularDistance(firstImagePositionPatient, lastIpp) /
|
||||
(instances.length - 1);
|
||||
|
||||
let previousIpp = firstIpp;
|
||||
let previousImagePositionPatient = firstImagePositionPatient;
|
||||
|
||||
for (let i = 1; i < instances.length; i++) {
|
||||
const instance = instances[i];
|
||||
const ipp = _getImagePositionPatient(instance);
|
||||
const instance = instances[i].getData().metadata;
|
||||
const { ImagePositionPatient } = instance;
|
||||
|
||||
const spacingBetweenFrames = _getPerpendicularDistance(ipp, previousIpp);
|
||||
const spacingBetweenFrames = _getPerpendicularDistance(
|
||||
ImagePositionPatient,
|
||||
previousImagePositionPatient
|
||||
);
|
||||
const spacingIssue = _getSpacingIssue(
|
||||
spacingBetweenFrames,
|
||||
averageSpacingBetweenFrames
|
||||
@@ -98,15 +108,28 @@ function processSingleframe(instances) {
|
||||
}
|
||||
}
|
||||
|
||||
previousIpp = ipp;
|
||||
previousImagePositionPatient = ImagePositionPatient;
|
||||
}
|
||||
}
|
||||
|
||||
return { value: true, missingFrames };
|
||||
}
|
||||
|
||||
// TODO: Is 10% a reasonable tolerance for spacing?
|
||||
const tolerance = 0.1;
|
||||
function _isSameOrientation(iop1, iop2) {
|
||||
if (iop1 === undefined || !iop2 === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
Math.abs(iop1[0] - iop2[0]) < iopTolerance &&
|
||||
Math.abs(iop1[1] - iop2[1]) < iopTolerance &&
|
||||
Math.abs(iop1[2] - iop2[2]) < iopTolerance
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Is 10% a reasonable spacingTolerance for spacing?
|
||||
const spacingTolerance = 0.1;
|
||||
const iopTolerance = 0.01;
|
||||
|
||||
/**
|
||||
* Checks for spacing issues.
|
||||
@@ -118,7 +141,7 @@ const tolerance = 0.1;
|
||||
*/
|
||||
function _getSpacingIssue(spacing, averageSpacing) {
|
||||
const equalWithinTolerance =
|
||||
Math.abs(spacing - averageSpacing) < averageSpacing * tolerance;
|
||||
Math.abs(spacing - averageSpacing) < averageSpacing * spacingTolerance;
|
||||
|
||||
if (equalWithinTolerance) {
|
||||
return;
|
||||
@@ -131,7 +154,7 @@ function _getSpacingIssue(spacing, averageSpacing) {
|
||||
const errorForEachSpacing =
|
||||
Math.abs(spacing - numberOfSpacings * averageSpacing) / numberOfSpacings;
|
||||
|
||||
if (errorForEachSpacing < tolerance * averageSpacing) {
|
||||
if (errorForEachSpacing < spacingTolerance * averageSpacing) {
|
||||
return {
|
||||
issue: reconstructionIssues.MISSING_FRAMES,
|
||||
missingFrames: numberOfSpacings - 1,
|
||||
@@ -141,18 +164,6 @@ function _getSpacingIssue(spacing, averageSpacing) {
|
||||
return { issue: reconstructionIssues.IRREGULAR_SPACING };
|
||||
}
|
||||
|
||||
function _getImagePositionPatient(instance) {
|
||||
const tagValue = instance
|
||||
.getTagValue('x00200032');
|
||||
if (!tagValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
return tagValue
|
||||
.split('\\')
|
||||
.map(element => Number(element));
|
||||
}
|
||||
|
||||
function _getPerpendicularDistance(a, b) {
|
||||
return Math.sqrt(
|
||||
Math.pow(a[0] - b[0], 2) +
|
||||
|
||||
@@ -53,10 +53,10 @@ const imagesTypes = [
|
||||
|
||||
/**
|
||||
* Checks whether dicom files with specified SOP Class UID have image data
|
||||
* @param {string} sopClassUid - SOP Class UID to be checked
|
||||
* @param {string} SOPClassUID - SOP Class UID to be checked
|
||||
* @returns {boolean} - true if it has image data
|
||||
*/
|
||||
export const isImage = sopClassUid => {
|
||||
if (!sopClassUid) return false;
|
||||
return imagesTypes.indexOf(sopClassUid) !== -1;
|
||||
export const isImage = SOPClassUID => {
|
||||
if (!SOPClassUID) return false;
|
||||
return imagesTypes.indexOf(SOPClassUID) !== -1;
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
const LOW_PRIORITY_MODALITIES = Object.freeze(['SEG', 'KO', 'PR']);
|
||||
|
||||
export default function isLowPriorityModality(modality) {
|
||||
return LOW_PRIORITY_MODALITIES.includes(modality);
|
||||
export default function isLowPriorityModality(Modality) {
|
||||
return LOW_PRIORITY_MODALITIES.includes(Modality);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import { api } from 'dicomweb-client';
|
||||
import DICOMWeb from '../../DICOMWeb';
|
||||
|
||||
export default async function fetchOverlayData(instance, server) {
|
||||
const OverlayDataPromises = [];
|
||||
const OverlayDataTags = [];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
for (let overlayGroup = 0x00; overlayGroup <= 0x1e; overlayGroup += 0x02) {
|
||||
let groupStr = `60${overlayGroup.toString(16)}`;
|
||||
|
||||
if (groupStr.length === 3) {
|
||||
groupStr = `600${overlayGroup.toString(16)}`;
|
||||
}
|
||||
|
||||
const OverlayDataTag = `${groupStr}3000`;
|
||||
|
||||
if (instance[OverlayDataTag] && instance[OverlayDataTag].BulkDataURI) {
|
||||
OverlayDataPromises.push(
|
||||
_getOverlayData(instance[OverlayDataTag], server)
|
||||
);
|
||||
OverlayDataTags.push(OverlayDataTag);
|
||||
}
|
||||
}
|
||||
|
||||
if (OverlayDataPromises.length) {
|
||||
Promise.all(OverlayDataPromises).then(results => {
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
instance[OverlayDataTags[i]] = results[i];
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function _getOverlayData(tag, server) {
|
||||
const { BulkDataURI } = tag;
|
||||
|
||||
let uri = BulkDataURI;
|
||||
|
||||
// TODO: Workaround for dcm4chee behind SSL-terminating proxy returning
|
||||
// incorrect bulk data URIs
|
||||
if (server.wadoRoot.indexOf('https') === 0 && !uri.includes('https')) {
|
||||
uri = uri.replace('http', 'https');
|
||||
}
|
||||
|
||||
const config = {
|
||||
url: server.wadoRoot, //BulkDataURI is absolute, so this isn't used
|
||||
headers: DICOMWeb.getAuthorizationHeader(server),
|
||||
};
|
||||
const dicomWeb = new api.DICOMwebClient(config);
|
||||
const options = {
|
||||
BulkDataURI: uri,
|
||||
};
|
||||
|
||||
return dicomWeb
|
||||
.retrieveBulkData(options)
|
||||
.then(result => result[0])
|
||||
.then(_unpackOverlay);
|
||||
}
|
||||
|
||||
function _unpackOverlay(arrayBuffer) {
|
||||
const bitArray = new Uint8Array(arrayBuffer);
|
||||
const byteArray = new Uint8Array(8 * bitArray.length);
|
||||
|
||||
for (let byteIndex = 0; byteIndex < byteArray.length; byteIndex++) {
|
||||
const bitIndex = byteIndex % 8;
|
||||
const bitByteIndex = Math.floor(byteIndex / 8);
|
||||
byteArray[byteIndex] =
|
||||
1 * ((bitArray[bitByteIndex] & (1 << bitIndex)) >> bitIndex);
|
||||
}
|
||||
|
||||
return byteArray;
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import { api } from 'dicomweb-client';
|
||||
import DICOMWeb from '../../DICOMWeb';
|
||||
|
||||
export default async function fetchPaletteColorLookupTableData(
|
||||
instance,
|
||||
server
|
||||
) {
|
||||
const {
|
||||
PaletteColorLookupTableUID,
|
||||
RedPaletteColorLookupTableDescriptor,
|
||||
GreenPaletteColorLookupTableDescriptor,
|
||||
BluePaletteColorLookupTableDescriptor,
|
||||
RedPaletteColorLookupTableData,
|
||||
GreenPaletteColorLookupTableData,
|
||||
BluePaletteColorLookupTableData,
|
||||
} = instance;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let entry;
|
||||
if (_paletteColorCache.isValidUID(PaletteColorLookupTableUID)) {
|
||||
entry = _paletteColorCache.get(PaletteColorLookupTableUID);
|
||||
|
||||
if (entry) {
|
||||
return resolve(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// no entry in cache... Fetch remote data.
|
||||
const promises = [
|
||||
_getPaletteColor(
|
||||
server,
|
||||
RedPaletteColorLookupTableData,
|
||||
RedPaletteColorLookupTableDescriptor
|
||||
),
|
||||
_getPaletteColor(
|
||||
server,
|
||||
GreenPaletteColorLookupTableData,
|
||||
GreenPaletteColorLookupTableDescriptor
|
||||
),
|
||||
_getPaletteColor(
|
||||
server,
|
||||
BluePaletteColorLookupTableData,
|
||||
BluePaletteColorLookupTableDescriptor
|
||||
),
|
||||
];
|
||||
|
||||
Promise.all(promises).then(
|
||||
([
|
||||
RedPaletteColorLookupTableData,
|
||||
GreenPaletteColorLookupTableData,
|
||||
BluePaletteColorLookupTableData,
|
||||
]) => {
|
||||
// when PaletteColorLookupTableUID is present, the entry can be cached...
|
||||
_paletteColorCache.add({
|
||||
RedPaletteColorLookupTableData,
|
||||
GreenPaletteColorLookupTableData,
|
||||
BluePaletteColorLookupTableData,
|
||||
PaletteColorLookupTableUID,
|
||||
});
|
||||
|
||||
instance.RedPaletteColorLookupTableData = RedPaletteColorLookupTableData;
|
||||
instance.GreenPaletteColorLookupTableData = GreenPaletteColorLookupTableData;
|
||||
instance.BluePaletteColorLookupTableData = BluePaletteColorLookupTableData;
|
||||
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple cache schema for retrieved color palettes.
|
||||
*/
|
||||
const _paletteColorCache = {
|
||||
count: 0,
|
||||
maxAge: 24 * 60 * 60 * 1000, // 24h cache?
|
||||
entries: {},
|
||||
isValidUID: function(PaletteColorLookupTableUID) {
|
||||
return (
|
||||
typeof PaletteColorLookupTableUID === 'string' &&
|
||||
PaletteColorLookupTableUID.length > 0
|
||||
);
|
||||
},
|
||||
get: function(PaletteColorLookupTableUID) {
|
||||
let entry = null;
|
||||
if (this.entries.hasOwnProperty(PaletteColorLookupTableUID)) {
|
||||
entry = this.entries[PaletteColorLookupTableUID];
|
||||
// check how the entry is...
|
||||
if (Date.now() - entry.time > this.maxAge) {
|
||||
// entry is too old... remove entry.
|
||||
delete this.entries[PaletteColorLookupTableUID];
|
||||
this.count--;
|
||||
entry = null;
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
},
|
||||
add: function(entry) {
|
||||
if (this.isValidUID(entry.uid)) {
|
||||
let PaletteColorLookupTableUID = entry.uid;
|
||||
if (this.entries.hasOwnProperty(PaletteColorLookupTableUID) !== true) {
|
||||
this.count++; // increment cache entry count...
|
||||
}
|
||||
entry.time = Date.now();
|
||||
this.entries[PaletteColorLookupTableUID] = entry;
|
||||
// @TODO: Add logic to get rid of old entries and reduce memory usage...
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function _getPaletteColor(server, paletteColorLookupTableData, lutDescriptor) {
|
||||
const numLutEntries = lutDescriptor[0];
|
||||
const bits = lutDescriptor[2];
|
||||
|
||||
const readUInt16 = (byteArray, position) => {
|
||||
return byteArray[position] + byteArray[position + 1] * 256;
|
||||
};
|
||||
|
||||
const arrayBufferToPaletteColorLUT = arraybuffer => {
|
||||
const byteArray = new Uint8Array(arraybuffer);
|
||||
const lut = [];
|
||||
|
||||
if (bits === 16) {
|
||||
for (let i = 0; i < numLutEntries; i++) {
|
||||
lut[i] = readUInt16(byteArray, i * 2);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < numLutEntries; i++) {
|
||||
lut[i] = byteArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
return lut;
|
||||
};
|
||||
|
||||
if (paletteColorLookupTableData.BulkDataURI) {
|
||||
let uri = paletteColorLookupTableData.BulkDataURI;
|
||||
|
||||
// TODO: Workaround for dcm4chee behind SSL-terminating proxy returning
|
||||
// incorrect bulk data URIs
|
||||
if (server.wadoRoot.indexOf('https') === 0 && !uri.includes('https')) {
|
||||
uri = uri.replace('http', 'https');
|
||||
}
|
||||
|
||||
const config = {
|
||||
url: server.wadoRoot, //BulkDataURI is absolute, so this isn't used
|
||||
headers: DICOMWeb.getAuthorizationHeader(server),
|
||||
};
|
||||
const dicomWeb = new api.DICOMwebClient(config);
|
||||
const options = {
|
||||
BulkDataURI: uri,
|
||||
};
|
||||
|
||||
return dicomWeb
|
||||
.retrieveBulkData(options)
|
||||
.then(result => result[0])
|
||||
.then(arrayBufferToPaletteColorLUT);
|
||||
} else if (paletteColorLookupTableData.InlineBinary) {
|
||||
const inlineBinaryData = atob(paletteColorLookupTableData.InlineBinary);
|
||||
const arraybuffer = _str2ab(inlineBinaryData);
|
||||
|
||||
return new Promise(resolve => {
|
||||
resolve(arrayBufferToPaletteColorLUT(arraybuffer));
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'Palette Color LUT was not provided as InlineBinary or BulkDataURI'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert String to ArrayBuffer
|
||||
*
|
||||
* @param {String} str Input String
|
||||
* @return {ArrayBuffer} Output converted ArrayBuffer
|
||||
*/
|
||||
function _str2ab(str) {
|
||||
const strLen = str.length;
|
||||
const bytes = new Uint8Array(strLen);
|
||||
|
||||
for (let i = 0; i < strLen; i++) {
|
||||
bytes[i] = str.charCodeAt(i);
|
||||
}
|
||||
|
||||
return bytes.buffer;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import log from '../../log';
|
||||
|
||||
function getFallbackTagFromInstance(tag, instance) {
|
||||
if (instance[tag]) {
|
||||
return instance[tag];
|
||||
}
|
||||
|
||||
const fallbackTags = fallbackTagsMap[tag];
|
||||
|
||||
if (fallbackTags) {
|
||||
for (let i = 0; i < fallbackTags.length; i++) {
|
||||
const fallbackTag = fallbackTags[i];
|
||||
|
||||
if (instance[fallbackTag]) {
|
||||
log.info(`metadata provider fallback tag ${tag} to ${fallbackTag}`);
|
||||
|
||||
return instance[fallbackTag];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackTagsMap = {
|
||||
PixelSpacing: ['ImagerPixelSpacing'],
|
||||
};
|
||||
|
||||
export { fallbackTagsMap, getFallbackTagFromInstance };
|
||||
@@ -1,109 +0,0 @@
|
||||
import { WadoRsMetaDataBuilder } from '../classes/metadata/WadoRsMetaDataBuilder';
|
||||
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
|
||||
import getWADORSImageId from './getWADORSImageId';
|
||||
|
||||
function getRadiopharmaceuticalInfoMetaData(instance) {
|
||||
const radiopharmaceuticalInfo = instance.radiopharmaceuticalInfo;
|
||||
|
||||
if (instance.modality !== 'PT' || !radiopharmaceuticalInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new WadoRsMetaDataBuilder()
|
||||
.addTag('00181072', radiopharmaceuticalInfo.radiopharmaceuticalStartTime)
|
||||
.addTag('00181074', radiopharmaceuticalInfo.radionuclideTotalDose)
|
||||
.addTag('00181075', radiopharmaceuticalInfo.radionuclideHalfLife)
|
||||
.toJSON();
|
||||
}
|
||||
|
||||
const getWadoRsInstanceMetaData = (study, series, instance) => {
|
||||
return new WadoRsMetaDataBuilder()
|
||||
.addTag('00080016', instance.sopClassUid)
|
||||
.addTag('00080018', instance.sopInstanceUid)
|
||||
.addTag('00080021', series.seriesDate)
|
||||
.addTag('00080031', series.seriesTime)
|
||||
.addTag('0008103e', series.seriesDescription)
|
||||
.addTag('00080060', series.modality)
|
||||
.addTag('00101010', study.patientAge)
|
||||
.addTag('00101020', study.patientSize)
|
||||
.addTag('00101030', study.patientWeight)
|
||||
.addTag('0020000d', study.studyInstanceUid)
|
||||
.addTag('00081030', study.studyDescription)
|
||||
.addTag('00100010', study.patientName)
|
||||
.addTag('00100020', study.patientId)
|
||||
.addTag('00080020', study.studyDate)
|
||||
.addTag('00080030', study.studyTime)
|
||||
.addTag('00080050', study.accessionNumber)
|
||||
.addTag('00200013', instance.instanceNumber)
|
||||
.addTag('00180050', instance.sliceThickness)
|
||||
.addTag('0020000e', series.seriesInstanceUid)
|
||||
.addTag('00200011', series.seriesNumber)
|
||||
.addTag('00200032', instance.imagePositionPatient, true)
|
||||
.addTag('00200037', instance.imageOrientationPatient, true)
|
||||
.addTag('00200052', instance.frameOfReferenceUID)
|
||||
.addTag('00201041', instance.sliceLocation)
|
||||
.addTag('00280002', instance.samplesPerPixel)
|
||||
.addTag('00280004', instance.photometricInterpretation)
|
||||
.addTag('00280006', instance.planarConfiguration)
|
||||
.addTag('00280010', instance.rows)
|
||||
.addTag('00280011', instance.columns)
|
||||
.addTag('00280030', instance.pixelSpacing, true)
|
||||
.addTag('00280034', instance.pixelAspectRatio, true)
|
||||
.addTag('00280100', instance.bitsAllocated)
|
||||
.addTag('00280101', instance.bitsStored)
|
||||
.addTag('00280102', instance.highBit)
|
||||
.addTag('00280103', instance.pixelRepresentation)
|
||||
.addTag('00280106', instance.smallestPixelValue)
|
||||
.addTag('00280107', instance.largestPixelValue)
|
||||
.addTag('00281050', instance.windowCenter, true)
|
||||
.addTag('00281051', instance.windowWidth, true)
|
||||
.addTag('00281052', instance.rescaleIntercept)
|
||||
.addTag('00281053', instance.rescaleSlope)
|
||||
.addTag('00281054', instance.rescaleType)
|
||||
.addTag('00281101', instance.redPaletteColorLookupTableDescriptor)
|
||||
.addTag('00281102', instance.greenPaletteColorLookupTableDescriptor)
|
||||
.addTag('00281103', instance.bluePaletteColorLookupTableDescriptor)
|
||||
.addTag('00281201', instance.redPaletteColorLookupTableData)
|
||||
.addTag('00281202', instance.greenPaletteColorLookupTableData)
|
||||
.addTag('00281203', instance.bluePaletteColorLookupTableData)
|
||||
.addTag('00540016', getRadiopharmaceuticalInfoMetaData(instance))
|
||||
.toJSON();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update metadata manager with instances of a specifc series
|
||||
* @param {Object} study A plain study descriptor object
|
||||
* @param {Object} series A Series descriptor object contaning the instances to be added to the manager
|
||||
*/
|
||||
function updateMetaDataManagerForSeries(study, series) {
|
||||
series.instances.forEach(instance => {
|
||||
const metaData = getWadoRsInstanceMetaData(study, series, instance);
|
||||
const numberOfFrames = instance.numberOfFrames || 1;
|
||||
|
||||
// We can share the same metaData with all frames because it doesn't have
|
||||
// any frame specific data, such as frameNumber, pixelData, offset, etc.
|
||||
// WADO-RS frame number is 1-based
|
||||
for (let frameNumber = 0; frameNumber < numberOfFrames; frameNumber++) {
|
||||
const imageId = getWADORSImageId(instance, frameNumber);
|
||||
|
||||
// TODO Make a metadata manager which uses study/series/instance UIDS instead of imageIds
|
||||
cornerstoneWADOImageLoader.wadors.metaDataManager.add(imageId, metaData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update metadata manager
|
||||
* @param {Object} study A plain study descriptor object
|
||||
* @param {string} [seriesInstanceUid] The Series Instance UID of the series to be added (Optional)
|
||||
*/
|
||||
export default function updateMetaDataManager(study, seriesInstanceUid) {
|
||||
if (seriesInstanceUid) {
|
||||
const series = study.seriesMap[seriesInstanceUid];
|
||||
updateMetaDataManagerForSeries(study, series);
|
||||
} else {
|
||||
study.seriesList.forEach(series => {
|
||||
updateMetaDataManagerForSeries(study, series);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user