All files / metadata/src/utilities/metadataProvider addDicomPart10Instance.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2

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                                    10746x                                                 45x        
import { addTyped } from '../../metaData';
import { MetadataModules } from '../../enums';
 
/**
 * Adds a DICOMweb JSON metadata instance to the NATURALIZED cache.
 *
 * Takes hex-tagged DICOMweb JSON (e.g. {"00080060": {vr:"CS", Value:["CT"]}})
 * and converts it to a naturalized instance via MetaDataIterator and
 * NaturalTagListener.createMetadataListener() (DicomMetadataListener + natural filter).
 *
 * @param imageId - The imageId to associate with this instance
 * @param metadata - DICOMweb JSON metadata object with hex-tagged entries
 * @returns The naturalized instance object
 */
export function addDicomWebInstance(
  imageId: string,
  metadata: Record<string, unknown>
) {
  return addTyped(MetadataModules.NATURALIZED, imageId, {
    dicomwebJson: metadata,
  });
}
 
/**
 * Adds a binary DICOM Part 10 instance to the NATURALIZED cache.
 *
 * Parses the ArrayBuffer using dcmjs AsyncDicomReader with
 * NaturalTagListener.createMetadataListener() so that naturalized output
 * (including pixel data as array of frames of
 * ArrayBuffer fragments) is produced and listener.information is
 * populated for the reader.
 *
 * @param imageId - The imageId to associate with this instance
 * @param part10 - ArrayBuffer/Uint8Array or resolver function returning those values
 * @returns A promise that resolves to the naturalized instance object
 */
export async function addDicomPart10Instance(
  imageId: string,
  part10:
    | ArrayBuffer
    | Uint8Array
    | (() => ArrayBuffer | Uint8Array | Promise<ArrayBuffer | Uint8Array>)
) {
  return addTyped(MetadataModules.NATURALIZED, imageId, {
    part10Buffer: part10,
  });
}