From 1aaac6aae040c20fa67dc7bde2f05b409b5a959e Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard19 Date: Mon, 21 Nov 2022 15:18:15 +0100 Subject: [PATCH] feat: update coverage data with new structure --- packages/app/src/domain/vaccine/common.ts | 2 + .../select-vaccine-coverage-data.ts | 39 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/app/src/domain/vaccine/common.ts b/packages/app/src/domain/vaccine/common.ts index c9e99af7ff..6583f32901 100644 --- a/packages/app/src/domain/vaccine/common.ts +++ b/packages/app/src/domain/vaccine/common.ts @@ -24,6 +24,8 @@ export const matchingAgeGroups: MatchingVaccineCoverageAgeGroupsType = { fully_basisserie: ['18', '12'], }; +export const ageGroups = ['12', '18', '60'] + export type PercentageKeysOfAgeGroups = Pick; export type PercentageLabelKeysOfAgeGroups = Pick< diff --git a/packages/app/src/domain/vaccine/data-selection/select-vaccine-coverage-data.ts b/packages/app/src/domain/vaccine/data-selection/select-vaccine-coverage-data.ts index 09685711ee..c5886e3555 100644 --- a/packages/app/src/domain/vaccine/data-selection/select-vaccine-coverage-data.ts +++ b/packages/app/src/domain/vaccine/data-selection/select-vaccine-coverage-data.ts @@ -1,32 +1,37 @@ import { GmCollectionVaccineCoveragePerAgeGroup, VrCollectionVaccineCoveragePerAgeGroup, VrVaccineCoveragePerAgeGroupValue } from '@corona-dashboard/common'; import { isPresent } from 'ts-is-present'; +import { ageGroups, PercentageKeysOfAgeGroups, PercentageLabelKeysOfAgeGroups } from '../common'; import { parseVaccinatedPercentageLabel } from '../logic/parse-vaccinated-percentage-label'; -export function selectVaccineCoverageData( +type VaccineCoveragePerAgeGroups = GmCollectionVaccineCoveragePerAgeGroup | VrCollectionVaccineCoveragePerAgeGroup + +export function selectVaccineCoverageData( data: T[] ) { return data.map((vaccineCoveragePerAgeGroup) => { const parsedLabels: { - fully_vaccinated_percentage?: number; - autumn_2022_vaccinated_percentage?: number; + vaccinated_percentage_12_plus?: number | null; + vaccinated_percentage_18_plus?: number | null; + vaccinated_percentage_60_plus?: number | null; } = {}; - if (isPresent(vaccineCoveragePerAgeGroup.fully_vaccinated_percentage_label)) { - const result = parseVaccinatedPercentageLabel(vaccineCoveragePerAgeGroup.fully_vaccinated_percentage_label); + ageGroups.forEach(ageGroup => { + const ageGroupKey = `vaccinated_percentage_${ageGroup}_plus` as keyof PercentageKeysOfAgeGroups + const ageGroupLabel = `vaccinated_percentage_${ageGroup}_plus_label` as keyof PercentageLabelKeysOfAgeGroups + const coveragePercentage = vaccineCoveragePerAgeGroup[ageGroupLabel] - if (isPresent(result)) { - parsedLabels.fully_vaccinated_percentage = result.sign === '>' ? 100 : 0; + if (isPresent(coveragePercentage)) { + const result = parseVaccinatedPercentageLabel( + coveragePercentage + ); + + if (isPresent(result)) { + parsedLabels[ageGroupKey] = + result.sign === '>' ? 100 : 0; + } } - } - - if (isPresent(vaccineCoveragePerAgeGroup.autumn_2022_vaccinated_percentage_label)) { - const result = parseVaccinatedPercentageLabel(vaccineCoveragePerAgeGroup.autumn_2022_vaccinated_percentage_label); - - if (isPresent(result)) { - parsedLabels.autumn_2022_vaccinated_percentage = result.sign === '>' ? 100 : 0; - } - } - + }); + return { ...vaccineCoveragePerAgeGroup, ...parsedLabels }; }); }