Skip to content

Commit

Permalink
fix(loadUserFiles): no named segmentation image as primary
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Apr 29, 2024
1 parent 10097fe commit 6d2ea50
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/actions/loadUserFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const BASE_MODALITY_TYPES = {
DX: { priority: 1 },
} as const;

const SEGMENTATION_EXTENSION = 'segmentation';

function findBaseDicom(loadableDataSources: Array<LoadableResult>) {
// find dicom dataset for primary selection if available
const dicoms = loadableDataSources.filter(
Expand Down Expand Up @@ -73,6 +75,25 @@ function findBaseDicom(loadableDataSources: Array<LoadableResult>) {
return undefined;
}

function isSegmentation(extension: string, name: string) {
const extensions = name.split('.').slice(1);
return extensions.includes(extension);
}

// does not pick segmentation images
function findBaseImage(loadableDataSources: Array<LoadableResult>) {
const baseImages = loadableDataSources
.filter(({ dataType }) => dataType === 'image')
.filter((importResult) => {
const name = getDataSourceName(importResult.dataSource);
if (!name) return false;
return !isSegmentation(SEGMENTATION_EXTENSION, name);
});

if (baseImages.length) return baseImages[0];
return undefined;
}

// returns image and dicom sources, no config files
function filterLoadableDataSources(
succeeded: Array<PipelineResultSuccess<ImportResult>>
Expand Down Expand Up @@ -100,8 +121,7 @@ function filterMatchingNames(
}))
.filter(({ name }) => {
if (!name) return false;
const extensions = name.split('.').slice(1);
const hasExtension = extensions.includes(extension);
const hasExtension = isSegmentation(extension, name);
const nameMatchesPrimary = name.startsWith(primaryNamePrefix);
return hasExtension && nameMatchesPrimary;
})
Expand All @@ -119,7 +139,10 @@ function findBaseDataSource(
) {
const loadableDataSources = filterLoadableDataSources(succeeded);
const baseDicom = findBaseDicom(loadableDataSources);
return baseDicom ?? loadableDataSources[0];
if (baseDicom) return baseDicom;
const baseImage = findBaseImage(loadableDataSources);
if (baseImage) return baseImage;
return loadableDataSources[0];
}

function filterOtherVolumesInStudy(
Expand Down Expand Up @@ -172,7 +195,11 @@ function loadSegmentations(
matchNames: boolean
) {
const matchingNames = matchNames
? filterMatchingNames(primaryDataSource, succeeded, 'segmentation').filter(
? filterMatchingNames(
primaryDataSource,
succeeded,
SEGMENTATION_EXTENSION
).filter(
isVolumeResult // filter out models
)
: [];
Expand Down

0 comments on commit 6d2ea50

Please sign in to comment.