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

18.18% Statements 2/11
0% Branches 0/4
33.33% Functions 1/3
18.18% Lines 2/11

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                            128x                                                 384x        
import { MetadataModules } from '../../enums';
import { addTypedProvider } from '../../metaData';
 
export interface UriModule {
  baseImageId: string;
  frameNumber?: number;
  framesString?: string;
  remaining?: string;
  sopInstanceUID?: string;
  seriesInstanceUID?: string;
  studyInstanceUID?: string;
}
 
export const frameRangeExtractor =
  /(\/frames\/|[&?]frameNumber=|[&?]frame=)([^/&?]*)(.*)/i;
 
export function getUriModule(imageId) {
  const framesMatch = imageId.match(frameRangeExtractor);
  if (!framesMatch) {
    return;
  }
  const baseImageId = imageId.substring(0, framesMatch.index);
  const framesString = framesMatch[2];
  const frameNumber = parseFloat(framesString);
  const remaining = framesMatch[3];
 
  return {
    baseImageId,
    frameNumber,
    framesString,
    remaining,
  };
}
 
export function uriModuleProvider(next, imageId, data, options) {
  return getUriModule(imageId) || next(imageId, data, options);
}
 
export function registerUriModule() {
  addTypedProvider(MetadataModules.URI_MODULE, uriModuleProvider);
}
 
export default getUriModule;