Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: update coverage data with new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-ozaynaci committed Nov 23, 2022
1 parent e2b4a44 commit 1aaac6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
2 changes: 2 additions & 0 deletions packages/app/src/domain/vaccine/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const matchingAgeGroups: MatchingVaccineCoverageAgeGroupsType = {
fully_basisserie: ['18', '12'],
};

export const ageGroups = ['12', '18', '60']

export type PercentageKeysOfAgeGroups = Pick<VaccineCoverageData, 'vaccinated_percentage_12_plus' | 'vaccinated_percentage_18_plus' | 'vaccinated_percentage_60_plus'>;

export type PercentageLabelKeysOfAgeGroups = Pick<
Expand Down
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 };
});
}

0 comments on commit 1aaac6a

Please sign in to comment.