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

Study page clinical data tab: fix download after pagination change #4912

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9790,11 +9790,42 @@ export class StudyViewPageStore
if (this.selectedSamples.result.length === 0) {
return Promise.resolve('');
}
let sampleClinicalDataResponse = await getAllClinicalDataByStudyViewFilter(
this.filters,
undefined,
undefined
);

const BATCH_SIZE = 25000;

const getBatch = (page: number) =>
getAllClinicalDataByStudyViewFilter(
this.filters,
undefined,
undefined,
'desc',
BATCH_SIZE,
page
);

// get first page, which gives us the total count, which we can use to figure out how many pages
// we need to download
let sampleClinicalDataResponse = await getBatch(0);

// create a target object to merge batches onto
// the results are { sampleId: clinicaldData[] }
// where the counted "rows" are samples. So a count of 1000 means you getting all clinical data from 1000
// samples, grouped by sampleId
const resultObj = { ...sampleClinicalDataResponse.data };

// if there are more than one batch, we need to fetch them and merge them into result
if (sampleClinicalDataResponse.totalItems > BATCH_SIZE) {
const pages = Math.ceil(
sampleClinicalDataResponse.totalItems / BATCH_SIZE
);
// start at one because we already have the first page from the initial fetch up above
let i = 1;
do {
const batch = await getBatch(i);
i++;
Object.assign(resultObj, batch.data);
} while (i < pages);
}

let clinicalAttributesNameSet = _.reduce(
this.clinicalAttributes.result,
Expand All @@ -9818,8 +9849,7 @@ export class StudyViewPageStore
patientId: next.patientId,
sampleId: next.sampleId,
} as { [attributeId: string]: string };
const clinicalData =
sampleClinicalDataResponse.data[next.uniqueSampleKey];
const clinicalData = resultObj[next.uniqueSampleKey];
_.forEach(
clinicalData,
(attr: ClinicalData) =>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/studyView/StudyViewUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3158,7 +3158,8 @@ export async function getAllClinicalDataByStudyViewFilter(
searchTerm: string | undefined,
sortAttributeId: any,
sortDirection: any = 'asc',
pageSize: number = 500
pageSize: number,
pageNumber: number
): Promise<{
totalItems: number;
data: { [uniqueSampleKey: string]: ClinicalData[] };
Expand All @@ -3169,8 +3170,8 @@ export async function getAllClinicalDataByStudyViewFilter(
] = await internalClient
.fetchClinicalDataClinicalTableUsingPOSTWithHttpInfo({
studyViewFilter,
pageSize,
pageNumber: 0,
pageSize: pageSize | 500,
pageNumber: pageNumber || 0,
searchTerm: searchTerm,
sortBy: sortAttributeId,
direction: sortDirection?.toUpperCase(),
Expand Down
3 changes: 2 additions & 1 deletion src/pages/studyView/tabs/ClinicalDataTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ async function fetchClinicalDataForStudyViewClinicalDataTab(
searchTerm,
sortAttributeId,
sortDirection,
recordLimit
recordLimit,
0
);

const aggregatedSampleClinicalData = _.mapValues(
Expand Down
Loading