All files / packages/core/src/utilities getScalingParameters.ts

100% Statements 6/6
50% Branches 4/8
100% Functions 1/1
100% Lines 6/6

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                          1x 1x   1x   1x           1x   1x                  
import { get as metaDataGet } from '../metaData';
import { ScalingParameters } from '../types';
 
/**
 * It returns the scaling parameters for the image with the given imageId. This can be
 * used to get passed (as an option) to the imageLoader in order to apply scaling to the image inside
 * the imageLoader.
 * @param imageId - The imageId of the image
 * @returns ScalingParameters
 */
export default function getScalingParameters(
  imageId: string
): ScalingParameters {
  const modalityLutModule = metaDataGet('modalityLutModule', imageId) || {};
  const generalSeriesModule = metaDataGet('generalSeriesModule', imageId) || {};
 
  const { modality } = generalSeriesModule;
 
  const scalingParameters = {
    rescaleSlope: modalityLutModule.rescaleSlope,
    rescaleIntercept: modalityLutModule.rescaleIntercept,
    modality,
  };
 
  const suvFactor = metaDataGet('scalingModule', imageId) || {};
 
  return {
    ...scalingParameters,
    ...(modality === 'PT' && {
      suvbw: suvFactor.suvbw,
      suvbsa: suvFactor.suvbsa,
      suvlbm: suvFactor.suvlbm,
    }),
  };
}