Skip to content

Commit

Permalink
✨ Add PatientIdentifiers URL Parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed May 9, 2023
1 parent 0e11c0b commit cbb851d
Showing 1 changed file with 61 additions and 7 deletions.
68 changes: 61 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 {
patientIdentifiers: PatientIdentifier[];
}

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

export class StudyViewPageStore
implements IAnnotationFilterSettings, ISettingsMenuButtonVisible {
private reactionDisposers: IReactionDisposer[] = [];
Expand Down Expand Up @@ -2165,14 +2175,23 @@ 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 samples = await this.fetchSamplesWithStudyIds(studyIds);
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 +2243,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;
}

fetchSamplesWithStudyIds(studyIds: string[]) {
return defaultClient.fetchSamplesUsingPOST({
sampleFilter: {
sampleListIds: studyIds.map(s => s.concat('', '_all')),
} as SampleFilter,
projection: 'SUMMARY',
});
}

convertPatientIdentifiersToSampleIdentifiers(
patientIdentifiers: Array<PatientIdentifier>,
samples: Sample[]
): SampleIdentifier[] {
return samples
.filter(s =>
patientIdentifiers.some(
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

0 comments on commit cbb851d

Please sign in to comment.