Skip to content

Commit

Permalink
Update with PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed May 11, 2023
1 parent 1472e6c commit 8273f1f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
9 changes: 7 additions & 2 deletions src/pages/studyView/StudyViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,18 @@ export default class StudyViewPage extends React.Component<
newStudyViewFilter.sharedCustomData = params.sharedCustomData;
}
}

let updateStoreFromURLPromise = remoteData(() => Promise.resolve([]));
if (!_.isEqual(newStudyViewFilter, this.store.studyViewQueryFilter)) {
this.store.updateStoreFromURL(newStudyViewFilter);
this.store.studyViewQueryFilter = newStudyViewFilter;
updateStoreFromURLPromise = remoteData(async () => {
await this.store.updateStoreFromURL(newStudyViewFilter);
return [];
});
}

onMobxPromise(
this.store.queriedPhysicalStudyIds,
[this.store.queriedPhysicalStudyIds, updateStoreFromURLPromise],
(strArr: string[]) => {
this.store.initializeReaction();
trackEvent({
Expand Down
45 changes: 25 additions & 20 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ import { PageType } from 'shared/userSession/PageType';
import { FeatureFlagEnum } from 'shared/featureFlags';
import intersect from 'fast_array_intersect';
import { PillStore } from 'shared/components/PillTag/PillTag';
import {
PatientIdentifier,
PatientIdentifierFilter,
} from 'shared/model/PatientIdentifierFilter';

export const STUDY_VIEW_FILTER_AUTOSUBMIT = 'study_view_filter_autosubmit';

Expand Down Expand Up @@ -390,15 +394,6 @@ enum CustomDataTypeEnum {
NUMERICAL = 'NUMERICAL',
}

interface PatientIdentifierFilter {
patientIdentifiers: PatientIdentifier[];
}

interface PatientIdentifier {
patientId: string;
studyId: string;
}

export class StudyViewPageStore
implements IAnnotationFilterSettings, ISettingsMenuButtonVisible {
private reactionDisposers: IReactionDisposer[] = [];
Expand Down Expand Up @@ -2181,16 +2176,10 @@ export class StudyViewPageStore
const samples = await this.fetchSamplesWithSampleListIds(
sampleListIds
);
const {
patientIdentifiers,
} = parsedFilterJson as PatientIdentifierFilter;
const sampleIdentifiers = this.convertPatientIdentifiersToSampleIdentifiers(
patientIdentifiers,
filters = this.getStudyViewFilterFromPatientIdentifierFilter(
parsedFilterJson as PatientIdentifierFilter,
samples
);
if (sampleIdentifiers.length > 0) {
filters.sampleIdentifiers = sampleIdentifiers;
}
} else {
filters = parsedFilterJson as Partial<StudyViewFilter>;
}
Expand Down Expand Up @@ -2265,15 +2254,31 @@ export class StudyViewPageStore
});
}

getStudyViewFilterFromPatientIdentifierFilter(
patientIdentifierFilter: PatientIdentifierFilter,
samples: Sample[]
): Partial<StudyViewFilter> {
const filters: Partial<StudyViewFilter> = {};
const sampleIdentifiers = this.convertPatientIdentifiersToSampleIdentifiers(
patientIdentifierFilter.patientIdentifiers,
samples
);
if (sampleIdentifiers.length > 0) {
filters.sampleIdentifiers = sampleIdentifiers;
}
return filters;
}

convertPatientIdentifiersToSampleIdentifiers(
patientIdentifiers: Array<PatientIdentifier>,
samples: Sample[]
): SampleIdentifier[] {
const patientIdentifiersMap = new Map<string, PatientIdentifier>(
patientIdentifiers.map(p => [p.studyId.concat('_', p.patientId), p])
);
return samples
.filter(s =>
patientIdentifiers.some(
p => p.patientId === s.patientId && p.studyId === s.studyId
)
patientIdentifiersMap.has(s.studyId.concat('_', s.patientId))
)
.map(s => ({
sampleId: s.sampleId,
Expand Down
8 changes: 8 additions & 0 deletions src/shared/model/PatientIdentifierFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface PatientIdentifierFilter {
patientIdentifiers: PatientIdentifier[];
}

export interface PatientIdentifier {
patientId: string;
studyId: string;
}

0 comments on commit 8273f1f

Please sign in to comment.