diff --git a/src/shared/api/cbioportalInternalClientInstance.ts b/src/shared/api/cbioportalInternalClientInstance.ts index 1fd37c920fe..6f4352f4144 100644 --- a/src/shared/api/cbioportalInternalClientInstance.ts +++ b/src/shared/api/cbioportalInternalClientInstance.ts @@ -20,7 +20,11 @@ function proxyColumnStore(client: any, endpoint: string) { return; } - const method = `${endpoint}UsingPOSTWithHttpInfo`; + const method = endpoint.match( + new RegExp('fetchPatientTreatmentCounts|fetchSampleTreatmentCounts') + ) + ? `${endpoint}UsingWithHttpInfo` + : `${endpoint}UsingPOSTWithHttpInfo`; const old = client[method]; client[method] = function(params: any) { @@ -43,6 +47,8 @@ function proxyColumnStore(client: any, endpoint: string) { 'FilteredSamples', 'ClinicalDataDensity', 'MutationDataCounts', + 'PatientTreatmentCounts', + 'SampleTreatmentCounts', 'GenomicData', 'GenericAssay', ]; @@ -88,7 +94,11 @@ function proxyColumnStore(client: any, endpoint: string) { }; } - params.$domain = `//${host}/api/column-store`; + params.$domain = method.match( + new RegExp('PatientTreatmentCounts|SampleTreatmentCounts') + ) + ? `//${host}` + : `//${host}/api/column-store`; const url = old.apply(this, [params]); this.request = oldRequest; diff --git a/src/shared/api/validation.ts b/src/shared/api/validation.ts index 37142c20230..e12a55fd24a 100644 --- a/src/shared/api/validation.ts +++ b/src/shared/api/validation.ts @@ -1,4 +1,5 @@ import _ from 'lodash'; +import { array } from 'yargs'; export const isObject = (value: any) => { return ( @@ -84,8 +85,91 @@ const deleteFields: Record = { const sortFields: Record = { ClinicalDataBin: 'attributeId,specialValue', FilteredSamples: 'patientId,sampleId', + SampleTreatmentCounts: 'treatment,time', + PatientTreatmentCounts: 'treatment', }; +function getLegacyPatientTreatmentCountUrl(url: string) { + return url.replace( + /api\/treatments\/patient-counts\/fetch?/, + 'api/treatments/patient' + ); +} + +function getLegacySampleTreatmentCountUrl(url: string) { + return url.replace( + /api\/treatments\/sample-counts\/fetch?/, + 'api/treatments/sample' + ); +} + +const treatmentLegacyUrl: Record string> = { + PatientTreatmentCounts: getLegacyPatientTreatmentCountUrl, + SampleTreatmentCounts: getLegacySampleTreatmentCountUrl, +}; + +const treatmentConverter: Record any> = { + PatientTreatmentCounts: convertLegacyPatientTreatmentCountsToCh, + SampleTreatmentCounts: convertLegacySampleTreatmentCountsToCh, +}; + +function convertLegacySampleTreatmentCountsToCh(legacyData: any) { + const sampleIdSet = new Set(); + const treatments: Array<{ + time: string; + treatment: string; + count: number; + samples: Array; + }> = []; + + legacyData.forEach((legacySampleTreatment: any) => { + let treatment = { + time: legacySampleTreatment['time'], + treatment: legacySampleTreatment['treatment'], + count: legacySampleTreatment['count'], + samples: new Array(), + }; + + treatments.push(treatment); + const samples = legacySampleTreatment['samples']; + if (samples instanceof Array) { + samples.forEach(sample => { + sampleIdSet.add(sample['sampleId']); + }); + } + }); + return { + totalSamples: sampleIdSet.size, + treatments: treatments, + }; +} + +function convertLegacyPatientTreatmentCountsToCh(legacyData: any) { + const patientIdSet = new Set(); + const treatments: Array<{ treatment: string; count: number }> = []; + + legacyData.forEach((legacyTreatment: any) => { + let treatment = { + treatment: legacyTreatment['treatment'], + count: legacyTreatment['count'], + }; + treatments.push(treatment); + + const samples = legacyTreatment['samples']; + if (samples instanceof Array) { + samples.forEach(sample => { + patientIdSet.add(sample['patientId']); + }); + } + }); + + return { + totalPatients: patientIdSet.size, + totalSamples: 0, + patientTreatments: treatments, + }; +} + export function deepSort(inp: any, label: string) { const arrs = getArrays(inp, []); @@ -126,8 +210,11 @@ function attemptSort(keys: string[], arr: any) { export function compareCounts(clData: any, legacyData: any, label: string) { const clDataSorted = deepSort(clData, label); - const legacyDataSorted = deepSort(legacyData, label); + var legacyDataSorted = deepSort(legacyData, label); + if (treatmentConverter[label]) { + legacyDataSorted = treatmentConverter[label](legacyDataSorted); + } const result = JSON.stringify(clDataSorted) === JSON.stringify(legacyDataSorted); @@ -167,7 +254,10 @@ export function validate( return chXHR .then(({ body, elapsedTime }: any) => { - const legacyUrl = url.replace(/column-store\//, ''); + let legacyUrl = url.replace(/column-store\//, ''); + if (treatmentLegacyUrl[label]) { + legacyUrl = treatmentLegacyUrl[label](legacyUrl); + } const legacyXHR = $.ajax({ method: 'post', url: legacyUrl,