Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | 34x 34x 34x 15288x 15288x 15288x 47x 47x 1x 47x 670736x 670736x 670736x 2768x 667968x 667968x 667968x 667968x 670736x 670736x 670736x 1337x 669399x 48x 48x 48x 6x 669393x 669393x 2768x 666625x 666625x 666625x 666625x 647373x 19252x 4547x 4547x 3645x 4547x 3645x 4547x 4547x 2042x 2042x 1380x 1380x 4x 1376x 1376x 1376x 1376x 4204x 4204x 1552x 2652x 2652x 1297x 1297x 329x 329x 5264x 5264x 2632x 5264x 5264x 5264x 5264x 329x 329x 657x 657x 1457x 1457x 3339x 14357x 2768x 2768x 2768x 670812x 668044x 668044x 668044x 2768x 2768x 2768x 2768x 2768x 2768x 2768x 2768x 2768x 34x 34x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 647373x 34x 34x | import queryString from 'query-string'; import dicomParser from 'dicom-parser'; import { utilities } from '@cornerstonejs/core'; import { imageIdToURI } from '../utils'; import DicomMetadataStore from '../services/DicomMetadataStore'; import fetchPaletteColorLookupTableData from '../utils/metadataProvider/fetchPaletteColorLookupTableData'; import toNumber from '../utils/toNumber'; import combineFrameInstance from '../utils/combineFrameInstance'; import formatPN from '../utils/formatPN'; const { calibratedPixelSpacingMetadataProvider, getPixelSpacingInformation } = utilities; class MetadataProvider { private readonly imageURIToUIDs: Map<string, any> = new Map(); // Can be used to store custom metadata for a specific type. // For instance, the scaling metadata for PET can be stored here // as type "scalingModule" private readonly customMetadata: Map<string, any> = new Map(); addImageIdToUIDs(imageId, uids) { Iif (!imageId) { throw new Error('MetadataProvider::Empty imageId'); } // This method is a fallback for when you don't have WADO-URI or WADO-RS. // You can add instances fetched by any method by calling addInstance, and hook an imageId to point at it here. // An example would be dicom hosted at some random site. const imageURI = imageIdToURI(imageId); this.imageURIToUIDs.set(imageURI, uids); } addCustomMetadata(imageId, type, metadata) { const imageURI = imageIdToURI(imageId); if (!this.customMetadata.has(type)) { this.customMetadata.set(type, {}); } this.customMetadata.get(type)[imageURI] = metadata; } _getInstance(imageId) { Iif (!imageId) { throw new Error('MetadataProvider::Empty imageId'); } const uids = this.getUIDsFromImageID(imageId); if (!uids) { return; } const { StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID, frameNumber } = uids; const instance = DicomMetadataStore.getInstance( StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID ); Iif (!instance) { return; } return (frameNumber && combineFrameInstance(frameNumber, instance)) || instance; } get(query, imageId, options = { fallback: false }) { Iif (Array.isArray(imageId)) { return; } const instance = this._getInstance(imageId); if (query === INSTANCE) { return instance; } // check inside custom metadata if (this.customMetadata.has(query)) { const customMetadata = this.customMetadata.get(query); const imageURI = imageIdToURI(imageId); if (customMetadata[imageURI]) { return customMetadata[imageURI]; } } return this.getTagFromInstance(query, instance, options); } getTag(query, imageId, options) { return this.get(query, imageId, options); } getInstance(imageId) { return this.get(INSTANCE, imageId); } getTagFromInstance(naturalizedTagOrWADOImageLoaderTag, instance, options = { fallback: false }) { if (!instance) { return; } // If its a naturalized dcmjs tag present on the instance, return. Iif (instance[naturalizedTagOrWADOImageLoaderTag]) { return instance[naturalizedTagOrWADOImageLoaderTag]; } // Maybe its a legacy dicomImageLoader tag then: return this._getCornerstoneDICOMImageLoaderTag(naturalizedTagOrWADOImageLoaderTag, instance); } /** * Adds a new handler for the given tag. The handler will be provided an * instance object that it can read values from. */ public addHandler(wadoImageLoaderTag: string, handler) { WADO_IMAGE_LOADER[wadoImageLoaderTag] = handler; } _getCornerstoneDICOMImageLoaderTag(wadoImageLoaderTag, instance) { let metadata = WADO_IMAGE_LOADER[wadoImageLoaderTag]?.(instance); if (metadata) { return metadata; } switch (wadoImageLoaderTag) { case WADO_IMAGE_LOADER_TAGS.GENERAL_SERIES_MODULE: const { SeriesDate, SeriesTime } = instance; let seriesDate; let seriesTime; if (SeriesDate) { seriesDate = dicomParser.parseDA(SeriesDate); } if (SeriesTime) { seriesTime = dicomParser.parseTM(SeriesTime); } metadata = { modality: instance.Modality, seriesInstanceUID: instance.SeriesInstanceUID, seriesNumber: toNumber(instance.SeriesNumber), studyInstanceUID: instance.StudyInstanceUID, seriesDate, seriesTime, }; break; case WADO_IMAGE_LOADER_TAGS.PATIENT_STUDY_MODULE: metadata = { patientAge: toNumber(instance.PatientAge), patientSize: toNumber(instance.PatientSize), patientWeight: toNumber(instance.PatientWeight), }; break; case WADO_IMAGE_LOADER_TAGS.PATIENT_DEMOGRAPHIC_MODULE: metadata = { patientSex: instance.PatientSex, }; break; case WADO_IMAGE_LOADER_TAGS.IMAGE_PIXEL_MODULE: metadata = { samplesPerPixel: toNumber(instance.SamplesPerPixel), photometricInterpretation: instance.PhotometricInterpretation, rows: toNumber(instance.Rows), columns: toNumber(instance.Columns), bitsAllocated: toNumber(instance.BitsAllocated), bitsStored: toNumber(instance.BitsStored), highBit: toNumber(instance.HighBit), pixelRepresentation: toNumber(instance.PixelRepresentation), planarConfiguration: toNumber(instance.PlanarConfiguration), pixelAspectRatio: toNumber(instance.PixelAspectRatio), smallestPixelValue: toNumber(instance.SmallestPixelValue), largestPixelValue: toNumber(instance.LargestPixelValue), redPaletteColorLookupTableDescriptor: toNumber( instance.RedPaletteColorLookupTableDescriptor ), greenPaletteColorLookupTableDescriptor: toNumber( instance.GreenPaletteColorLookupTableDescriptor ), bluePaletteColorLookupTableDescriptor: toNumber( instance.BluePaletteColorLookupTableDescriptor ), redPaletteColorLookupTableData: fetchPaletteColorLookupTableData( instance, 'RedPaletteColorLookupTableData', 'RedPaletteColorLookupTableDescriptor' ), greenPaletteColorLookupTableData: fetchPaletteColorLookupTableData( instance, 'GreenPaletteColorLookupTableData', 'GreenPaletteColorLookupTableDescriptor' ), bluePaletteColorLookupTableData: fetchPaletteColorLookupTableData( instance, 'BluePaletteColorLookupTableData', 'BluePaletteColorLookupTableDescriptor' ), }; break; case WADO_IMAGE_LOADER_TAGS.VOI_LUT_MODULE: const { WindowCenter, WindowWidth, VOILUTFunction } = instance; if (WindowCenter == null || WindowWidth == null) { return; } const windowCenter = Array.isArray(WindowCenter) ? WindowCenter : [WindowCenter]; const windowWidth = Array.isArray(WindowWidth) ? WindowWidth : [WindowWidth]; metadata = { windowCenter: toNumber(windowCenter), windowWidth: toNumber(windowWidth), voiLUTFunction: VOILUTFunction, }; break; case WADO_IMAGE_LOADER_TAGS.MODALITY_LUT_MODULE: const { RescaleIntercept, RescaleSlope } = instance; if (RescaleIntercept === undefined || RescaleSlope === undefined) { return; } metadata = { rescaleIntercept: toNumber(instance.RescaleIntercept), rescaleSlope: toNumber(instance.RescaleSlope), rescaleType: instance.RescaleType, }; break; case WADO_IMAGE_LOADER_TAGS.SOP_COMMON_MODULE: metadata = { sopClassUID: instance.SOPClassUID, sopInstanceUID: instance.SOPInstanceUID, }; break; case WADO_IMAGE_LOADER_TAGS.PET_IMAGE_MODULE: metadata = { frameReferenceTime: instance.FrameReferenceTime, actualFrameDuration: instance.ActualFrameDuration, }; break; case WADO_IMAGE_LOADER_TAGS.PET_ISOTOPE_MODULE: const { RadiopharmaceuticalInformationSequence } = instance; Iif (RadiopharmaceuticalInformationSequence) { const RadiopharmaceuticalInformation = Array.isArray( RadiopharmaceuticalInformationSequence ) ? RadiopharmaceuticalInformationSequence[0] : RadiopharmaceuticalInformationSequence; const { RadiopharmaceuticalStartTime, RadionuclideTotalDose, RadionuclideHalfLife } = RadiopharmaceuticalInformation; const radiopharmaceuticalInfo = { radiopharmaceuticalStartTime: dicomParser.parseTM(RadiopharmaceuticalStartTime), radionuclideTotalDose: RadionuclideTotalDose, radionuclideHalfLife: RadionuclideHalfLife, }; metadata = { radiopharmaceuticalInfo, }; } break; case WADO_IMAGE_LOADER_TAGS.OVERLAY_PLANE_MODULE: const overlays = []; 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`; const OverlayData = instance[OverlayDataTag]; if (!OverlayData) { continue; } const OverlayRowsTag = `${groupStr}0010`; const OverlayColumnsTag = `${groupStr}0011`; const OverlayType = `${groupStr}0040`; const OverlayOriginTag = `${groupStr}0050`; const OverlayDescriptionTag = `${groupStr}0022`; const OverlayLabelTag = `${groupStr}1500`; const ROIAreaTag = `${groupStr}1301`; const ROIMeanTag = `${groupStr}1302`; const ROIStandardDeviationTag = `${groupStr}1303`; const OverlayOrigin = instance[OverlayOriginTag]; let rows = 0; if (instance[OverlayRowsTag] instanceof Array) { // The DICOM VR for overlay rows is US (unsigned short). const rowsInt16Array = new Uint16Array(instance[OverlayRowsTag][0]); rows = rowsInt16Array[0]; } else { rows = instance[OverlayRowsTag]; } let columns = 0; if (instance[OverlayColumnsTag] instanceof Array) { // The DICOM VR for overlay columns is US (unsigned short). const columnsInt16Array = new Uint16Array(instance[OverlayColumnsTag][0]); columns = columnsInt16Array[0]; } else { columns = instance[OverlayColumnsTag]; } let x = 0; let y = 0; if (OverlayOrigin.length === 1) { // The DICOM VR for overlay origin is SS (signed short) with a multiplicity of 2. const originInt16Array = new Int16Array(OverlayOrigin[0]); x = originInt16Array[0]; y = originInt16Array[1]; } else { x = OverlayOrigin[0]; y = OverlayOrigin[1]; } const overlay = { rows: rows, columns: columns, type: instance[OverlayType], x, y, pixelData: OverlayData, description: instance[OverlayDescriptionTag], label: instance[OverlayLabelTag], roiArea: instance[ROIAreaTag], roiMean: instance[ROIMeanTag], roiStandardDeviation: instance[ROIStandardDeviationTag], }; overlays.push(overlay); } metadata = { overlays, }; break; case WADO_IMAGE_LOADER_TAGS.PATIENT_MODULE: const { PatientName } = instance; let patientName; Iif (PatientName) { patientName = formatPN(PatientName); } metadata = { patientName, patientId: instance.PatientID, }; break; case WADO_IMAGE_LOADER_TAGS.GENERAL_IMAGE_MODULE: metadata = { sopInstanceUID: instance.SOPInstanceUID, instanceNumber: toNumber(instance.InstanceNumber), lossyImageCompression: instance.LossyImageCompression, lossyImageCompressionRatio: instance.LossyImageCompressionRatio, lossyImageCompressionMethod: instance.LossyImageCompressionMethod, }; break; case WADO_IMAGE_LOADER_TAGS.GENERAL_STUDY_MODULE: metadata = { studyDescription: instance.StudyDescription, studyDate: instance.StudyDate, studyTime: instance.StudyTime, accessionNumber: instance.AccessionNumber, }; break; case WADO_IMAGE_LOADER_TAGS.CINE_MODULE: metadata = { frameTime: instance.FrameTime, numberOfFrames: instance.NumberOfFrames ? Number(instance.NumberOfFrames) : 1, }; break; case WADO_IMAGE_LOADER_TAGS.PET_SERIES_MODULE: metadata = { correctedImage: instance.CorrectedImage, units: instance.Units, decayCorrection: instance.DecayCorrection, }; break; case WADO_IMAGE_LOADER_TAGS.CALIBRATION_MODULE: // map the DICOM tags to the cornerstone tags since cornerstone tags // are camelCase and instance tags are all caps metadata = { sequenceOfUltrasoundRegions: instance.SequenceOfUltrasoundRegions?.map(region => { return { regionSpatialFormat: region.RegionSpatialFormat, regionDataType: region.RegionDataType, regionFlags: region.RegionFlags, regionLocationMinX0: region.RegionLocationMinX0, regionLocationMinY0: region.RegionLocationMinY0, regionLocationMaxX1: region.RegionLocationMaxX1, regionLocationMaxY1: region.RegionLocationMaxY1, referencePixelX0: region.ReferencePixelX0, referencePixelY0: region.ReferencePixelY0, referencePixelPhysicalValueX: region.ReferencePixelPhysicalValueX, referencePixelPhysicalValueY: region.ReferencePixelPhysicalValueY, physicalUnitsXDirection: region.PhysicalUnitsXDirection, physicalUnitsYDirection: region.PhysicalUnitsYDirection, physicalDeltaX: region.PhysicalDeltaX, physicalDeltaY: region.PhysicalDeltaY, }; }), }; break; /** * Below are the tags and not the modules since they are not really * consistent with the modules above */ case 'temporalPositionIdentifier': metadata = { temporalPositionIdentifier: instance.TemporalPositionIdentifier, }; break; default: return; } return metadata; } /** * Retrieves the frameNumber information, depending on the url style * wadors /frames/1 * wadouri &frame=1 * @param {*} imageId * @returns */ getFrameInformationFromURL(imageId) { function getInformationFromURL(informationString, separator) { let result = ''; const splittedStr = imageId.split(informationString)[1]; if (splittedStr.includes(separator)) { result = splittedStr.split(separator)[0]; } else { result = splittedStr; } return result; } Iif (imageId.includes('/frames')) { return getInformationFromURL('/frames', '/'); } Iif (imageId.includes('&frame=')) { return getInformationFromURL('&frame=', '&'); } return; } getUIDsFromImageID(imageId) { if (imageId.startsWith('wadors:')) { const strippedImageId = imageId.split('/studies/')[1]; const splitImageId = strippedImageId.split('/'); return { StudyInstanceUID: splitImageId[0], // Note: splitImageId[1] === 'series' SeriesInstanceUID: splitImageId[2], // Note: splitImageId[3] === 'instances' SOPInstanceUID: splitImageId[4], frameNumber: splitImageId[6], }; } else Iif (imageId.includes('?requestType=WADO')) { const qs = queryString.parse(imageId); return { StudyInstanceUID: qs.studyUID, SeriesInstanceUID: qs.seriesUID, SOPInstanceUID: qs.objectUID, frameNumber: qs.frameNumber, }; } // Maybe its a non-standard imageId // check if the imageId starts with http:// or https:// using regex // Todo: handle non http imageIds let imageURI; const urlRegex = /^(http|https|dicomfile):\/\//; Iif (urlRegex.test(imageId)) { imageURI = imageId; } else { imageURI = imageIdToURI(imageId); } // remove &frame=number from imageId imageURI = imageURI.split('&frame=')[0]; const uids = this.imageURIToUIDs.get(imageURI); const frameNumber = this.getFrameInformationFromURL(imageId) || '1'; Iif (uids && frameNumber !== undefined) { return { ...uids, frameNumber }; } return uids; } } const metadataProvider = new MetadataProvider(); export default metadataProvider; const WADO_IMAGE_LOADER = { imagePlaneModule: instance => { const { ImageOrientationPatient, ImagePositionPatient } = instance; // Fallback for DX images. // TODO: We should use the rest of the results of this function // to update the UI somehow const { PixelSpacing, type } = getPixelSpacingInformation(instance) || {}; let rowPixelSpacing; let columnPixelSpacing; let rowCosines; let columnCosines; let usingDefaultValues = false; let isDefaultValueSetForRowCosine = false; let isDefaultValueSetForColumnCosine = false; let imageOrientationPatient; if (PixelSpacing) { [rowPixelSpacing, columnPixelSpacing] = PixelSpacing; calibratedPixelSpacingMetadataProvider.add(instance.imageId, { rowPixelSpacing: parseFloat(PixelSpacing[0]), columnPixelSpacing: parseFloat(PixelSpacing[1]), type, }); } else E{ rowPixelSpacing = columnPixelSpacing = 1; usingDefaultValues = true; } if (ImageOrientationPatient) { rowCosines = toNumber(ImageOrientationPatient.slice(0, 3)); columnCosines = toNumber(ImageOrientationPatient.slice(3, 6)); imageOrientationPatient = toNumber(ImageOrientationPatient); } else E{ rowCosines = [1, 0, 0]; columnCosines = [0, 1, 0]; imageOrientationPatient = [1, 0, 0, 0, 1, 0]; usingDefaultValues = true; isDefaultValueSetForRowCosine = true; isDefaultValueSetForColumnCosine = true; } const imagePositionPatient = toNumber(ImagePositionPatient) || [0, 0, 0]; Iif (!ImagePositionPatient) { usingDefaultValues = true; } return { frameOfReferenceUID: instance.FrameOfReferenceUID, rows: toNumber(instance.Rows), columns: toNumber(instance.Columns), spacingBetweenSlices: toNumber(instance.SpacingBetweenSlices), imageOrientationPatient, rowCosines, isDefaultValueSetForRowCosine, columnCosines, isDefaultValueSetForColumnCosine, imagePositionPatient, sliceThickness: toNumber(instance.SliceThickness), sliceLocation: toNumber(instance.SliceLocation), pixelSpacing: toNumber(PixelSpacing || 1), rowPixelSpacing, columnPixelSpacing, usingDefaultValues, }; }, }; const WADO_IMAGE_LOADER_TAGS = { // dicomImageLoader specific GENERAL_SERIES_MODULE: 'generalSeriesModule', PATIENT_STUDY_MODULE: 'patientStudyModule', IMAGE_PIXEL_MODULE: 'imagePixelModule', VOI_LUT_MODULE: 'voiLutModule', MODALITY_LUT_MODULE: 'modalityLutModule', SOP_COMMON_MODULE: 'sopCommonModule', PET_IMAGE_MODULE: 'petImageModule', PET_ISOTOPE_MODULE: 'petIsotopeModule', PET_SERIES_MODULE: 'petSeriesModule', OVERLAY_PLANE_MODULE: 'overlayPlaneModule', PATIENT_DEMOGRAPHIC_MODULE: 'patientDemographicModule', // react-cornerstone-viewport specific PATIENT_MODULE: 'patientModule', GENERAL_IMAGE_MODULE: 'generalImageModule', GENERAL_STUDY_MODULE: 'generalStudyModule', CINE_MODULE: 'cineModule', CALIBRATION_MODULE: 'calibrationModule', }; const INSTANCE = 'instance'; |