All files / extensions/cornerstone-dicom-seg/src/utils segLocalImageIds.ts

23.07% Statements 3/13
14.28% Branches 1/7
40% Functions 2/5
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  24x                                                     9144x   9144x    
export function isLocalSchemeImageId(imageId: string): boolean {
  return /^(wadouri:|dicomfile:|dicomweb:)/.test(imageId);
}
 
export function stripFrameFromImageId(imageId: string): string {
  const queryIndex = imageId.indexOf('?');
  Iif (queryIndex === -1) {
    return imageId;
  }
 
  const basePath = imageId.slice(0, queryIndex);
  const rebuiltQuery = imageId
    .slice(queryIndex + 1)
    .split('&')
    .filter(param => param.split('=')[0] !== 'frame')
    .join('&');
 
  return rebuiltQuery ? `${basePath}?${rebuiltQuery}` : basePath;
}
 
export function appendFrameToImageId(baseImageId: string, frame: number): string {
  const withoutFrame = stripFrameFromImageId(baseImageId);
  const separator = withoutFrame.includes('?') ? '&' : '?';
 
  return `${withoutFrame}${separator}frame=${frame}`;
}
 
export function getFrameIndexFromImageId(imageId: string): number {
  const frameMatch = imageId.match(/(?:&|\?)frame=(\d+)/);
 
  return frameMatch ? Number(frameMatch[1]) : 1;
}