From 251d7e27ba591f90a0448143a34ff1737c25c811 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Mon, 18 Mar 2024 09:21:12 +0100 Subject: [PATCH 1/6] feat(chart): add accumulated values property WIP --- packages/demo/src/AppCCP.svelte | 12 ++++++ .../results/ChartComponent.wc.svelte | 38 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index fd06e5ae..48e27bf9 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -265,6 +265,18 @@ chartType="bar" xAxisTitle="Probentypen" yAxisTitle="Probenanzahl" + accumulatedValues={JSON.stringify([ + { + name: "Gewebe Schockgefroren", + values: [ + "tissue-frozen", + "tissue-ffpe", + "tumor-tissue-ffpe", + "normal-tissue-ffpe", + "other-tissue-ffpe", + ], + }, + ])} filterRegex="^(?!(tissue-other|buffy-coat|peripheral-blood-cells|dried-whole-blood|swab|ascites|stool-faeces|saliva|liquid-other|derivative-other))" backgroundColor={JSON.stringify(barChartBackgroundColors)} > diff --git a/packages/lib/src/components/results/ChartComponent.wc.svelte b/packages/lib/src/components/results/ChartComponent.wc.svelte index 1e136935..e3646c18 100644 --- a/packages/lib/src/components/results/ChartComponent.wc.svelte +++ b/packages/lib/src/components/results/ChartComponent.wc.svelte @@ -7,6 +7,7 @@ backgroundHoverColor: { type: "Array" }, perSite: { type: "Boolean" }, groupRange: { type: "Number" }, + accumulatedValues: { type: "Array" }, }, }} /> @@ -52,6 +53,9 @@ export let filterRegex: string = ""; export let groupingLabel: string = ""; export let viewScales: boolean = chartType !== "pie" ? true : false; + export let accumulatedValues: + | { name: string; values: string[] }[] + | undefined = undefined; let options: ChartOption; $: options = @@ -171,6 +175,23 @@ }, }; + const accumulateValues = ( + responseStore: ResponseStore, + valuesToAccumulate: string[], + ): number => { + let aggregatedData = 0; + + valuesToAccumulate.forEach((value: string) => { + aggregatedData += getAggregatedPopulationForStratumCode( + responseStore, + value, + "sample_kind", + ); + }); + + return aggregatedData; + }; + /** * gets the aggregated population for a given stratum code * @param responseStore - the response store @@ -242,6 +263,17 @@ }); } + if (accumulatedValues !== undefined && accumulatedValues.length > 0) { + accumulatedValues.forEach((valueToAccumulate) => { + const aggregationCount: number = accumulateValues( + responseStore, + valueToAccumulate.values, + ); + combinedSubGroupData.data.push(aggregationCount); + combinedSubGroupData.labels.push(valueToAccumulate.name); + }); + } + return { labels: combinedSubGroupData.labels, data: [ @@ -384,7 +416,11 @@ * will be aggregated in groups if a divider is set * eg. 'C30', 'C31.1', 'C31.2' -> 'C31' when divider is '.' */ - let chartData = getChartDataSets(responseStore, chartLabels); + let chartData: ChartDataSets = getChartDataSets( + responseStore, + chartLabels, + ); + chart.data.datasets = chartData.data; chartLabels = chartData.labels; From 0efd88c8e1d9f3fa3218f26a6669d2ce818dc832 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Mon, 18 Mar 2024 14:53:09 +0100 Subject: [PATCH 2/6] feat(chart): add support for accumulated values --- packages/demo/public/options.json | 4 ++-- packages/demo/src/AppCCP.svelte | 2 +- .../results/ChartComponent.wc.svelte | 21 +++++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/demo/public/options.json b/packages/demo/public/options.json index f465f7e8..56a16e83 100644 --- a/packages/demo/public/options.json +++ b/packages/demo/public/options.json @@ -85,7 +85,7 @@ ], "tooltips": { "tissue-ffpe": "Gewebe FFPE", - "tissue-frozen": "Gewebe schockgefroren", + "frozen-tissue": "Gewebe schockgefroren", "tissue-other": "Gewebe, Andere Konservierungsart", "whole-blood": "Vollblut", "blood-serum": "Serum", @@ -107,7 +107,7 @@ }, "legendMapping":{ "tissue-ffpe": "Gewebe FFPE", - "tissue-frozen": "Gewebe schockgefroren", + "frozen-tissue": "Gewebe schockgefroren", "tissue-other": "Gewebe, Andere Konservierungsart", "whole-blood": "Vollblut", "blood-serum": "Serum", diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index 48e27bf9..ef28f58a 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -267,7 +267,7 @@ yAxisTitle="Probenanzahl" accumulatedValues={JSON.stringify([ { - name: "Gewebe Schockgefroren", + name: "frozen-tissue", values: [ "tissue-frozen", "tissue-ffpe", diff --git a/packages/lib/src/components/results/ChartComponent.wc.svelte b/packages/lib/src/components/results/ChartComponent.wc.svelte index e3646c18..bd6e484a 100644 --- a/packages/lib/src/components/results/ChartComponent.wc.svelte +++ b/packages/lib/src/components/results/ChartComponent.wc.svelte @@ -178,6 +178,7 @@ const accumulateValues = ( responseStore: ResponseStore, valuesToAccumulate: string[], + catalogueGroupCode: string, ): number => { let aggregatedData = 0; @@ -185,10 +186,10 @@ aggregatedData += getAggregatedPopulationForStratumCode( responseStore, value, - "sample_kind", + catalogueGroupCode, ); }); - + console.log(aggregatedData); return aggregatedData; }; @@ -263,14 +264,30 @@ }); } + /** + * if accumulated values are set, accumulate the values of the given stratum codes and adds them to the chart + * e.g. {name: "frozen-tissue", values: ["tissue-frozen","tissue-ffpe"]} + * will remove the values from the chart and add their accumulated value to "frozen-tissue" + */ if (accumulatedValues !== undefined && accumulatedValues.length > 0) { accumulatedValues.forEach((valueToAccumulate) => { const aggregationCount: number = accumulateValues( responseStore, valueToAccumulate.values, + catalogueGroupCode, ); + combinedSubGroupData.data.push(aggregationCount); combinedSubGroupData.labels.push(valueToAccumulate.name); + + for (let i = 0; i < combinedSubGroupData.labels.length; i++) { + const element: string = combinedSubGroupData.labels[i]; + if (valueToAccumulate.values.includes(element)) { + combinedSubGroupData.labels.splice(i, 1); + combinedSubGroupData.data.splice(i, 1); + i--; + } + } }); } From 06d6322d9e16d41604476c536f01a4396e3f4328 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Tue, 19 Mar 2024 15:56:32 +0100 Subject: [PATCH 3/6] feat(catalogue): aggregate frozen and ffpe sample types --- .../public/catalogues/catalogue-dktk.json | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/demo/public/catalogues/catalogue-dktk.json b/packages/demo/public/catalogues/catalogue-dktk.json index 8a480e32..1a279666 100644 --- a/packages/demo/public/catalogues/catalogue-dktk.json +++ b/packages/demo/public/catalogues/catalogue-dktk.json @@ -20181,6 +20181,18 @@ { "value": "histology", "name": "tumor-tissue-ffpe" + }, + { + "value": "sample_kind", + "name": "tissue-ffpe" + }, + { + "value": "sample_kind", + "name": "normal-tissue-ffpe" + }, + { + "value": "sample_kind", + "name": "other-tissue-ffpe" } ] ] @@ -20188,7 +20200,27 @@ { "key": "tumor-tissue-frozen", "name": "Gewebe schockgefroren", - "description": "Tumorgewebe (Kryo/Frisch)" + "description": "Tumorgewebe (Kryo/Frisch)", + "aggregatedValue": [ + [ + { + "value": "sample_kind", + "name": "tissue-frozen" + }, + { + "value": "sample_kind", + "name": "tumor-tissue-frozen" + }, + { + "value": "sample_kind", + "name": "normal-tissue-frozen" + }, + { + "value": "sample_kind", + "name": "other-tissue-frozen" + } + ] + ] }, { "key": "tissue-other", From 8601bb6a068654867d6d095d2f8ef1ab72311c49 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Wed, 20 Mar 2024 09:49:13 +0100 Subject: [PATCH 4/6] feat(charts): move accumulations input to options --- packages/demo/public/options.json | 12 ++++++++++++ packages/demo/src/AppCCP.svelte | 12 ------------ .../src/components/results/ChartComponent.wc.svelte | 12 +++++------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/demo/public/options.json b/packages/demo/public/options.json index 56a16e83..2abc7ecc 100644 --- a/packages/demo/public/options.json +++ b/packages/demo/public/options.json @@ -83,6 +83,18 @@ "hintText": [ "Verteilung der Probentypen die mit den identifizierten Patienten verbunden sind." ], + "accumulatedValues": [ + { + "name": "frozen-tissue", + "values": [ + "tissue-frozen", + "tissue-ffpe", + "tumor-tissue-ffpe", + "normal-tissue-ffpe", + "other-tissue-ffpe" + ] + } + ], "tooltips": { "tissue-ffpe": "Gewebe FFPE", "frozen-tissue": "Gewebe schockgefroren", diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index ef28f58a..fd06e5ae 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -265,18 +265,6 @@ chartType="bar" xAxisTitle="Probentypen" yAxisTitle="Probenanzahl" - accumulatedValues={JSON.stringify([ - { - name: "frozen-tissue", - values: [ - "tissue-frozen", - "tissue-ffpe", - "tumor-tissue-ffpe", - "normal-tissue-ffpe", - "other-tissue-ffpe", - ], - }, - ])} filterRegex="^(?!(tissue-other|buffy-coat|peripheral-blood-cells|dried-whole-blood|swab|ascites|stool-faeces|saliva|liquid-other|derivative-other))" backgroundColor={JSON.stringify(barChartBackgroundColors)} > diff --git a/packages/lib/src/components/results/ChartComponent.wc.svelte b/packages/lib/src/components/results/ChartComponent.wc.svelte index bd6e484a..9cc748e8 100644 --- a/packages/lib/src/components/results/ChartComponent.wc.svelte +++ b/packages/lib/src/components/results/ChartComponent.wc.svelte @@ -7,7 +7,6 @@ backgroundHoverColor: { type: "Array" }, perSite: { type: "Boolean" }, groupRange: { type: "Number" }, - accumulatedValues: { type: "Array" }, }, }} /> @@ -53,10 +52,6 @@ export let filterRegex: string = ""; export let groupingLabel: string = ""; export let viewScales: boolean = chartType !== "pie" ? true : false; - export let accumulatedValues: - | { name: string; values: string[] }[] - | undefined = undefined; - let options: ChartOption; $: options = ($lensOptions?.chartOptions && @@ -269,8 +264,11 @@ * e.g. {name: "frozen-tissue", values: ["tissue-frozen","tissue-ffpe"]} * will remove the values from the chart and add their accumulated value to "frozen-tissue" */ - if (accumulatedValues !== undefined && accumulatedValues.length > 0) { - accumulatedValues.forEach((valueToAccumulate) => { + if ( + options.accumulatedValues !== undefined && + options.accumulatedValues.length > 0 + ) { + options.accumulatedValues.forEach((valueToAccumulate) => { const aggregationCount: number = accumulateValues( responseStore, valueToAccumulate.values, From 9dec16de99955ec04d6bca5f4fcac58bc7c9b4c8 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Wed, 20 Mar 2024 09:52:38 +0100 Subject: [PATCH 5/6] chore(logs): remove unnecessary console logs --- packages/lib/src/components/results/ChartComponent.wc.svelte | 1 - packages/lib/src/stores/query.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/lib/src/components/results/ChartComponent.wc.svelte b/packages/lib/src/components/results/ChartComponent.wc.svelte index 9cc748e8..4d7368bb 100644 --- a/packages/lib/src/components/results/ChartComponent.wc.svelte +++ b/packages/lib/src/components/results/ChartComponent.wc.svelte @@ -184,7 +184,6 @@ catalogueGroupCode, ); }); - console.log(aggregatedData); return aggregatedData; }; diff --git a/packages/lib/src/stores/query.ts b/packages/lib/src/stores/query.ts index 5c5921a1..90d9ee6d 100644 --- a/packages/lib/src/stores/query.ts +++ b/packages/lib/src/stores/query.ts @@ -219,7 +219,6 @@ export const addStratifier = ({ groupRange, }): void => { let queryItem: QueryItem; - console.log(catalogue); catalogue.forEach((parentCategory: Category) => { if ("childCategories" in parentCategory) { parentCategory.childCategories.forEach( From 40214f64f0f8c0b342dbfee3426d8019b764eb3c Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Wed, 20 Mar 2024 11:21:58 +0100 Subject: [PATCH 6/6] fix(ccp options): divide frozen and ffpe in accumulations --- packages/demo/public/options.json | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/demo/public/options.json b/packages/demo/public/options.json index 2abc7ecc..f88e3cdd 100644 --- a/packages/demo/public/options.json +++ b/packages/demo/public/options.json @@ -85,18 +85,26 @@ ], "accumulatedValues": [ { - "name": "frozen-tissue", + "name": "ffpe-tissue", "values": [ - "tissue-frozen", "tissue-ffpe", "tumor-tissue-ffpe", "normal-tissue-ffpe", "other-tissue-ffpe" ] + }, + { + "name": "frozen-tissue", + "values": [ + "tissue-frozen", + "tumor-tissue-frozen", + "normal-tissue-frozen", + "other-tissue-frozen" + ] } ], "tooltips": { - "tissue-ffpe": "Gewebe FFPE", + "ffpe-tissue": "Gewebe FFPE", "frozen-tissue": "Gewebe schockgefroren", "tissue-other": "Gewebe, Andere Konservierungsart", "whole-blood": "Vollblut", @@ -118,7 +126,7 @@ "derivative-other": "Derivat, Andere" }, "legendMapping":{ - "tissue-ffpe": "Gewebe FFPE", + "ffpe-tissue": "Gewebe FFPE", "frozen-tissue": "Gewebe schockgefroren", "tissue-other": "Gewebe, Andere Konservierungsart", "whole-blood": "Vollblut",