All files / packages/tools/src/utilities getModalityUnit.ts

23.07% Statements 3/13
16.66% Branches 2/12
50% Functions 1/2
23.07% Lines 3/13

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                        36x   36x     36x                                                
import { metaData } from '@cornerstonejs/core';
 
type ModalityUnitOptions = {
  isPreScaled: boolean;
  isSuvScaled: boolean;
};
 
function getModalityUnit(
  modality: string,
  imageId: string,
  options: ModalityUnitOptions
): string {
  Iif (modality === 'CT') {
    return 'HU';
  } else Iif (modality === 'PT') {
    return _handlePTModality(imageId, options);
  } else {
    return '';
  }
}
 
function _handlePTModality(imageId: string, options: ModalityUnitOptions) {
  if (!options.isPreScaled) {
    return 'raw';
  }
 
  if (options.isSuvScaled) {
    return 'SUV';
  }
 
  const generalSeriesModule = metaData.get('generalSeriesModule', imageId);
 
  // it might be possible that the referenceImageId 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';
  }
}
 
export { getModalityUnit, ModalityUnitOptions };