All files / tools/src/utilities getPixelValueUnits.ts

56.25% Statements 9/16
41.66% Branches 5/12
100% Functions 3/3
56.25% Lines 9/16

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                      16x 16x                             24x   24x 16x   8x                           16x       16x 16x                                  
import { metaData } from '@cornerstonejs/core';
 
type pixelUnitsOptions = {
  isPreScaled: boolean;
  isSuvScaled: boolean;
};
 
function getPixelValueUnitsImageId(
  imageId: string,
  options: pixelUnitsOptions
): string {
  const generalSeriesModule = metaData.get('generalSeriesModule', imageId);
  return getPixelValueUnits(generalSeriesModule.modality, imageId, options);
}
 
/**
 * Determines the appropriate pixel value units based on the image modality and options.
 * @param modality - The modality of the image (e.g., 'CT', 'PT').
 * @param imageId - The unique identifier for the image.
 * @param options - Additional options for determining pixel units.
 * @returns The appropriate pixel value units as a string.
 */
function getPixelValueUnits(
  modality: string,
  imageId: string,
  options: pixelUnitsOptions
): string {
  Iif (modality === 'CT') {
    return 'HU';
  } else if (modality === 'PT') {
    return _handlePTModality(imageId, options);
  } else {
    return '';
  }
}
 
/**
 * Handles the determination of pixel value units for PT (Positron Emission Tomography) modality.
 * @param imageId - The unique identifier for the image.
 * @param options - Additional options for determining pixel units.
 * @returns The appropriate pixel value units for PT modality as a string.
 */
function _handlePTModality(
  imageId: string,
  options: pixelUnitsOptions
): string {
  Iif (!options.isPreScaled) {
    return 'raw';
  }
 
  Eif (options.isSuvScaled) {
    return 'SUV';
  }
 
  const generalSeriesModule = metaData.get('generalSeriesModule', imageId);
 
  // It might be possible that the reference ImageId is not the one
  // that is being displayed. So we need to get the modality from imageId again
  if (generalSeriesModule?.modality === 'PT') {
    const petSeriesModule = metaData.get('petSeriesModule', imageId);
    return petSeriesModule?.units || 'unitless';
  }
 
  return 'unknown';
}
 
export type { pixelUnitsOptions };
export { getPixelValueUnits, getPixelValueUnitsImageId };