All files / metadata/src/displayset buildSeriesInfo.ts

0% Statements 0/13
0% Branches 0/6
0% Functions 0/1
0% Lines 0/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 34 35 36 37 38 39 40 41 42 43 44                                                                                       
import type { NaturalizedInstance, SeriesInfo } from './types';
 
/**
 * Aggregates series-level statistics over a series' naturalized instances.
 *
 * Independent of split rules: a rule derives its own facts through its `series`
 * hook (see {@link RuleContext}), so this helper only counts and is safe to call
 * with an empty `instances` list (it returns zeroed counts).
 *
 * @param instances - naturalized instances for the series.
 * @returns the aggregated series statistics.
 */
export function buildSeriesInfo(instances: NaturalizedInstance[]): SeriesInfo {
  const NumberOfSeriesRelatedInstances = instances.length;
  let numberOfFrames = 0;
  let numberOfNonImageObjects = 0;
  let numberOfSOPInstanceUIDsPerSeries = 0;
 
  for (const instance of instances) {
    if (instance.NumberOfFrames) {
      numberOfFrames += Number(instance.NumberOfFrames);
    } else if (instance.Rows) {
      numberOfFrames += 1;
    } else {
      numberOfNonImageObjects += 1;
    }
 
    if (instance.SOPInstanceUID) {
      numberOfSOPInstanceUIDsPerSeries += 1;
    }
  }
 
  return {
    NumberOfSeriesRelatedInstances,
    numberOfFrames,
    // `numImageFrames` mirrors `numberOfFrames` here purely for OHIF parity (the
    // display-set shape exposes `numImageFrames`); they intentionally hold the
    // same series-level frame count.
    numImageFrames: numberOfFrames,
    numberOfNonImageObjects,
    numberOfSOPInstanceUIDsPerSeries,
  };
}