Skip to content

Commit

Permalink
feat(WIP backends): add multiple backends
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsJohansen87 committed Feb 29, 2024
1 parent b979426 commit 3f79c54
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 108 deletions.
127 changes: 124 additions & 3 deletions packages/demo/public/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"rna": "RNA",
"derivative-other": "Derivat, Andere"
},
"legendMapping":{
"legendMapping": {
"tissue-ffpe": "Gewebe FFPE",
"tissue-frozen": "Gewebe schockgefroren",
"tissue-other": "Gewebe, Andere Konservierungsart",
Expand Down Expand Up @@ -146,8 +146,7 @@
"stratifierCode": "Histlogoies",
"stratumCode": "1"
},
{
}
{}
]
}
]
Expand All @@ -165,5 +164,127 @@
"dataKey": "patients"
}
]
},
"backends": {
"spots": [
{
"url": "http://localhost:8080",
"sites": [
"berlin",
"berlin-test",
"bonn",
"dresden",
"essen",
"frankfurt",
"freiburg",
"hannover",
"mainz",
"muenchen-lmu",
"muenchen-tum",
"ulm",
"wuerzburg",
"mannheim",
"dktk-test",
"hamburg"
],
"uiSiteMap": [
[
"berlin",
"Berlin"
],
[
"berlin-test",
"Berlin Test"
],
[
"bonn",
"Bonn"
],
[
"dresden",
"Dresden"
],
[
"essen",
"Essen"
],
[
"frankfurt",
"Frankfurt"
],
[
"freiburg",
"Freiburg"
],
[
"hannover",
"Hannover"
],
[
"mainz",
"Mainz"
],
[
"muenchen-lmu",
"München(LMU)"
],
[
"muenchen-tum",
"München(TUM)"
],
[
"ulm",
"Ulm"
],
[
"wuerzburg",
"Würzburg"
],
[
"mannheim",
"Mannheim"
],
[
"dktk-test",
"DKTK-Test"
],
[
"hamburg",
"Hamburg"
]
],
"catalogueKeyToResponseKeyMap": [
[
"gender",
"Gender"
],
[
"age_at_diagnosis",
"Age"
],
[
"diagnosis",
"diagnosis"
],
[
"medicationStatements",
"MedicationType"
],
[
"sample_kind",
"sample_kind"
],
[
"therapy_of_tumor",
"ProcedureType"
],
[
"75186-7",
"75186-7"
]
]
}
],
"blazes": []
}
}
74 changes: 11 additions & 63 deletions packages/demo/src/AppCCP.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,69 +46,18 @@
let catalogueopen = false;
const catalogueKeyToResponseKeyMap = [
["gender", "Gender"],
["age_at_diagnosis", "Age"],
["diagnosis", "diagnosis"],
["medicationStatements", "MedicationType"],
["sample_kind", "sample_kind"],
["therapy_of_tumor", "ProcedureType"],
["75186-7", "75186-7"],
// ["encounter", "Encounter"],
];
// VITE_TARGET_ENVIRONMENT should be set by the ci pipeline
const backendUrl =
import.meta.env.VITE_TARGET_ENVIRONMENT === "production"
? "https://backend.data.dktk.dkfz.de/prod/"
: "https://backend.demo.lens.samply.de/prod/";
const uiSiteMap: string[][] = [
["berlin", "Berlin"],
["berlin-test", "Berlin"],
["bonn", "Bonn"],
["dresden", "Dresden"],
["essen", "Essen"],
["frankfurt", "Frankfurt"],
["freiburg", "Freiburg"],
["hannover", "Hannover"],
["mainz", "Mainz"],
["muenchen-lmu", "München(LMU)"],
["muenchen-tum", "München(TUM)"],
["ulm", "Ulm"],
["wuerzburg", "Würzburg"],
["mannheim", "Mannheim"],
["dktk-test", "DKTK-Test"],
["hamburg", "Hamburg"],
];
// // VITE_TARGET_ENVIRONMENT should be set by the ci pipeline
// const backendUrl =
// import.meta.env.VITE_TARGET_ENVIRONMENT === "production"
// ? "https://backend.data.dktk.dkfz.de/prod/"
// : "https://backend.demo.lens.samply.de/prod/";
const genderHeaders: Map<string, string> = new Map<string, string>()
.set("male", "männlich")
.set("female", "weiblich")
.set("other", "Divers, Intersexuell")
.set("unknown", "unbekannt");
const backendConfig = {
url: import.meta.env.PROD ? backendUrl : "http://localhost:8080",
backends: [
"mannheim",
"freiburg",
"muenchen-tum",
"hamburg",
"frankfurt",
"berlin-test",
"dresden",
"mainz",
"muenchen-lmu",
"essen",
"ulm",
"wuerzburg",
"hannover",
],
uiSiteMap: uiSiteMap,
catalogueKeyToResponseKeyMap: catalogueKeyToResponseKeyMap,
};
const barChartBackgroundColors: string[] = ["#4dc9f6", "#3da4c7"];
const vitalStateHeaders: Map<string, string> = new Map<string, string>()
Expand Down Expand Up @@ -145,12 +94,7 @@
noQueryMessage="Leere Suchanfrage: Sucht nach allen Ergebnissen."
showQuery={true}
/>
<lens-search-button
title="Suchen"
{measures}
backendConfig={JSON.stringify(backendConfig)}
{backendMeasures}
/>
<lens-search-button title="Suchen" {backendMeasures} />
</div>
<div class="grid">
<div class="catalogue">
Expand Down Expand Up @@ -288,4 +232,8 @@
</div>
</footer>

<lens-options options={libraryOptions} catalogueData={mockCatalogueData} />
<lens-options
options={libraryOptions}
catalogueData={mockCatalogueData}
{measures}
/>
109 changes: 109 additions & 0 deletions packages/demo/src/backends/blaze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { buildLibrary, buildMeasure } from "../helpers/cql-measure";
import { responseStore } from "../stores/response";
import type { Site } from "../types/response";
import { measureStore } from "../stores/measures";

let measureDefinitions;

measureStore.subscribe((store) => {
measureDefinitions = store.map((measure) => measure.measure);
});

export class Blaze {
constructor(
private url: URL,
private name: string,
private auth: string = "",
) {}

/**
* sends the query to beam and updates the store with the results
* @param cql the query as cql string
* @param controller the abort controller to cancel the request
*/
async send(cql: string, controller?: AbortController): Promise<void> {
try {
responseStore.update((store) => {
store.set(this.name, { status: "claimed", data: null });
return store;
});
const libraryResponse = await fetch(
new URL(`${this.url}/Library`),
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(buildLibrary(cql)),
signal: controller?.signal,
},
);
if (!libraryResponse.ok) {
this.handleError(
`Couldn't create Library in Blaze`,
libraryResponse,
);
}
const library = await libraryResponse.json();
const measureResponse = await fetch(
new URL(`${this.url}/Measure`),
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
buildMeasure(library.url, measureDefinitions),
),
signal: controller.signal,
},
);
if (!measureResponse.ok) {
this.handleError(
`Couldn't create Measure in Blaze`,
measureResponse,
);
}
const measure = await measureResponse.json();
const dataResponse = await fetch(
new URL(
`${this.url}/Measure/$evaluate-measure?measure=${measure.url}&periodStart=2000&periodEnd=2030`,
),
{
signal: controller.signal,
},
);
if (!dataResponse.ok) {
this.handleError(
`Couldn't evaluate Measure in Blaze`,
dataResponse,
);
}
const blazeResponse: Site = await dataResponse.json();
responseStore.update((store) => {
store.set(this.name, {
status: "succeeded",
data: blazeResponse,
});
return store;
});
} catch (err) {
if (err.name === "AbortError") {
console.log(`Aborting former blaze request.`);
} else {
console.error(err);
}
}
}

async handleError(message: string, response: Response): Promise<void> {
const errorMessage = await response.text();
console.debug(
`${message}. Received error ${response.status} with message ${errorMessage}`,
);
responseStore.update((store) => {
store.set(this.name, { status: "permfailed", data: null });
return store;
});
}
}
Loading

0 comments on commit 3f79c54

Please sign in to comment.