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

On Study View handle larger number of resource files #5034

Merged
merged 10 commits into from
Nov 1, 2024
47 changes: 38 additions & 9 deletions src/pages/studyView/resources/FilesAndLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ class FilesLinksTableComponent extends LazyMobXTable<{

const RECORD_LIMIT = 500;

function getResourceDataOfEntireStudy(studyIds: string[]) {
// Only handle the first studyId for now. Can be expanded to make a call per
// studyId.
const studyId = studyIds[0];
const allResources = internalClient.getAllStudyResourceDataInStudyPatientSampleUsingGET(
{
studyId: studyId,
projection: 'DETAILED',
}
);
return allResources;
}

function getResourceDataOfPatients(studyClinicalData: {
[uniqueSampleKey: string]: ClinicalData[];
}) {
Expand Down Expand Up @@ -97,7 +110,7 @@ function buildItemsAndResources(resourceData: {

async function fetchFilesLinksData(
filters: StudyViewFilter,
sampleIdResourceData: { [sampleId: string]: ResourceData[] },
selectedSamples: Array<any>,
searchTerm: string | undefined,
sortAttributeId: string | undefined,
sortDirection: 'asc' | 'desc' | undefined,
Expand All @@ -112,13 +125,29 @@ async function fetchFilesLinksData(
0
);

const resourcesForPatients = await getResourceDataOfPatients(
studyClinicalDataResponse.data
const selectedStudyIds = [
...new Set(selectedSamples.map(item => item.studyId)),
];

// sampleIds (+patientIds) for the selectedSamples
const selectedIds = new Map([
...new Map(selectedSamples.map(item => [item.sampleId, item.studyId])),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is strange. why instantiate maps inside of the map? i think just

   new Map([...selectedSamples.map(xxx)])

...new Map(selectedSamples.map(item => [item.patientId, item.studyId])),
]);

// Fetch resources for entire study
const resourcesForEntireStudy = await getResourceDataOfEntireStudy(
hweej marked this conversation as resolved.
Show resolved Hide resolved
selectedStudyIds
);
const resourcesForPatientsAndSamples: { [key: string]: ResourceData[] } = {
...sampleIdResourceData,
...resourcesForPatients,
};

// Filter the resources to consist of only studyView selected samples
// Also keep patient level resources (e.g. Those don't have a sampleId)
const resourcesForPatientsAndSamples = _(resourcesForEntireStudy)
.filter(resource =>
selectedIds.has(resource.sampleId || resource.patientId)
)
.groupBy(r => r.patientId)
.value();

// we create objects with the necessary properties for each resource
// calculate the total number of resources per patient.
Expand Down Expand Up @@ -197,7 +226,6 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
await: () => [
this.props.store.selectedSamples,
this.props.store.resourceDefinitions,
this.props.store.sampleResourceData,
],
onError: () => {},
invoke: async () => {
Expand All @@ -207,12 +235,13 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {

const resources = await fetchFilesLinksData(
this.props.store.filters,
this.props.store.sampleResourceData.result!,
this.props.store.selectedSamples.result,
this.searchTerm,
'patientId',
'asc',
RECORD_LIMIT
);

return Promise.resolve(resources);
},
});
Expand Down
Loading