All files / platform/core/src/utils getWADORSImageId.js

0% Statements 0/12
0% Branches 0/8
0% Functions 0/2
0% Lines 0/12

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                                                                           
function getWADORSImageUrl(instance, frame) {
  let wadorsuri = instance.wadorsuri;
 
  if (!wadorsuri) {
    return;
  }
 
  // Use null to obtain an imageId which represents the instance
  if (frame === null) {
    wadorsuri = wadorsuri.replace(/frames\/(\d+)/, '');
  } else {
    // We need to sum 1 because WADO-RS frame number is 1-based
    frame = frame ? parseInt(frame) + 1 : 1;
 
    // Replaces /frame/1 by /frame/{frame}
    wadorsuri = wadorsuri.replace(/frames\/(\d+)/, `frames/${frame}`);
  }
 
  return wadorsuri;
}
 
/**
 * Obtain an imageId for Cornerstone based on the WADO-RS scheme
 *
 * @param {object} instanceMetada metadata object (InstanceMetadata)
 * @param {(string\|number)} [frame] the frame number
 * @returns {string} The imageId to be used by Cornerstone
 */
export default function getWADORSImageId(instance, frame) {
  const uri = getWADORSImageUrl(instance, frame);
 
  if (!uri) {
    return;
  }
 
  return `wadors:${uri}`;
}