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
Changes from 1 commit
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
71 changes: 64 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 @@ -389,6 +390,15 @@ enum CustomDataTypeEnum {
NUMERICAL = 'NUMERICAL',
}

interface PatientIdentifierFilter {
haynescd marked this conversation as resolved.
Show resolved Hide resolved
patientIdentifiers: PatientIdentifier[];
}

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

export class StudyViewPageStore
implements IAnnotationFilterSettings, ISettingsMenuButtonVisible {
private reactionDisposers: IReactionDisposer[] = [];
Expand Down Expand Up @@ -2165,14 +2175,26 @@ 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
);
const {
patientIdentifiers,
} = parsedFilterJson as PatientIdentifierFilter;
const sampleIdentifiers = this.convertPatientIdentifiersToSampleIdentifiers(
patientIdentifiers,
samples
);
if (sampleIdentifiers.length > 0) {
filters.sampleIdentifiers = sampleIdentifiers;
}
} 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 +2246,41 @@ 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',
});
}

convertPatientIdentifiersToSampleIdentifiers(
patientIdentifiers: Array<PatientIdentifier>,
samples: Sample[]
): SampleIdentifier[] {
return samples
.filter(s =>
patientIdentifiers.some(
haynescd marked this conversation as resolved.
Show resolved Hide resolved
p => p.patientId === s.patientId && p.studyId === s.studyId
)
)
.map(s => ({
sampleId: s.sampleId,
studyId: s.studyId,
}));
}

@computed
get initialFilters(): StudyViewFilter {
let initialFilter = {} as StudyViewFilter;
Expand Down