Skip to content

Commit

Permalink
feat(data passer): add apis for removing items and values
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsJohansen87 committed Jan 25, 2024
1 parent 8863e17 commit 5d35e6d
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 42 deletions.
75 changes: 47 additions & 28 deletions packages/demo/src/AppFragmentDevelopment.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts">
import { get } from "svelte/store";
import "../../lib";
import type { QueryItem, QueryValue } from "../../lib/src/types/queryData";
// import "../../../dist/lib/lens-web-componets";
import type { CatalogueText } from "../../lib/src/types/texts";
import {
Expand Down Expand Up @@ -131,38 +133,33 @@
catalogueKeyToResponseKeyMap: catalogueKeyToResponseKeyMap,
};
const genderHeaders: Map<string, string> = new Map<string, string>()
.set("male", "männlich")
.set("female", "weiblich")
.set("other", "Divers, Intersexuell")
.set("unknown", "unbekannt");
const barChartBackgroundColors: string[] = ["#4dc9f6","#3da4c7"];
const vitalStateHeaders: Map<string, string> = new Map<string, string>()
.set("lebend", "alive")
.set("verstorben", "deceased")
.set("unbekannt", "unknown");
const therapyHeaders: Map<string, string> = new Map<string, string>().set(
"medicationStatements",
"Sys. T"
);
let dataPasser: any;
const getQuery = () => {
// if (!dataPasser) return;
console.log(dataPasser, dataPasser.getQuery());
console.log(dataPasser, dataPasser.getQueryAPI());
queryStore = dataPasser.getQueryAPI();
};
const getResponse = () => {
console.log(dataPasser, dataPasser.getResponse());
console.log(dataPasser, dataPasser.getResponseAPI());
};
const getAST = () => {
console.log(dataPasser, dataPasser.getAST());
console.log(dataPasser, dataPasser.getAstAPI());
};
const removeItem = (queryObject) => {
dataPasser.removeItemFromQuyeryAPI({queryObject});
getQuery();
};
const removeValue = (queryItem: QueryItem, value: QueryValue) => {
console.log(queryItem, value);
dataPasser.removeValueFromQueryAPI({queryItem, value});
getQuery();
};
let queryStore: QueryItem[][] = [];
</script>

<main>
Expand All @@ -172,6 +169,33 @@ const barChartBackgroundColors: string[] = ["#4dc9f6","#3da4c7"];
<button on:click={() => getQuery()}>Get Query Store</button>
<button on:click={() => getResponse()}>Get Response Store</button>
<button on:click={() => getAST()}>Get AST</button>
{#each queryStore as queryStoreGroup}
<div>
{#each queryStoreGroup as queryStoreItem}
<div>
<button on:click={() => removeItem(queryStoreItem)}>
remove {queryStoreItem.name}:
</button>
<ul>
{#each queryStoreItem.values as queryStoreValue}
<li>
<button on:click={() => removeValue(queryStoreItem, queryStoreValue)}>
remove {queryStoreValue.name}
</button>
</li>
{/each}
</ul>
</div>
{/each}
</div>
{/each}
</div>

<h2>Search bars</h2>
<div class="componentBox">
<lens-search-bar-multiple
noMatchesFoundMessage={"No matches found"}
/>
</div>

<h2>Search Button</h2>
Expand Down Expand Up @@ -219,12 +243,7 @@ const barChartBackgroundColors: string[] = ["#4dc9f6","#3da4c7"];
/>
</div>

<h2>Search bars</h2>
<div class="componentBox">
<lens-search-bar-multiple
noMatchesFoundMessage={"No matches found"}
/>
</div>


<h2>State display</h2>
<div class="componentBox">
Expand Down
56 changes: 48 additions & 8 deletions packages/lib/src/components/DataPasser.wc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,91 @@
<script lang="ts">
import { catalogue } from "../stores/catalogue";
import { responseStore } from "../stores/response";
import { addStratifier, queryStore} from "../stores/query";
import type { QueryItem } from "../types/queryData";
import type { ResponseStore } from "../types/backend";
import { addStratifier, queryStore, removeItemFromQuery, removeValueFromQuery} from "../stores/query";
import { buildAstFromQuery } from "../helpers/ast-transformer";
import type { QueryItem, QueryValue } from "../types/queryData";
import type { ResponseStore } from "../types/backend";
import type { AstTopLayer } from "../types/ast";
/**
* returns the query store to the library user
* @returns the query store
*/
export const getQuery = () : QueryItem[][] => {
export const getQueryAPI = () : QueryItem[][] => {
return $queryStore;
}
/**
* lets the library user add a single stratifier to the query store
* @param label the value of the stratifier (e.g. "C31")
* @param catalogueGroupCode the code of the group where the stratifier is located (e.g. "diagnosis")
* @param queryGroupIndex the index of the query group where the stratifier should be added
*/
interface SetQueryParams {
interface addStratifierToQueryAPIParams {
label: string;
catalogueGroupCode: string;
groupRange?: string;
queryGroupIndex?: number;
}
export const setQuery = ({label, catalogueGroupCode, groupRange, queryGroupIndex}) : void => {
export const addStratifierToQueryAPI = ({label, catalogueGroupCode, groupRange, queryGroupIndex}: addStratifierToQueryAPIParams) : void => {
addStratifier({label, catalogueGroupCode, catalogue: $catalogue, queryGroupIndex, groupRange});
}
/**
* removes a query item from the query store
* @param queryObject the query object that should be removed
* @param queryGroupIndex the index of the query group where the stratifier should be removed
*/
interface RemoveItemFromQueryAPIParams {
queryObject: QueryItem;
queryGroupIndex?: number;
}
export const removeItemFromQuyeryAPI = ({queryObject, queryGroupIndex = 0}: RemoveItemFromQueryAPIParams): void => {
removeItemFromQuery(queryObject, queryGroupIndex);
}
/**
* removes the value of a query item from the query store
* @param queryItem the query item from which the value should be removed from
* @param value the value that should be removed
*/
interface RemoveValueFromQueryAPIParams {
queryItem: QueryItem;
value: QueryValue;
queryGroupIndex?: number;
}
export const removeValueFromQueryAPI = ({ queryItem, value, queryGroupIndex = 0}: RemoveValueFromQueryAPIParams): void => {
const queryObject = {
...queryItem,
values: [value]
}
removeValueFromQuery(queryObject, queryGroupIndex);
}
/**
* returns the response from the backend to the library user
* @returns the response from the backend
*/
export const getResponse = () : ResponseStore => {
export const getResponseAPI = () : ResponseStore => {
return $responseStore;
}
/**
* returns the AST to the library user
* @returns the AST
*/
export const getAST = () : string => {
export const getAstAPI = () : AstTopLayer => {
return buildAstFromQuery($queryStore);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/lib/src/interfaces/DataPasser.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
interface LensDataPasser {
getQuery(): QueryItem[][];
setQuery(params: SetQueryParams): void;
}
getQueryAPI(): QueryItem[][];
addStratifierToQueryAPI(params: addStratifierToQueryAPIParams): void;
removeItemFromQuyeryAPI(params: removeItemFromQuyeryAPIParams): void;
removeValueFromQueryAPI(params: removeValueFromQueryAPIParams): void;
getResponseAPI(): ResponseStore;
getAstAPI(): AstTopLayer;
}

export default LensDataPasser;
95 changes: 92 additions & 3 deletions packages/lib/src/stores/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { QueryItem, QueryValue } from "../types/queryData";
import { writable } from "svelte/store";
import { v4 as uuidv4 } from "uuid";
import type { Category, Criteria } from "../types/treeData";



Expand Down Expand Up @@ -100,7 +101,7 @@ export const addItemToQuery = (queryObject: QueryItem, queryGroupIndex: number)
};

/**
* Removes an item from the query
* Removes an value of an Item from the query
* If the item has multiple values, only the value will be removed
* If the item has only one value, the item will be removed
* @param queryObject
Expand Down Expand Up @@ -132,7 +133,11 @@ export const removeValueFromQuery = (queryObject: QueryItem, queryGroupIndex: nu
});
}


/**
* removes an item from the query
* @param queryObject the object to be removed
* @param queryGroupIndex index of the group where the object is located
*/
export const removeItemFromQuery = (queryObject: QueryItem, queryGroupIndex: number) => {
queryModified.set(true);
/**
Expand All @@ -142,7 +147,7 @@ export const removeItemFromQuery = (queryObject: QueryItem, queryGroupIndex: num
*/
queryObject = Object.assign({}, queryObject)

queryStore.update((query) => {
queryStore.update((query: QueryItem[][]) => {
let queryStoreGroup: QueryItem[] = query[queryGroupIndex];

queryStoreGroup = queryStoreGroup.filter((item) => {
Expand Down Expand Up @@ -178,3 +183,87 @@ function findObjectsWithSameName(objectsArray: QueryItem[]) {
}




/**
* adds a single stratifier to the query
* numbers can be grouped together by setting the groupRange
* @param label the value of the stratifier (e.g. "C31")
* @param catalogue the catalogue where the stratifier is located
* @param catalogueGroupCode the code of the group where the stratifier is located (e.g. "diagnosis")
* @param queryGroupIndex the index of the query group where the stratifier should be added
*/

export interface AddStratifierParams {
label: string,
catalogueGroupCode: string,
catalogue: Category[],
queryGroupIndex?: number,
groupRange?: number
}

export const addStratifier = ({ label, catalogue, catalogueGroupCode, queryGroupIndex = 0, groupRange }): void => {

let queryItem: QueryItem;
console.log(catalogue);
catalogue.forEach((parentCategory: Category) => {
if ("childCategories" in parentCategory) {
parentCategory.childCategories.forEach(
(childCategorie: Category) => {
if (
childCategorie.key === catalogueGroupCode &&
"criteria" in childCategorie
) {
let values: QueryValue[] = [];

if (childCategorie.fieldType === "number") {
values = [
{
name: `${label}`,
value: {
min: parseInt(label),
max:
parseInt(label) +
groupRange - 1,
},
queryBindId: uuidv4(),
},
];
} else {
childCategorie.criteria.forEach(
(criterion: Criteria) => {
if (criterion.key === label) {
values[0] = {
name: criterion.name,
value: criterion.key,
queryBindId: uuidv4(),
description:
criterion.description,
};
}
}
);
}

queryItem = {
id: uuidv4(),
key: childCategorie.key,
name: childCategorie.name,
system:
"system" in childCategorie
? childCategorie.system
: "",
type:
"type" in childCategorie
? childCategorie.type
: "BETWEEN",
values: values,
};

addItemToQuery(queryItem, queryGroupIndex);
}
}
);
}
});
}

0 comments on commit 5d35e6d

Please sign in to comment.