This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update coverage data with new structure
- Loading branch information
1 parent
e2b4a44
commit 1aaac6a
Showing
2 changed files
with
24 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 22 additions & 17 deletions
39
packages/app/src/domain/vaccine/data-selection/select-vaccine-coverage-data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends GmCollectionVaccineCoveragePerAgeGroup | VrCollectionVaccineCoveragePerAgeGroup | VrVaccineCoveragePerAgeGroupValue>( | ||
type VaccineCoveragePerAgeGroups = GmCollectionVaccineCoveragePerAgeGroup | VrCollectionVaccineCoveragePerAgeGroup | ||
|
||
export function selectVaccineCoverageData<T extends VaccineCoveragePerAgeGroups>( | ||
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 }; | ||
}); | ||
} |