Skip to content

Commit

Permalink
Merge pull request #4616 from haynescd/feature/10081-Support-filter-u…
Browse files Browse the repository at this point in the history
…rls-for-patientIds

✨ Add PatientIdentifiers URL Parameter
  • Loading branch information
alisman authored May 19, 2023
2 parents 8ac1d92 + 8273f1f commit 182f679
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 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
76 changes: 69 additions & 7 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
PatientTreatmentRow,
ResourceData,
Sample,
SampleFilter,
SampleIdentifier,
SampleMolecularIdentifier,
SampleTreatmentRow,
Expand Down Expand Up @@ -267,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 @@ -2165,14 +2170,20 @@ export class StudyViewPageStore
// We do not support studyIds in the query filters
let filters: Partial<StudyViewFilter> = {};
if (query.filterJson) {
try {
filters = JSON.parse(
decodeURIComponent(query.filterJson)
) as Partial<StudyViewFilter>;
this.updateStoreByFilters(filters);
} catch (e) {
// TODO: add some logging here?
const parsedFilterJson = this.parseRawFilterJson(query.filterJson);
if (query.filterJson.includes('patientIdentifiers')) {
const sampleListIds = studyIds.map(s => s.concat('', '_all'));
const samples = await this.fetchSamplesWithSampleListIds(
sampleListIds
);
filters = this.getStudyViewFilterFromPatientIdentifierFilter(
parsedFilterJson as PatientIdentifierFilter,
samples
);
} else {
filters = parsedFilterJson as Partial<StudyViewFilter>;
}
this.updateStoreByFilters(filters);
} else if (query.filterAttributeId && query.filterValues) {
const clinicalAttributes = _.uniqBy(
await defaultClient.fetchClinicalAttributesUsingPOST({
Expand Down Expand Up @@ -2224,6 +2235,57 @@ export class StudyViewPageStore
}
}

parseRawFilterJson(filterJson: string): any {
let rawJson;
try {
rawJson = JSON.parse(decodeURIComponent(filterJson));
} catch (e) {
console.error('FilterJson invalid Json: error: ', e);
}
return rawJson;
}

fetchSamplesWithSampleListIds(sampleListIds: string[]) {
return defaultClient.fetchSamplesUsingPOST({
sampleFilter: {
sampleListIds: sampleListIds,
} as SampleFilter,
projection: 'SUMMARY',
});
}

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 =>
patientIdentifiersMap.has(s.studyId.concat('_', s.patientId))
)
.map(s => ({
sampleId: s.sampleId,
studyId: s.studyId,
}));
}

@computed
get initialFilters(): StudyViewFilter {
let initialFilter = {} as StudyViewFilter;
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 182f679

Please sign in to comment.