Skip to content

Commit

Permalink
Merge pull request #184 from CanDIG/bugfix/downed-servers
Browse files Browse the repository at this point in the history
DIG-1820 / DIG-1832: Redscreen errors on prod
  • Loading branch information
OrdiNeu authored Oct 23, 2024
2 parents 4398b13 + 00c730a commit c742987
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
export function aggregateObj(stat, aggregateObj, aggregator = (object, key) => object[key]) {
const count = { ...aggregateObj };
Object.keys(stat).forEach((key) => {
const value = parseInt(aggregator(stat, key), 10);
if (key in count) {
count[key] += aggregator(stat, key);
count[key] += value;
} else {
count[key] = aggregator(stat, key);
count[key] = value;
}
});
return count;
Expand Down
6 changes: 4 additions & 2 deletions src/views/clinicalGenomic/search/SearchHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ function SearchHandler({ setLoading }) {
// Reorder the data, and fill out the patients per cohort
const clinicalData = {};
data.forEach((site) => {
clinicalData[site.location.name] = site?.results;
if ('results' in site) {
clinicalData[site.location.name] = site?.results;
}
});

const genomicData = data
.map((site) =>
site.results.genomic?.map((caseData) => {
site?.results?.genomic?.map((caseData) => {
caseData.location = site.location;
return caseData;
})
Expand Down
6 changes: 3 additions & 3 deletions src/views/clinicalGenomic/widgets/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function Sidebar() {
filter: {
node: [readerContext?.programs?.map((loc) => loc.location.name) || []], // Set your default nodes
exclude_cohorts: [
readerContext?.programs?.map((loc) => loc?.results?.items.map((cohort) => cohort.program_id)).flat(1) || []
readerContext?.programs?.map((loc) => loc?.results?.items?.map((cohort) => cohort.program_id)).flat(1) || []
], // Set cohorts to empty array or whichever default value you want
query: {}
}
Expand All @@ -464,8 +464,8 @@ function Sidebar() {

// Parse out what we need:
const sites = readerContext?.programs?.map((loc) => loc.location.name) || [];
const cohorts = readerContext?.federation?.map((loc) => loc.results.map((cohort) => cohort.program_id))?.flat(1) || [] || [];
const authorizedCohorts = readerContext?.programs?.flatMap((loc) => loc?.results?.items.map((cohort) => cohort.program_id)) || [];
const cohorts = readerContext?.federation?.map((loc) => loc.results?.map((cohort) => cohort.program_id) || [])?.flat(1) || [];
const authorizedCohorts = readerContext?.programs?.flatMap((loc) => loc?.results?.items?.map((cohort) => cohort.program_id)) || [];
const treatmentTypes = ExtractSidebarElements('treatment_types');
const tumourPrimarySites = ExtractSidebarElements('tumour_primary_sites');
const systemicTherapyDrugNames = ExtractSidebarElements('drug_names');
Expand Down
14 changes: 5 additions & 9 deletions src/views/summary/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ function Summary() {

/* Aggregated count of federated data */
function federationStatCount(data, endpoint) {
const candigDataSouceCollection = {};
const candigDataSourceCollection = {};

if (data && Array.isArray(data)) {
// Fake Server with same URL
// data[0].location[0] = 'UHN';
// data[0].location[1] = 'Ontario';
// data[0].location[2] = 'ca-on';

let count = 0;
data?.forEach((stat) => {
// Federation aggregate count of stats
count += 1;
if (!stat.results) {
// Something went wrong
return;
Expand All @@ -74,14 +72,12 @@ function Summary() {
case '/individual_count':
setIndividualCount((oldIndividualCount) => aggregateObj(stat.results, oldIndividualCount));
if (stat.location) {
if (!(stat.location['province-code'] in candigDataSouceCollection)) {
candigDataSouceCollection[stat.location['province-code']] = 0;
if (!(stat.location['province-code'] in candigDataSourceCollection)) {
candigDataSourceCollection[stat.location['province-code']] = 0;
}
candigDataSouceCollection[stat.location['province-code']] += parseInt(stat.results.individual_count, 10);
candigDataSourceCollection[stat.location['province-code']] += parseInt(stat.results.individual_count, 10);

if (count === data.length) {
setCanDigDataSource(candigDataSouceCollection);
}
setCanDigDataSource(candigDataSourceCollection);
}

break;
Expand Down

0 comments on commit c742987

Please sign in to comment.