Skip to content

Commit

Permalink
refactor(load-data): factor out pickBaseDicom
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Mar 25, 2024
1 parent 618d07f commit 429e065
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/store/load-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
importDataSources,
toDataSelection,
} from '@/src/io/import/importDataSources';
import { isLoadableResult } from '@/src/io/import/common';
import { LoadableResult, isLoadableResult } from '@/src/io/import/common';
import { useDICOMStore } from '@/src/store/datasets-dicom';
import { useDatasetStore } from '@/src/store/datasets';
import { useMessageStore } from '@/src/store/messages';
Expand Down Expand Up @@ -107,6 +107,20 @@ function useLoadingNotifications() {
};
}

function pickBaseDicom(loadableDataSources: LoadableResult[]) {
// pick dicom dataset as primary selection if available
const dicoms = loadableDataSources.filter(
({ dataType }) => dataType === 'dicom'
);
const dicomStore = useDICOMStore();
const baseDicom = dicoms.find((dicomSource) => {
const volumeInfo = dicomStore.volumeInfo[dicomSource.dataID];
const modality = volumeInfo?.Modality;
return BASE_MODALITY_TYPES.includes(modality);
});
return baseDicom;
}

const useLoadDataStore = defineStore('loadData', () => {
const { startLoading, stopLoading, setError, isLoading } =
useLoadingNotifications();
Expand Down Expand Up @@ -139,17 +153,7 @@ const useLoadDataStore = defineStore('loadData', () => {
const loadableDataSources = succeeded.flatMap((result) => {
return result.data.filter(isLoadableResult);
});
// pick dicom dataset as primary selection if available
const dicoms = loadableDataSources.filter(
({ dataType }) => dataType === 'dicom'
);
const dicomStore = useDICOMStore();
// prefer some modalities as primary selection
const baseDicom = dicoms.find((dicomSource) => {
const volumeInfo = dicomStore.volumeInfo[dicomSource.dataID];
const modality = volumeInfo?.Modality;
return BASE_MODALITY_TYPES.includes(modality);
});
const baseDicom = pickBaseDicom(loadableDataSources);
const primaryDataset = baseDicom ?? loadableDataSources[0];
const selection = toDataSelection(primaryDataset);
if (selection) {
Expand Down

0 comments on commit 429e065

Please sign in to comment.