All files / extensions/default/src/SOPClassHandlers chartSOPClassHandler.ts

24% Statements 6/25
0% Branches 0/4
0% Functions 0/7
24% Lines 6/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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97            34x   34x     34x   34x   34x                                                                                                                                               34x                  
import { Types, DisplaySetService, utils } from '@ohif/core';
 
import { id } from '../id';
 
type InstanceMetadata = Types.InstanceMetadata;
 
const SOPClassHandlerName = 'chart';
 
const CHART_MODALITY = 'CHT';
 
// Private SOPClassUid for chart data
const ChartDataSOPClassUid = '1.9.451.13215.7.3.2.7.6.1';
 
const sopClassUids = [ChartDataSOPClassUid];
 
const makeChartDataDisplaySet = (instance, sopClassUids) => {
  const {
    StudyInstanceUID,
    SeriesInstanceUID,
    SOPInstanceUID,
    SeriesDescription,
    SeriesNumber,
    SeriesDate,
    SOPClassUID,
  } = instance;
 
  return {
    Modality: CHART_MODALITY,
    loading: false,
    isReconstructable: false,
    displaySetInstanceUID: utils.guid(),
    SeriesDescription,
    SeriesNumber,
    SeriesDate,
    SOPInstanceUID,
    SeriesInstanceUID,
    StudyInstanceUID,
    SOPClassHandlerId: `${id}.sopClassHandlerModule.${SOPClassHandlerName}`,
    SOPClassUID,
    isDerivedDisplaySet: true,
    isLoaded: true,
    sopClassUids,
    instance,
    instances: [instance],
 
    /**
     * Adds instances to the chart displaySet, rather than creating a new one
     * when user moves to a different workflow step and gets back to a step that
     * recreates the chart
     */
    addInstances: function (instances: InstanceMetadata[], _displaySetService: DisplaySetService) {
      this.instances.push(...instances);
      this.instance = this.instances[this.instances.length - 1];
 
      return this;
    },
  };
};
 
function getSopClassUids(instances) {
  const uniqueSopClassUidsInSeries = new Set();
  instances.forEach(instance => {
    uniqueSopClassUidsInSeries.add(instance.SOPClassUID);
  });
  const sopClassUids = Array.from(uniqueSopClassUidsInSeries);
 
  return sopClassUids;
}
 
function _getDisplaySetsFromSeries(instances) {
  // If the series has no instances, stop here
  Iif (!instances || !instances.length) {
    throw new Error('No instances were provided');
  }
 
  const sopClassUids = getSopClassUids(instances);
  const displaySets = instances.map(instance => {
    Iif (instance.Modality === CHART_MODALITY) {
      return makeChartDataDisplaySet(instance, sopClassUids);
    }
 
    throw new Error('Unsupported modality');
  });
 
  return displaySets;
}
 
const chartHandler = {
  name: SOPClassHandlerName,
  sopClassUids,
  getDisplaySetsFromSeries: instances => {
    return _getDisplaySetsFromSeries(instances);
  },
};
 
export { chartHandler };