All files / dicomImageLoader/src/imageLoader/wadouri retrieveMultiframeDataset.ts

26.92% Statements 7/26
28.57% Branches 4/14
33.33% Functions 2/6
28% Lines 7/25

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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                                        31982x       31982x   31982x 31982x       31982x     31982x     31982x                                                              
import { loadedDataSets } from './loadedDataSets';
 
function _get(uri) {
  if (!loadedDataSets[uri]) {
    return;
  }
 
  return loadedDataSets[uri];
}
 
function isMultiframeDataset(uri) {
  const dataSet = _get(uri);
 
  return _isMultiframeDataset(dataSet);
}
 
function _isMultiframeDataset(dataSet) {
  // Checks if dicomTag NumberOf Frames exists and it is greater than one
  if (!dataSet) {
    return false;
  }
 
  const numberOfFrames = dataSet.intString('x00280008');
 
  return numberOfFrames && numberOfFrames > 1;
}
 
function retrieveFrameParameterIndex(uri) {
  return uri.indexOf('&frame=');
}
 
function retrieveMultiframeDataset(uri) {
  const frameParameterIndex = retrieveFrameParameterIndex(uri);
  const multiframeURI =
    frameParameterIndex === -1 ? uri : uri.slice(0, frameParameterIndex);
  const frame = parseInt(uri.slice(frameParameterIndex + 7), 10) || 1;
 
  let dataSet;
 
  Iif (loadedDataSets[multiframeURI]) {
    dataSet = loadedDataSets[multiframeURI].dataSet;
  } else {
    dataSet = undefined;
  }
 
  return {
    dataSet,
    frame,
  };
}
 
function generateMultiframeWADOURIs(uri) {
  const listWADOURIs = [];
 
  const dataSet = _get(uri);
 
  if (_isMultiframeDataset(dataSet)) {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const numberOfFrames = (dataSet as any).intString('x00280008');
 
    for (let i = 1; i <= numberOfFrames; i++) {
      listWADOURIs.push(`${uri}&frame=${i}`);
    }
  } else {
    listWADOURIs.push(uri);
  }
 
  return listWADOURIs;
}
 
export default {
  _get,
  generateMultiframeWADOURIs,
  retrieveMultiframeDataset,
  isMultiframeDataset,
};