Skip to content

Commit

Permalink
fix: connected value showcase to charts table (#4727)
Browse files Browse the repository at this point in the history
* enabled dynamic title in value showcase and fixed ordering of age groups
  • Loading branch information
davidruvolo51 authored Feb 17, 2025
1 parent ad8ad61 commit 5e05a3e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 18 deletions.
5 changes: 3 additions & 2 deletions apps/cranio-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
"graphql-request": "5.2.0",
"molgenis-components": "*",
"molgenis-viz": "*",
"vue":"3.5.13",
"vue": "3.5.13",
"vue-router": "4.4.3"
},
"devDependencies": {
"@vitejs/plugin-vue": "4.6.2",
"prettier": "2.8.8",
"vite": "5.4.12"
"vite": "5.4.12",
"vitest": "1.6.1"
},
"browserslist": [
"> 1%",
Expand Down
7 changes: 7 additions & 0 deletions apps/cranio-provider/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export function uniqueValues(data: any, key: string): string[] {
return Array.from(new Set(values)).sort() as string[];
}

export function uniqueAgeGroups(data: any, key: string): string[] {
const values = uniqueValues(data, key);
return values.sort((a: string, b: string) => {
return b.charCodeAt(0) - a.charCodeAt(0);
});
}

/**
* @name ernCenterPalette
* @description color palette for charts that show ERN and center comparisons
Expand Down
14 changes: 14 additions & 0 deletions apps/cranio-provider/src/utils/parseChartTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @name parseChartTitle
* @param string string containing a value to replace
* @param value value to subsititute
* @param pattern search pattern
* @returns string
*/
export function parseChartTitle(
string: string,
value: string | number,
pattern: string = "${value}"
) {
return string.replace(pattern, `${value}`);
}
4 changes: 2 additions & 2 deletions apps/cranio-provider/src/views/provider-cs-all-general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ import ProviderDashboard from "../components/ProviderDashboard.vue";
import { generateAxisTickData } from "../utils/generateAxisTicks";
import { getDashboardChart } from "../utils/getDashboardData";
import { generateColorPalette } from "../utils/generateColorPalette";
import { uniqueValues } from "../utils";
import { uniqueValues, uniqueAgeGroups } from "../utils";
import type { ICharts, IChartData } from "../types/schema";
import type { IKeyValuePair } from "../types";
Expand Down Expand Up @@ -282,7 +282,7 @@ function updatePatientsByCountryChart() {
}
function setAgeGroupFilter() {
ageGroups.value = uniqueValues(
ageGroups.value = uniqueAgeGroups(
cranioTypeChart.value?.dataPoints,
"dataPointPrimaryCategory"
);
Expand Down
4 changes: 2 additions & 2 deletions apps/cranio-provider/src/views/provider-cs-center-general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import {
import { generateAxisTickData } from "../utils/generateAxisTicks";
import { getDashboardChart } from "../utils/getDashboardData";
import { generateColorPalette } from "../utils/generateColorPalette";
import { uniqueValues } from "../utils";
import { uniqueValues, uniqueAgeGroups } from "../utils";
import type { ICharts, IChartData } from "../types/schema";
import type { IKeyValuePair } from "../types/index";
Expand Down Expand Up @@ -222,7 +222,7 @@ function updateMultipeSuturesChart() {
}
function setAgeGroupFilter() {
ageGroups.value = uniqueValues(
ageGroups.value = uniqueAgeGroups(
cranioTypeChart.value?.dataPoints,
"dataPointPrimaryCategory"
);
Expand Down
44 changes: 32 additions & 12 deletions apps/cranio-provider/src/views/provider-overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<LoadingScreen v-if="loading" style="height: auto" />
<ValueShowcase
v-else
:title="`${numberOfPatientsSubmitted} patients submitted`"
:description="`Your center has submitted on average ${monthlyAverageOfSubmissions} patients per month`"
:title="(numberOfPatientsSubmitted?.chartTitle as string)"
:description="(patientsSubmittedByTime?.chartTitle as string)"
>
<template v-slot:icon>
<UserCircleIcon />
Expand All @@ -34,7 +34,9 @@
<DashboardRow :columns="2">
<DashboardChart id="provider-overview-patients-by-workstream">
<LoadingScreen v-if="loading" style="height: 215px" />
<MessageBox v-else-if="!loading && numberOfPatientsSubmitted === 0">
<MessageBox
v-else-if="!loading && numberOfPatientsSubmitted!.dataPoints![0].dataPointValue === 0"
>
<span>Not enough data to show chart</span>
</MessageBox>
<ColumnChart
Expand Down Expand Up @@ -103,15 +105,16 @@ import { asKeyValuePairs, uniqueValues } from "../utils";
import { generateColorPalette } from "../utils/generateColorPalette";
import { getDashboardChart } from "../utils/getDashboardData";
import { generateAxisTickData } from "../utils/generateAxisTicks";
import { parseChartTitle } from "../utils/parseChartTitle";
import type { ICharts, IChartData } from "../types/schema";
import type { IAppPage } from "../types/app";
import type { IKeyValuePair } from "../types/index";
const props = defineProps<IAppPage>();
const loading = ref<boolean>(true);
const numberOfPatientsSubmitted = ref<number>(0);
const monthlyAverageOfSubmissions = ref<number>(0);
const numberOfPatientsSubmitted = ref<ICharts>();
const patientsSubmittedByTime = ref<ICharts>();
const patientsByWorkstreamChart = ref<ICharts>();
const patientsByWorkstreamChartData = ref<IChartData[]>();
const patientsByWorkstreamPalette = ref<IKeyValuePair>();
Expand All @@ -126,7 +129,7 @@ async function getPageData() {
"patients-total"
);
const monthlySubmissionResponse = await getDashboardChart(
const timeSubmissionResponse = await getDashboardChart(
props.api.graphql.current,
"patients-per-month"
);
Expand All @@ -144,12 +147,8 @@ async function getPageData() {
patientsByWorkstreamChart.value = patientsByWorkstreamResponse[0];
sexByWorkstreamChart.value = sexByWorkstreamResponse[0];
const submissionsData = submissionsResponse[0];
const monthlySubmissionsData = monthlySubmissionResponse[0];
numberOfPatientsSubmitted.value =
submissionsData.dataPoints![0].dataPointValue!;
monthlyAverageOfSubmissions.value =
monthlySubmissionsData.dataPoints![0].dataPointValue!;
numberOfPatientsSubmitted.value = submissionsResponse[0];
patientsSubmittedByTime.value = timeSubmissionResponse[0];
}
function updateSexByWorkstream(value: string) {
Expand All @@ -175,6 +174,27 @@ function updateSexByWorkstream(value: string) {
onMounted(() => {
getPageData()
.then(() => {
// set value showcase titles
if (
numberOfPatientsSubmitted.value?.chartTitle &&
numberOfPatientsSubmitted.value?.dataPoints
) {
numberOfPatientsSubmitted.value.chartTitle = parseChartTitle(
numberOfPatientsSubmitted.value.chartTitle,
numberOfPatientsSubmitted.value.dataPoints[0].dataPointValue!
);
}
if (
patientsSubmittedByTime.value?.chartTitle &&
patientsSubmittedByTime.value?.dataPoints
) {
patientsSubmittedByTime.value.chartTitle = parseChartTitle(
patientsSubmittedByTime.value.chartTitle,
patientsSubmittedByTime.value.dataPoints[0].dataPointValue!
);
}
// prepare workstream data
patientsByWorkstreamChartData.value =
patientsByWorkstreamChart.value!.dataPoints?.sort(
Expand Down
11 changes: 11 additions & 0 deletions apps/cranio-provider/tests/parseChartTitle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, test } from "vitest";
import { parseChartTitle } from "../src/utils/parseChartTitle";

describe("parseChartTitle", () => {
test("text is correctly replaces", () => {
const currentTitle = "The current selected value is ${value}.";
const dataValue = 123;
const updatedTitle = parseChartTitle(currentTitle, dataValue, "${value}");
expect(updatedTitle).toBe("The current selected value is 123.");
});
});

0 comments on commit 5e05a3e

Please sign in to comment.