Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typings): Enhance typing support with withAppTypes and custom services throughout OHIF #4090

Merged
merged 16 commits into from
May 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import loadRTStruct from './loadRTStruct';

const sopClassUids = ['1.2.840.10008.5.1.4.1.1.481.3'];

let loadPromises = {};
const loadPromises = {};

function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager) {
function _getDisplaySetsFromSeries(
instances,
servicesManager: AppTypes.ServicesManager,
extensionManager
) {
const instance = instances[0];

const {
Expand Down Expand Up @@ -69,8 +73,8 @@ function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager)
displaySet.referencedSeriesInstanceUID = referencedSeries.SeriesInstanceUID;

displaySet.getReferenceDisplaySet = () => {
const { DisplaySetService } = servicesManager.services;
const referencedDisplaySets = DisplaySetService.getDisplaySetsForSeries(
const { displaySetService } = servicesManager.services;
const referencedDisplaySets = displaySetService.getDisplaySetsForSeries(
displaySet.referencedSeriesInstanceUID
);

Expand All @@ -90,7 +94,7 @@ function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager)
return [displaySet];
}

function _load(rtDisplaySet, servicesManager, extensionManager, headers) {
function _load(rtDisplaySet, servicesManager: AppTypes.ServicesManager, extensionManager, headers) {
const { SOPInstanceUID } = rtDisplaySet;
const { segmentationService } = servicesManager.services;
if (
Expand Down Expand Up @@ -168,7 +172,10 @@ function _deriveReferencedSeriesSequenceFromFrameOfReferenceSequence(
return ReferencedSeriesSequence;
}

function _segmentationExistsInCache(rtDisplaySet, segmentationService) {
function _segmentationExistsInCache(
rtDisplaySet,
segmentationService: AppTypes.SegmentationService
) {
// Todo: fix this
return false;
// This should be abstracted with the CornerstoneCacheService
Expand Down
5 changes: 3 additions & 2 deletions extensions/cornerstone-dicom-rt/src/utils/promptHydrateRT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function promptHydrateRT({
toolGroupId = 'default',
preHydrateCallbacks,
hydrateRTDisplaySet,
}) {
}: withAppTypes) {
const { uiViewportDialogService } = servicesManager.services;
const extensionManager = servicesManager._extensionManager;
const appConfig = extensionManager._appConfig;
Expand Down Expand Up @@ -41,7 +41,7 @@ function promptHydrateRT({
});
}

function _askHydrate(uiViewportDialogService, viewportId) {
function _askHydrate(uiViewportDialogService: AppTypes.UIViewportDialogService, viewportId) {
return new Promise(function (resolve, reject) {
const message = 'Do you want to open this Segmentation?';
const actions = [
Expand All @@ -62,6 +62,7 @@ function _askHydrate(uiViewportDialogService, viewportId) {
};

uiViewportDialogService.show({
id: 'promptHydrateRT',
viewportId,
type: 'info',
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import createRTToolGroupAndAddTools from '../utils/initRTToolGroup';

const RT_TOOLGROUP_BASE_NAME = 'RTToolGroup';

function OHIFCornerstoneRTViewport(props) {
function OHIFCornerstoneRTViewport(props: withAppTypes) {
const {
children,
displaySets,
Expand Down
4 changes: 2 additions & 2 deletions extensions/cornerstone-dicom-seg/src/commandsModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dcmjs from 'dcmjs';
import { createReportDialogPrompt } from '@ohif/extension-default';
import { ServicesManager, Types } from '@ohif/core';
import { Types } from '@ohif/core';
import { cache, metaData } from '@cornerstonejs/core';
import {
segmentation as cornerstoneToolsSegmentation,
Expand Down Expand Up @@ -48,7 +48,7 @@ const commandsModule = ({
displaySetService,
viewportGridService,
toolGroupService,
} = (servicesManager as ServicesManager).services;
} = servicesManager.services;

const actions = {
/**
Expand Down
2 changes: 1 addition & 1 deletion extensions/cornerstone-dicom-seg/src/getPanelModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getPanelModule = ({
extensionManager,
configuration,
title,
}) => {
}: withAppTypes) => {
const { customizationService } = servicesManager.services;

const wrappedPanelSegmentation = configuration => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import { dicomlabToRGB } from './utils/dicomlabToRGB';

const sopClassUids = ['1.2.840.10008.5.1.4.1.1.66.4'];

let loadPromises = {};
const loadPromises = {};

function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager) {
function _getDisplaySetsFromSeries(
instances,
servicesManager: AppTypes.ServicesManager,
extensionManager
) {
const instance = instances[0];

const {
Expand Down Expand Up @@ -95,7 +99,12 @@ function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager)
return [displaySet];
}

function _load(segDisplaySet, servicesManager, extensionManager, headers) {
function _load(
segDisplaySet,
servicesManager: AppTypes.ServicesManager,
extensionManager,
headers
) {
const { SOPInstanceUID } = segDisplaySet;
const { segmentationService } = servicesManager.services;

Expand Down Expand Up @@ -137,7 +146,12 @@ function _load(segDisplaySet, servicesManager, extensionManager, headers) {
return loadPromises[SOPInstanceUID];
}

async function _loadSegments({ extensionManager, servicesManager, segDisplaySet, headers }) {
async function _loadSegments({
extensionManager,
servicesManager,
segDisplaySet,
headers,
}: withAppTypes) {
const utilityModule = extensionManager.getModuleEntry(
'@ohif/extension-cornerstone.utilityModule.common'
);
Expand Down Expand Up @@ -212,7 +226,7 @@ async function _loadSegments({ extensionManager, servicesManager, segDisplaySet,
Object.assign(segDisplaySet, results);
}

function _segmentationExists(segDisplaySet, segmentationService) {
function _segmentationExists(segDisplaySet, segmentationService: AppTypes.SegmentationService) {
// This should be abstracted with the CornerstoneCacheService
return segmentationService.getSegmentation(segDisplaySet.displaySetInstanceUID);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/cornerstone-dicom-seg/src/getToolbarModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getToolbarModule({ servicesManager }) {
export function getToolbarModule({ servicesManager }: withAppTypes) {
const { segmentationService, toolbarService, toolGroupService } = servicesManager.services;
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function PanelSegmentation({
commandsManager,
extensionManager,
configuration,
}) {
}: withAppTypes) {
const {
segmentationService,
viewportGridService,
Expand Down
4 changes: 2 additions & 2 deletions extensions/cornerstone-dicom-seg/src/utils/hydrationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function updateViewportsForSegmentationRendering({
}: {
viewportId: string;
loadFn: () => Promise<string>;
servicesManager: any;
servicesManager: AppTypes.ServicesManager;
referencedDisplaySetInstanceUID?: string;
}) {
const { cornerstoneViewportService, segmentationService, viewportGridService } =
Expand Down Expand Up @@ -134,7 +134,7 @@ function getUpdatedViewportsForSegmentation({
viewportId,
servicesManager,
referencedDisplaySetInstanceUID,
}) {
}: withAppTypes) {
const { hangingProtocolService, displaySetService, segmentationService, viewportGridService } =
servicesManager.services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function promptHydrateSEG({
viewportId,
preHydrateCallbacks,
hydrateSEGDisplaySet,
}) {
}: withAppTypes) {
const { uiViewportDialogService } = servicesManager.services;
const extensionManager = servicesManager._extensionManager;
const appConfig = extensionManager._appConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import _getStatusComponent from './_getStatusComponent';

const SEG_TOOLGROUP_BASE_NAME = 'SEGToolGroup';

function OHIFCornerstoneSEGViewport(props) {
function OHIFCornerstoneSEGViewport(props: withAppTypes) {
const {
children,
displaySets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const _generateReport = (measurementData, additionalFindingTypes, options = {})
return dataset;
};

const commandsModule = props => {
const commandsModule = (props: withAppTypes) => {
const { servicesManager } = props;
const { customizationService } = servicesManager.services;
const actions = {
Expand All @@ -57,7 +57,7 @@ const commandsModule = props => {
const reportBlob = dcmjs.data.datasetToBlob(srDataset);

//Create a URL for the binary.
var objectUrl = URL.createObjectURL(reportBlob);
const objectUrl = URL.createObjectURL(reportBlob);
window.location.assign(objectUrl);
},

Expand Down
10 changes: 7 additions & 3 deletions extensions/cornerstone-dicom-sr/src/getSopClassHandlerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ function addInstances(instances: InstanceMetadata[], displaySetService: DisplayS
* @param servicesManager is the services that can be used for creating
* @returns The list of display sets created for the given instances object
*/
function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager) {
function _getDisplaySetsFromSeries(
instances,
servicesManager: AppTypes.ServicesManager,
extensionManager
) {
// If the series has no instances, stop here
if (!instances || !instances.length) {
throw new Error('No instances were provided');
Expand Down Expand Up @@ -150,7 +154,7 @@ function _getDisplaySetsFromSeries(instances, servicesManager, extensionManager)
return [displaySet];
}

async function _load(displaySet, servicesManager, extensionManager) {
async function _load(displaySet, servicesManager: AppTypes.ServicesManager, extensionManager) {
const { displaySetService, measurementService } = servicesManager.services;
const dataSources = extensionManager.getDataSources();
const dataSource = dataSources[0];
Expand Down Expand Up @@ -223,7 +227,7 @@ function _checkIfCanAddMeasurementsToDisplaySet(
srDisplaySet,
newDisplaySet,
dataSource,
servicesManager
servicesManager: AppTypes.ServicesManager
) {
const { customizationService } = servicesManager.services;
let unloadedMeasurements = srDisplaySet.measurements.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const convertSites = (codingValues, sites) => {
*
*/
export default function hydrateStructuredReport(
{ servicesManager, extensionManager, appConfig },
{ servicesManager, extensionManager, appConfig }: withAppTypes,
displaySetInstanceUID
) {
const annotationManager = CsAnnotation.state.getAnnotationManager();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ServicesManager, ExtensionManager } from '@ohif/core';
import { ExtensionManager } from '@ohif/core';

import { setTrackingUniqueIdentifiersForElement } from '../tools/modules/dicomSRModule';

Expand All @@ -14,7 +14,7 @@ const MEASUREMENT_TRACKING_EXTENSION_ID = '@ohif/extension-measurement-tracking'

const SR_TOOLGROUP_BASE_NAME = 'SRToolGroup';

function OHIFCornerstoneSRViewport(props) {
function OHIFCornerstoneSRViewport(props: withAppTypes) {
const { children, dataSource, displaySets, viewportOptions, servicesManager, extensionManager } =
props;

Expand Down Expand Up @@ -369,7 +369,7 @@ OHIFCornerstoneSRViewport.propTypes = {
viewportLabel: PropTypes.string,
customProps: PropTypes.object,
viewportOptions: PropTypes.object,
servicesManager: PropTypes.instanceOf(ServicesManager).isRequired,
servicesManager: PropTypes.object.isRequired,
extensionManager: PropTypes.instanceOf(ExtensionManager).isRequired,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function _getInstanceFromSegmentations(segmentations, displaySetService) {
return { seriesMetadata, instance };
}

function updateSegmentationsChartDisplaySet({ servicesManager }): void {
function updateSegmentationsChartDisplaySet({ servicesManager }: withAppTypes): void {
const { segmentationService, displaySetService } = servicesManager.services;
const segmentations = segmentationService.getSegmentations();
const { seriesMetadata, instance } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cache } from '@cornerstonejs/core';

const LABELMAP = Enums.SegmentationRepresentations.Labelmap;

const commandsModule = ({ commandsManager, servicesManager }) => {
const commandsModule = ({ commandsManager, servicesManager }: withAppTypes) => {
const services = servicesManager.services;
const { displaySetService, viewportGridService, segmentationService } = services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { ActionButtons } from '@ohif/ui';
import { useTranslation } from 'react-i18next';

function DynamicExport({ commandsManager, servicesManager, extensionManager }) {
function DynamicExport({ commandsManager, servicesManager, extensionManager }: withAppTypes) {
const { segmentationService } = servicesManager.services;
const { t } = useTranslation('dynamicExport');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import DynamicVolumeControls from './DynamicVolumeControls';

const SOPClassHandlerId = '@ohif/extension-default.sopClassHandlerModule.stack';

export default function PanelGenerateImage({ servicesManager, commandsManager }) {
export default function PanelGenerateImage({ servicesManager, commandsManager }: withAppTypes) {
const { cornerstoneViewportService, viewportGridService, displaySetService } =
servicesManager.services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { setEnabledElement } from '../state';
import './OHIFCornerstoneViewport.css';
import CornerstoneOverlays from './Overlays/CornerstoneOverlays';
import getSOPInstanceAttributes from '../utils/measurementServiceMappings/utils/getSOPInstanceAttributes';
import CornerstoneServices from '../types/CornerstoneServices';
import CinePlayer from '../components/CinePlayer';
import { Types } from '@ohif/core';

Expand Down Expand Up @@ -100,26 +99,29 @@ function areEqual(prevProps, nextProps) {

// Todo: This should be done with expose of internal API similar to react-vtkjs-viewport
// Then we don't need to worry about the re-renders if the props change.
const OHIFCornerstoneViewport = React.memo(props => {
const OHIFCornerstoneViewport = React.memo((props: withAppTypes) => {
const {
displaySets,
dataSource,
viewportOptions,
displaySetOptions,
servicesManager,
onElementEnabled,
// eslint-disable-next-line react/prop-types
onElementDisabled,
isJumpToMeasurementDisabled,
// Note: you SHOULD NOT use the initialImageIdOrIndex for manipulation
// of the imageData in the OHIFCornerstoneViewport. This prop is used
// to set the initial state of the viewport's first image to render
// eslint-disable-next-line react/prop-types
initialImageIndex,
// if the viewport is part of a hanging protocol layout
// we should not really rely on the old synchronizers and
// you see below we only rehydrate the synchronizers if the viewport
// is not part of the hanging protocol layout. HPs should
// define their own synchronizers. Since the synchronizers are
// viewportId dependent and
// eslint-disable-next-line react/prop-types
isHangingProtocolLayout,
} = props;

Expand Down Expand Up @@ -152,7 +154,7 @@ const OHIFCornerstoneViewport = React.memo(props => {
viewportGridService,
stateSyncService,
viewportActionCornersService,
} = servicesManager.services as CornerstoneServices;
} = servicesManager.services;

const [viewportDialogState] = useViewportDialog();
// useCallback for scroll bar height calculation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CustomizableViewportOverlay from './CustomizableViewportOverlay';
import ViewportOrientationMarkers from './ViewportOrientationMarkers';
import ViewportImageSliceLoadingIndicator from './ViewportImageSliceLoadingIndicator';

function CornerstoneOverlays(props) {
function CornerstoneOverlays(props: withAppTypes) {
const { viewportId, element, scrollbarHeight, servicesManager } = props;
const { cornerstoneViewportService } = servicesManager.services;
const [imageSliceData, setImageSliceData] = useState({
Expand Down
Loading
Loading