Skip to content

Commit

Permalink
Study page clinical data tab: fix download after pagination change (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman committed May 16, 2024
1 parent 911ae1e commit d1b6cd5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
44 changes: 37 additions & 7 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9645,11 +9645,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 @@ -9673,8 +9704,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 @@ -3173,7 +3173,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 @@ -3184,8 +3185,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

0 comments on commit d1b6cd5

Please sign in to comment.