All files / extensions/cornerstone-dicom-rt/src getCommandsModule.ts

91.66% Statements 11/12
0% Branches 0/1
100% Functions 2/2
91.66% Lines 11/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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56    34x 34x 34x   34x   2x       2x             2x               2x         2x             34x               34x                
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
 
const commandsModule = ({ commandsManager, servicesManager }: withAppTypes) => {
  const services = servicesManager.services;
  const { displaySetService, viewportGridService } = services;
 
  const actions = {
    hydrateRTSDisplaySet: ({ displaySet, viewportId }) => {
      Iif (displaySet.Modality !== 'RTSTRUCT') {
        throw new Error('Display set is not an RTSTRUCT');
      }
 
      const referencedDisplaySet = displaySetService.getDisplaySetByUID(
        displaySet.referencedDisplaySetInstanceUID
      );
 
      // update the previously stored segmentationPresentation with the new viewportId
      // presentation so that when we put the referencedDisplaySet back in the viewport
      // it will have the correct segmentation representation hydrated
      commandsManager.runCommand('updateStoredSegmentationPresentation', {
        displaySet: displaySet,
        type: SegmentationRepresentations.Contour,
      });
 
      // update the previously stored positionPresentation with the new viewportId
      // presentation so that when we put the referencedDisplaySet back in the viewport
      // it will be in the correct position zoom and pan
      commandsManager.runCommand('updateStoredPositionPresentation', {
        viewportId,
        displaySetInstanceUID: referencedDisplaySet.displaySetInstanceUID,
      });
 
      viewportGridService.setDisplaySetsForViewport({
        viewportId,
        displaySetInstanceUIDs: [referencedDisplaySet.displaySetInstanceUID],
      });
    },
  };
 
  const definitions = {
    hydrateRTSDisplaySet: {
      commandFn: actions.hydrateRTSDisplaySet,
      storeContexts: [],
      options: {},
    },
  };
 
  return {
    actions,
    definitions,
    defaultContext: 'cornerstone-dicom-rt',
  };
};
 
export default commandsModule;