Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
igoroctaviano committed Jan 31, 2025
1 parent 8cfcb07 commit 9a9d0aa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 24 deletions.
29 changes: 17 additions & 12 deletions src/components/CaseViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Routes, Route, useLocation, useParams } from 'react-router-dom'
import { Layout, Menu } from 'antd'
import * as dcmjs from 'dcmjs'
import * as dmv from 'dicom-microscopy-viewer'
import { useEffect, useState } from 'react'

import { AnnotationSettings } from '../AppConfig'
Expand Down Expand Up @@ -67,7 +66,7 @@ function ParametrizedSlideViewer ({
enableAnnotationTools: boolean
annotations: AnnotationSettings[]
}): JSX.Element | null {
const { studyInstanceUID = '', seriesInstanceUID = '' } = useParams<{ studyInstanceUID: string; seriesInstanceUID: string }>()
const { studyInstanceUID = '', seriesInstanceUID = '' } = useParams<{ studyInstanceUID: string, seriesInstanceUID: string }>()
const location = useLocation()
const [selectedSlide, setSelectedSlide] = useState(slides.find((slide: Slide) => {
return slide.seriesInstanceUIDs.find((uid: string) => {
Expand All @@ -77,17 +76,21 @@ function ParametrizedSlideViewer ({
const [derivedDataset, setDerivedDataset] = useState<NaturalizedInstance | null>(null)

useEffect(() => {
const findReferencedSlide = async ({ clients, studyInstanceUID, seriesInstanceUID }: { clients: { [key: string]: DicomWebManager }, studyInstanceUID: string, seriesInstanceUID: string }) => new Promise<ReferencedSlideResult | null>((resolve, reject) => {
try {
const allClients = Object.values(StorageClasses).map((storageClass) => clients[storageClass])
allClients.map(async (client) => {
const seriesMetadata = await client.retrieveSeriesMetadata({
const findReferencedSlide = async ({ clients, studyInstanceUID, seriesInstanceUID }: {
clients: { [key: string]: DicomWebManager }
studyInstanceUID: string
seriesInstanceUID: string
}): Promise<ReferencedSlideResult | null> => await new Promise<ReferencedSlideResult | null>((resolve, reject) => {
try {
const allClients = Object.values(StorageClasses).map((storageClass) => clients[storageClass])
Promise.all(allClients.map(async (client) => {
const seriesMetadata = await client.retrieveSeriesMetadata({
studyInstanceUID: studyInstanceUID,
seriesInstanceUID: seriesInstanceUID
})
const [naturalizedSeriesMetadata] = seriesMetadata.map((metadata) => naturalizeDataset(metadata)) as NaturalizedInstance[]

if (naturalizedSeriesMetadata.ReferencedSeriesSequence) {
if (naturalizedSeriesMetadata.ReferencedSeriesSequence != null) {
const referencedSeriesInstanceUID = naturalizedSeriesMetadata.ReferencedSeriesSequence[0].SeriesInstanceUID
const referencedSlide = slides.find((slide: Slide) => {
return slide.seriesInstanceUIDs.find((uid: string) => {
Expand All @@ -101,7 +104,7 @@ function ParametrizedSlideViewer ({
const imageLibrary = naturalizedSeriesMetadata.ContentSequence?.find(
contentItem => contentItem.ConceptNameCodeSequence[0].CodeValue === IMAGE_LIBRARY_CONCEPT_NAME_CODE
)
if (imageLibrary?.ContentSequence?.[0]?.ContentSequence?.[0]?.ReferencedSOPSequence?.[0]) {
if ((imageLibrary?.ContentSequence?.[0]?.ContentSequence?.[0]?.ReferencedSOPSequence?.[0]) != null) {
const referencedSOPInstanceUID = imageLibrary.ContentSequence[0].ContentSequence[0].ReferencedSOPSequence[0].ReferencedSOPInstanceUID
const referencedSlide = slides.find((slide: Slide) => {
return slide.volumeImages.find((image: { SOPInstanceUID: string }) => {
Expand All @@ -110,18 +113,20 @@ function ParametrizedSlideViewer ({
})
resolve({ slide: referencedSlide, metadata: naturalizedSeriesMetadata })
}
})
})).catch(reject)
} catch (error) {
reject(error)
}
})

if (selectedSlide == null) {
findReferencedSlide({ clients, studyInstanceUID, seriesInstanceUID }).then((result: ReferencedSlideResult | null) => {
void findReferencedSlide({ clients, studyInstanceUID, seriesInstanceUID }).then((result: ReferencedSlideResult | null) => {
if (result != null) {
setSelectedSlide(result.slide)
setDerivedDataset(result.metadata)
}
}).catch(error => {
console.error('Error finding referenced slide:', error)
})
}
}, [slides, studyInstanceUID, seriesInstanceUID])
Expand Down
60 changes: 48 additions & 12 deletions src/components/SlideViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ interface SlideViewerProps extends RouteComponentProps {
email: string
}
selectedPresentationStateUID?: string
derivedDataset?: dmv.metadata.Dataset // Add this line
derivedDataset?: dmv.metadata.Dataset // Add this line
}

interface SlideViewerState {
Expand Down Expand Up @@ -977,7 +977,7 @@ class SlideViewer extends React.Component<SlideViewerProps, SlideViewerState> {
return this.defaultRoiStyle
}

loadDerivedDataset = (derivedDataset: dmv.metadata.Dataset): void => {
loadDerivedDataset = (derivedDataset: dmv.metadata.Dataset): void => {
console.debug('Loading derived dataset')
const Comprehensive3DSR = '1.2.840.10008.5.1.4.1.1.88.34'
const MicroscopyBulkSimpleAnnotation = '1.2.840.10008.5.1.4.1.1.88.24'
Expand Down Expand Up @@ -1022,8 +1022,8 @@ class SlideViewer extends React.Component<SlideViewerProps, SlideViewerState> {
* with 3D spatial coordinates defined in the same frame of reference as the
* currently selected series and add them to the VOLUME image viewer.
*/
addAnnotations (): Promise<void> {
return new Promise<void>((resolve, reject) => {
async addAnnotations (): Promise<void> {
return await new Promise<void>((resolve, reject) => {
console.info('search for Comprehensive 3D SR instances')
const client = this.props.clients[StorageClasses.COMPREHENSIVE_3D_SR]
client.searchForInstances({
Expand Down Expand Up @@ -1161,7 +1161,7 @@ class SlideViewer extends React.Component<SlideViewerProps, SlideViewerState> {
* selected series and add them to the VOLUME image viewer.
*/
addAnnotationGroups = async (): Promise<void> => {
return new Promise<void>((resolve, reject) => {
return await new Promise<void>((resolve, reject) => {
console.info('search for Microscopy Bulk Simple Annotations instances')
const client = this.props.clients[
StorageClasses.MICROSCOPY_BULK_SIMPLE_ANNOTATION
Expand Down Expand Up @@ -1257,15 +1257,15 @@ class SlideViewer extends React.Component<SlideViewerProps, SlideViewerState> {
reject(error)
})
})
}
}

/**
* Retrieve Segmentation instances that contain segments defined in the same
* frame of reference as the currently selected series and add them to the
* VOLUME image viewer.
*/
addSegmentations = async (): Promise<void> => {
return new Promise<void>((resolve, reject) => {
return await new Promise<void>((resolve, reject) => {
console.info('search for Segmentation instances')
const client = this.props.clients[StorageClasses.SEGMENTATION]
client.searchForSeries({
Expand Down Expand Up @@ -1352,7 +1352,7 @@ class SlideViewer extends React.Component<SlideViewerProps, SlideViewerState> {
* VOLUME image viewer.
*/
addParametricMaps = async (): Promise<void> => {
return new Promise<void>((resolve, reject) => {
return await new Promise<void>((resolve, reject) => {
console.info('search for Parametric Map instances')
const client = this.props.clients[StorageClasses.PARAMETRIC_MAP]
client.searchForSeries({
Expand Down Expand Up @@ -1462,10 +1462,46 @@ class SlideViewer extends React.Component<SlideViewerProps, SlideViewerState> {
this.setDefaultPresentationState()
this.loadPresentationStates()

this.addAnnotations().then(() => this.props.derivedDataset && this.loadDerivedDataset(this.props.derivedDataset))
this.addAnnotationGroups().then(() => this.props.derivedDataset && this.loadDerivedDataset(this.props.derivedDataset))
this.addSegmentations().then(() => this.props.derivedDataset && this.loadDerivedDataset(this.props.derivedDataset))
this.addParametricMaps().then(() => this.props.derivedDataset && this.loadDerivedDataset(this.props.derivedDataset))
// Handle promises properly with catch blocks
void this.addAnnotations()
.then(() => {
if (this.props.derivedDataset != null) {
this.loadDerivedDataset(this.props.derivedDataset)
}
})
.catch(error => {
console.error('Failed to add annotations:', error)
})

void this.addAnnotationGroups()
.then(() => {
if (this.props.derivedDataset != null) {
this.loadDerivedDataset(this.props.derivedDataset)
}
})
.catch(error => {
console.error('Failed to add annotation groups:', error)
})

void this.addSegmentations()
.then(() => {
if (this.props.derivedDataset != null) {
this.loadDerivedDataset(this.props.derivedDataset)
}
})
.catch(error => {
console.error('Failed to add segmentations:', error)
})

void this.addParametricMaps()
.then(() => {
if (this.props.derivedDataset != null) {
this.loadDerivedDataset(this.props.derivedDataset)
}
})
.catch(error => {
console.error('Failed to add parametric maps:', error)
})
}

onRoiModified = (event: CustomEventInit): void => {
Expand Down

0 comments on commit 9a9d0aa

Please sign in to comment.