All files / dicomImageLoader/src/imageLoader/wadors combineFrameInstance.ts

66.66% Statements 14/21
41.66% Branches 5/12
33.33% Functions 3/9
66.66% Lines 14/21

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 78 79 80 81 82 83 84 85 86 87 88              2404x             2404x               2404x                         34362x   34362x       34362x       34362x   34362x                             2380x   2380x 2380x           2380x     2380x           2380x              
import getTagValue from './getTagValue';
 
function getFrameInformation(
  PerFrameFunctionalGroupsSequence,
  SharedFunctionalGroupsSequence,
  frameNumber
) {
  const shared = (
    SharedFunctionalGroupsSequence
      ? Object.values(SharedFunctionalGroupsSequence[0])
      : []
  )
    .map((it: unknown) => it['Value']?.[0])
    .filter((it) => it !== undefined && typeof it === 'object');
  const perFrame = (
    PerFrameFunctionalGroupsSequence
      ? Object.values(PerFrameFunctionalGroupsSequence[frameNumber - 1])
      : []
  )
    .map((it: unknown) => it['Value']?.[0])
    .filter((it) => it !== undefined && typeof it === 'object');
 
  return {
    shared,
    perFrame,
  };
}
 
function getMultiframeInformation(metaData) {
  let {
    52009230: PerFrameFunctionalGroupsSequence,
    52009229: SharedFunctionalGroupsSequence,
    '00280008': NumberOfFrames,
    // eslint-disable-next-line prefer-const
    ...rest
  } = metaData;
 
  PerFrameFunctionalGroupsSequence = getTagValue(
    PerFrameFunctionalGroupsSequence,
    false
  );
  SharedFunctionalGroupsSequence = getTagValue(
    SharedFunctionalGroupsSequence,
    false
  );
  NumberOfFrames = getTagValue(NumberOfFrames);
 
  return {
    PerFrameFunctionalGroupsSequence,
    SharedFunctionalGroupsSequence,
    NumberOfFrames,
    rest,
  };
}
// function that retrieves specific frame metadata information from multiframe
// metadata
function combineFrameInstance(frameNumber, instance) {
  const {
    PerFrameFunctionalGroupsSequence,
    SharedFunctionalGroupsSequence,
    NumberOfFrames,
    rest,
  } = getMultiframeInformation(instance);
 
  Eif (PerFrameFunctionalGroupsSequence || NumberOfFrames > 1) {
    const { shared, perFrame } = getFrameInformation(
      PerFrameFunctionalGroupsSequence,
      SharedFunctionalGroupsSequence,
      frameNumber
    );
 
    const newInstance = Object.assign(instance, { frameNumber });
 
    // merge the shared first then the per frame to override
    [...shared, ...perFrame].forEach((item) => {
      Object.entries(item).forEach(([key, value]) => {
        newInstance[key] = value;
      });
    });
 
    return Object.assign(rest, { '00280008': NumberOfFrames }, newInstance);
  }
 
  return instance;
}
 
export { combineFrameInstance, getMultiframeInformation, getFrameInformation };