All files / extensions/cornerstone/src/customizations layoutSelectorCustomization.ts

92.3% Statements 24/26
77.77% Branches 7/9
100% Functions 6/6
92.3% Lines 24/26

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 98 99 100 101 102 103 104 105            1833x         11417x       11417x           1833x           1833x   1833x   1833x   1833x 202x   1631x   1631x       1631x 2033x 2033x 2033x 18x   2015x     1631x   24465x 13048x     11417x   11417x                 24465x     1833x                                                                  
export default {
  'layoutSelector.advancedPresetGenerator': ({
    servicesManager,
  }: {
    servicesManager: AppTypes.ServicesManager;
  }) => {
    const _areSelectorsValid = (
      hp: AppTypes.HangingProtocol.Protocol,
      displaySets: AppTypes.DisplaySet[],
      hangingProtocolService: AppTypes.HangingProtocolService
    ) => {
      Iif (!hp.displaySetSelectors || Object.values(hp.displaySetSelectors).length === 0) {
        return true;
      }
 
      return hangingProtocolService.areRequiredSelectorsValid(
        Object.values(hp.displaySetSelectors),
        displaySets[0]
      );
    };
 
    const generateAdvancedPresets = ({
      servicesManager,
    }: {
      servicesManager: AppTypes.ServicesManager;
    }) => {
      const { hangingProtocolService, viewportGridService, displaySetService } =
        servicesManager.services;
 
      const hangingProtocols = Array.from(hangingProtocolService.protocols.values());
 
      const viewportId = viewportGridService.getActiveViewportId();
 
      if (!viewportId) {
        return [];
      }
      const displaySetInstanceUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
 
      Iif (!displaySetInstanceUIDs) {
        return [];
      }
 
      const displaySets = displaySetInstanceUIDs.map(uid => {
        const displaySet = displaySetService.getDisplaySetByUID(uid);
        const referencedDisplaySetUID = displaySet?.measurements?.[0]?.displaySetInstanceUID;
        if (displaySet.Modality === 'SR' && referencedDisplaySetUID) {
          return displaySetService.getDisplaySetByUID(referencedDisplaySetUID);
        }
        return displaySet;
      });
 
      return hangingProtocols
        .map(hp => {
          if (!hp.isPreset) {
            return null;
          }
 
          const areValid = _areSelectorsValid(hp, displaySets, hangingProtocolService);
 
          return {
            icon: hp.icon,
            title: hp.name,
            commandOptions: {
              protocolId: hp.id,
            },
            disabled: !areValid,
          };
        })
        .filter(preset => preset !== null);
    };
 
    return generateAdvancedPresets({ servicesManager });
  },
  'layoutSelector.commonPresets': [
    {
      icon: 'layout-common-1x1',
      commandOptions: {
        numRows: 1,
        numCols: 1,
      },
    },
    {
      icon: 'layout-common-1x2',
      commandOptions: {
        numRows: 1,
        numCols: 2,
      },
    },
    {
      icon: 'layout-common-2x2',
      commandOptions: {
        numRows: 2,
        numCols: 2,
      },
    },
    {
      icon: 'layout-common-2x3',
      commandOptions: {
        numRows: 2,
        numCols: 3,
      },
    },
  ],
};