All files / dicomImageLoader/src/imageLoader getScalingParameters.ts

100% Statements 6/6
70% Branches 7/10
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 37                    9634x   9634x     9634x   9634x           9634x   9634x                      
import type { Types } from '@cornerstonejs/core';
 
/**
 * 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(metaData, imageId: string) {
  const modalityLutModule = metaData.get('modalityLutModule', imageId) || {};
 
  const generalSeriesModule = (metaData.get('generalSeriesModule', imageId) ||
    {}) as Types.GeneralSeriesModuleMetadata;
 
  const { modality } = generalSeriesModule;
 
  const scalingParameters = {
    rescaleSlope: modalityLutModule.rescaleSlope,
    rescaleIntercept: modalityLutModule.rescaleIntercept,
    modality,
  };
 
  const scalingModules = metaData.get('scalingModule', imageId) || {};
 
  return {
    ...scalingParameters,
    ...(modality === 'PT' && { suvbw: scalingModules.suvbw }),
    ...(modality === 'RTDOSE' && {
      doseGridScaling: scalingModules.DoseGridScaling,
      doseSummation: scalingModules.DoseSummation,
      doseType: scalingModules.DoseType,
      doseUnit: scalingModules.DoseUnit,
    }),
  };
}