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

✨ Add PatientIdentifiers URL Parameter #4616

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
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);
haynescd marked this conversation as resolved.
Show resolved Hide resolved
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,
haynescd marked this conversation as resolved.
Show resolved Hide resolved
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;
}