From d53823d041575efb70042ce6e14cd41b37ccdd00 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Mon, 9 Sep 2024 08:51:00 +0200 Subject: [PATCH 1/9] fix(options): fix fetch path error --- packages/demo/src/AppCCP.svelte | 2 +- packages/lib/src/types/treeData.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index dbca66e..b9f3b75 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -20,7 +20,7 @@ if (import.meta.env.VITE_TARGET_ENVIRONMENT === "production") { catalogueUrl = "catalogues/catalogue-dktk.json"; - optionsFilePath = "options.json"; + optionsFilePath = "options-ccp-prod.json"; } else { catalogueUrl = "catalogues/catalogue-dktk-staging.json"; optionsFilePath = "options-ccp-demo.json"; diff --git a/packages/lib/src/types/treeData.ts b/packages/lib/src/types/treeData.ts index 0d8f152..7dc4ab7 100644 --- a/packages/lib/src/types/treeData.ts +++ b/packages/lib/src/types/treeData.ts @@ -17,7 +17,7 @@ export type Category = key: string; name: string; system?: string; - fieldType: "single-select" | "autocomplete" | "number"; + fieldType: "single-select" | "autocomplete" | "number" | "date"; type: "EQUALS" | "BETWEEN"; min?: number; max?: number; From a39a1d3d99a35c30bca07d24a1e0e9dffee311a1 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Thu, 12 Sep 2024 15:20:27 +0200 Subject: [PATCH 2/9] feat(parameters): change attributes to parameters this means, there will be no json.stringify needed to pass data into the components --- packages/demo/src/AppCCP.svelte | 72 ++++++++++++------- packages/lib/src/components/Options.wc.svelte | 26 ++++--- .../buttons/InfoButtonComponent.wc.svelte | 5 -- .../buttons/SearchButtonComponenet.wc.svelte | 5 -- .../components/catalogue/Catalogue.wc.svelte | 6 -- .../results/ChartComponent.wc.svelte | 7 -- .../results/ResultSummaryComponent.wc.svelte | 3 - .../results/ResultTableComponent.wc.svelte | 1 - .../search-bar/SearchBarComponent.wc.svelte | 4 -- .../SearchBarMultipleComponent.wc.svelte | 5 -- 10 files changed, 60 insertions(+), 74 deletions(-) diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index dbca66e..ae6bea0 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -13,8 +13,10 @@ dktkHistologyMeasure, } from "./measures"; - let catalogueData: string = ""; - let libraryOptions: string = ""; + /** + * VITE_TARGET_ENVIRONMENT is set by the ci pipeline + */ + let catalogueUrl: string = ""; let optionsFilePath: string = ""; @@ -27,26 +29,35 @@ } /** - * VITE_TARGET_ENVIRONMENT is set by the ci pipeline + * fetch both catalogue data and options + * response needs to be converted to text so that it can be passed to the options component for proper schema validation + * @param catalogueUrl the url where to fetch the catalogue.json + * @param optionsFilePath the url where to fetch the options.json + * @returns a promise that resolves to an object containing the catalogueJSON and optionsJSON */ + const fetchData = async ( + catalogueUrl: string, + optionsFilePath: string, + ): Promise<{ catalogueJSON: string; optionsJSON: string }> => { + const cataloguePromise: string = await fetch(catalogueUrl).then( + (response) => response.text(), + ); - /** - * get catalogue file - */ - fetch(catalogueUrl) - .then((response) => response.text()) - .then((data) => { - catalogueData = data; - }); + const optionsPromise: string = await fetch(optionsFilePath).then( + (response) => response.text(), + ); - /** - * get options file - */ - fetch(optionsFilePath) - .then((response) => response.json()) - .then((data) => { - libraryOptions = data; - }); + return Promise.all([cataloguePromise, optionsPromise]).then( + ([catalogueJSON, optionsJSON]) => { + return { catalogueJSON, optionsJSON }; + }, + ); + }; + + const jsonPromises: Promise<{ + catalogueJSON: string; + optionsJSON: string; + }> = fetchData(catalogueUrl, optionsFilePath); const measures: MeasureGroup[] = [ { @@ -63,7 +74,7 @@ ]; /** - * TODO: move to config file + * TODO: add catalogueText option to config file */ const catalogueText = { group: "Group", @@ -75,7 +86,7 @@ }, }; - let catalogueopen = false; + let catalogueopen: boolean = false; const genderHeaders: Map = new Map() .set("male", "männlich") @@ -190,7 +201,7 @@ filterRegex="^[CD].*" xAxisTitle="Anzahl der Diagnosen" yAxisTitle="ICD-10-Codes" - backgroundColor={JSON.stringify(barChartBackgroundColors)} + backgroundColor={barChartBackgroundColors} />
@@ -202,7 +213,7 @@ filterRegex="^(([0-9]?[0-9]$)|(1[0-2]0))" xAxisTitle="Alter" yAxisTitle="Anzahl der Primärdiagnosen" - backgroundColor={JSON.stringify(barChartBackgroundColors)} + backgroundColor={barChartBackgroundColors} />
@@ -222,7 +233,7 @@ headers={therapyHeaders} xAxisTitle="Art der Therapie" yAxisTitle="Anzahl der Therapieeinträge" - backgroundColor={JSON.stringify(barChartBackgroundColors)} + backgroundColor={barChartBackgroundColors} />
@@ -232,7 +243,7 @@ chartType="bar" xAxisTitle="Art der Therapie" yAxisTitle="Anzahl der Therapieeinträge" - backgroundColor={JSON.stringify(barChartBackgroundColors)} + backgroundColor={barChartBackgroundColors} />
@@ -243,7 +254,7 @@ xAxisTitle="Probentypen" yAxisTitle="Probenanzahl" filterRegex="^(?!(tissue-other|buffy-coat|peripheral-blood-cells|dried-whole-blood|swab|ascites|stool-faeces|saliva|liquid-other|derivative-other))" - backgroundColor={JSON.stringify(barChartBackgroundColors)} + backgroundColor={barChartBackgroundColors} >
@@ -287,5 +298,12 @@ > - +{#await jsonPromises} + Loading data... +{:then { optionsJSON, catalogueJSON }} + +{:catch someError} + System error: {someError.message} +{/await} + diff --git a/packages/lib/src/components/Options.wc.svelte b/packages/lib/src/components/Options.wc.svelte index 5c0a663..e7e35ac 100644 --- a/packages/lib/src/components/Options.wc.svelte +++ b/packages/lib/src/components/Options.wc.svelte @@ -1,10 +1,6 @@ @@ -21,26 +17,34 @@ import type { Criteria } from "../types/treeData"; import optionsSchema from "../types/options.schema.json"; import catalogueSchema from "../types/catalogue.schema.json"; - import { parser } from "@exodus/schemasafe"; + import { parser, type Parse, type ParseResult } from "@exodus/schemasafe"; import type { LensOptions } from "../types/options"; import { catalogueKeyToResponseKeyMap, uiSiteMappingsStore, } from "../stores/mappings"; - export let options: LensOptions = {}; - export let catalogueData: Criteria[] = []; + export let optionsJSON: string = ""; + export let catalogueJSON: string = ""; export let measures: MeasureStore = {} as MeasureStore; + /** + * transform the JSON strings to objects for validation and further processing + */ + let options: LensOptions = {} as LensOptions; + let catalogueData: Criteria[] = []; + $: options = JSON.parse(optionsJSON); + $: catalogueData = JSON.parse(catalogueJSON); + /** * Validate the options against the schema before passing them to the store */ $: { - const parse = parser(optionsSchema, { + const parse: Parse = parser(optionsSchema, { includeErrors: true, allErrors: true, }); - const validJSON = parse(JSON.stringify(options)); + const validJSON: ParseResult = parse(JSON.stringify(options)); if (validJSON.valid === true) { $lensOptions = options; } else if (typeof options === "object") { @@ -52,11 +56,11 @@ } $: { - const parse = parser(catalogueSchema, { + const parse: Parse = parser(catalogueSchema, { includeErrors: true, allErrors: true, }); - const validJSON = parse(JSON.stringify(catalogueData)); + const validJSON: ParseResult = parse(JSON.stringify(catalogueData)); if (validJSON.valid === true) { $catalogue = catalogueData; } else if (typeof catalogueData === "object") { diff --git a/packages/lib/src/components/buttons/InfoButtonComponent.wc.svelte b/packages/lib/src/components/buttons/InfoButtonComponent.wc.svelte index 9ce8f23..2719705 100644 --- a/packages/lib/src/components/buttons/InfoButtonComponent.wc.svelte +++ b/packages/lib/src/components/buttons/InfoButtonComponent.wc.svelte @@ -1,11 +1,6 @@ diff --git a/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte b/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte index ec4624f..557110d 100644 --- a/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte +++ b/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte @@ -1,11 +1,6 @@ diff --git a/packages/lib/src/components/catalogue/Catalogue.wc.svelte b/packages/lib/src/components/catalogue/Catalogue.wc.svelte index f41a487..b7044fe 100644 --- a/packages/lib/src/components/catalogue/Catalogue.wc.svelte +++ b/packages/lib/src/components/catalogue/Catalogue.wc.svelte @@ -1,12 +1,6 @@ diff --git a/packages/lib/src/components/results/ChartComponent.wc.svelte b/packages/lib/src/components/results/ChartComponent.wc.svelte index e7866b5..fa7126f 100644 --- a/packages/lib/src/components/results/ChartComponent.wc.svelte +++ b/packages/lib/src/components/results/ChartComponent.wc.svelte @@ -1,13 +1,6 @@ diff --git a/packages/lib/src/components/results/ResultSummaryComponent.wc.svelte b/packages/lib/src/components/results/ResultSummaryComponent.wc.svelte index 2782c1f..f6a5330 100644 --- a/packages/lib/src/components/results/ResultSummaryComponent.wc.svelte +++ b/packages/lib/src/components/results/ResultSummaryComponent.wc.svelte @@ -1,9 +1,6 @@ diff --git a/packages/lib/src/components/results/ResultTableComponent.wc.svelte b/packages/lib/src/components/results/ResultTableComponent.wc.svelte index c32a454..0facb44 100644 --- a/packages/lib/src/components/results/ResultTableComponent.wc.svelte +++ b/packages/lib/src/components/results/ResultTableComponent.wc.svelte @@ -1,7 +1,6 @@ diff --git a/packages/lib/src/components/search-bar/SearchBarComponent.wc.svelte b/packages/lib/src/components/search-bar/SearchBarComponent.wc.svelte index dab891d..750e677 100644 --- a/packages/lib/src/components/search-bar/SearchBarComponent.wc.svelte +++ b/packages/lib/src/components/search-bar/SearchBarComponent.wc.svelte @@ -1,10 +1,6 @@ diff --git a/packages/lib/src/components/search-bar/SearchBarMultipleComponent.wc.svelte b/packages/lib/src/components/search-bar/SearchBarMultipleComponent.wc.svelte index 443eb63..131b3a9 100644 --- a/packages/lib/src/components/search-bar/SearchBarMultipleComponent.wc.svelte +++ b/packages/lib/src/components/search-bar/SearchBarMultipleComponent.wc.svelte @@ -1,11 +1,6 @@ From ef9ff0d28cc23c06b062a9fb768badef76bab0e6 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Wed, 2 Oct 2024 09:21:07 +0200 Subject: [PATCH 3/9] fix(ast): system is passed to query and ast --- packages/demo/src/AppCCP.svelte | 14 ++++++++++++++ .../catalogue/AutoCompleteComponent.svelte | 1 + .../catalogue/SingleSelectItemComponent.svelte | 10 ++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index f87f35a..e1c16e6 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -107,8 +107,22 @@ ); let dataPasser: LensDataPasser; + + const getQuery = (): void => { + console.log("QueryStore:", dataPasser.getQueryAPI()); + }; + + const getAST = (): void => { + console.log("AST:", dataPasser.getAstAPI()); + }; +
- + From 3ab2ebb94d8c0debb86b1916b2e70060f4ec088f Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Wed, 2 Oct 2024 09:36:49 +0200 Subject: [PATCH 4/9] feat(api): add api to set query the whole store --- packages/lib/src/components/DataPasser.wc.svelte | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/lib/src/components/DataPasser.wc.svelte b/packages/lib/src/components/DataPasser.wc.svelte index c321aeb..ee7d781 100644 --- a/packages/lib/src/components/DataPasser.wc.svelte +++ b/packages/lib/src/components/DataPasser.wc.svelte @@ -73,6 +73,14 @@ * Setters */ + /** + * sets the query store + * @param queryStore the new query store + */ + export const setQueryStoreAPI = (queryStore: QueryItem[][]): void => { + queryStore.set(queryStore); + }; + /** * lets the library user add a single stratifier to the query store * @param params the parameters for the function From aa05e66eeab98a2c715d534b9a3751ffafff5317 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Wed, 2 Oct 2024 09:38:20 +0200 Subject: [PATCH 5/9] chore(testing): remove test functions --- packages/demo/src/AppCCP.svelte | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/demo/src/AppCCP.svelte b/packages/demo/src/AppCCP.svelte index e1c16e6..f87f35a 100644 --- a/packages/demo/src/AppCCP.svelte +++ b/packages/demo/src/AppCCP.svelte @@ -107,22 +107,8 @@ ); let dataPasser: LensDataPasser; - - const getQuery = (): void => { - console.log("QueryStore:", dataPasser.getQueryAPI()); - }; - - const getAST = (): void => { - console.log("AST:", dataPasser.getAstAPI()); - }; -