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

Feature/deal with misssing gm archived data v2 #4598

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"properties": {
"values": {
"type": "array",
"minItems": 1,
APW26 marked this conversation as resolved.
Show resolved Hide resolved
"maxItems": 2,
"items": {
"$ref": "#/definitions/value"
Expand Down
42 changes: 42 additions & 0 deletions packages/app/src/data/gm/vaccinations/empty-coverage-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This file was introduced as part of COR-1226 which covers the municipality reorganisation of 2023.
// During this reorganisation, three municipalities (GMs) have been merged into a single GM, specifically
// GM0501, GM0530 and GM0614 became GM1992. This reorganisation resulted in missing coverage data
// for both booster vaccinations as well as base vaccinations. This file combats the missing data by
// generating 'empty' data objects with no values.

const emptyBoosterCoverageValue = {
percentage: null,
percentage_label: null,
date_of_insertion_unix: null,
date_unix: undefined,
};

const emptyVaccineCoveragePerAgeGroupValue = {
has_one_shot_percentage: null,
has_one_shot_percentage_label: null,
fully_vaccinated_percentage: null,
fully_vaccinated_percentage_label: null,
date_of_insertion_unix: null,
date_unix: null,
};

export const emptyCoverageData = {
booster_coverage_archived_20220904: {
values: [
{ age_group: '12+', ...emptyBoosterCoverageValue },
{ age_group: '18+', ...emptyBoosterCoverageValue },
],
},
vaccine_coverage_per_age_group_archived: {
values: [
{ age_group_range: '18+', birthyear_range: '-2003', ...emptyVaccineCoveragePerAgeGroupValue },
{ age_group_range: '12+', birthyear_range: '-2009', ...emptyVaccineCoveragePerAgeGroupValue },
],
},
vaccine_coverage_per_age_group_archived_20220908: {
values: [
{ age_group_range: '18+', birthyear_range: '-2004', ...emptyVaccineCoveragePerAgeGroupValue },
{ age_group_range: '12+', birthyear_range: '-2010', ...emptyVaccineCoveragePerAgeGroupValue },
],
},
};
76 changes: 14 additions & 62 deletions packages/app/src/domain/vaccine/vaccine-coverage-toggle-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import { useIntl } from '~/intl';
import { SiteText } from '~/locale';
import { assert } from '~/utils/assert';
import { replaceVariablesInText } from '~/utils/replace-variables-in-text';
import {
KeyWithLabel,
useVaccineCoveragePercentageFormatter,
} from './logic/use-vaccine-coverage-percentage-formatter';
import { KeyWithLabel, useVaccineCoveragePercentageFormatter } from './logic/use-vaccine-coverage-percentage-formatter';

type AgeTypes = {
fully_vaccinated: number | null;
Expand Down Expand Up @@ -49,7 +46,7 @@ interface VaccineCoverageToggleTileProps {
descriptionFooter: string;
age18Plus: AgeTypes;
age12Plus: AgeTypes;
dateUnix: number;
dateUnix: number | null;
numFractionDigits?: number;
age12PlusToggleText: VaccinationGradeToggleTypes;
age18PlusToggleText: VaccinationGradeToggleTypes;
Expand All @@ -71,7 +68,7 @@ export function VaccineCoverageToggleTile({
const [selectedTab, setSelectedTab] = useState(age18PlusToggleText.label);

const metadata: MetadataProps = {
date: dateUnix,
date: dateUnix ?? undefined,
source: source,
};

Expand Down Expand Up @@ -104,31 +101,18 @@ export function VaccineCoverageToggleTile({
description={age18PlusToggleText.description_booster_grade}
numFractionDigits={numFractionDigits}
>
{age18Plus.dateUnixBoostered && (
<Metadata
source={source}
date={age18Plus.dateUnixBoostered}
isTileFooter
/>
)}
{age18Plus.dateUnixBoostered && <Metadata source={source} date={age18Plus.dateUnixBoostered} isTileFooter />}
</AgeGroupBlock>
) : (
<NoBoosterBlock
title={labelTexts.booster_grade}
description={
age18PlusToggleText.description_booster_grade_not_available
}
/>
<NoBoosterBlock title={labelTexts.booster_grade} description={age18PlusToggleText.description_booster_grade_not_available} />
)}
<AgeGroupBlock
title={labelTexts.vaccination_grade}
data={age18Plus}
property="fully_vaccinated"
secondProperty="has_one_shot"
description={age18PlusToggleText.description_vaccination_grade}
secondDescription={
age18PlusToggleText.description_vaccination_one_shot_with_percentage
}
secondDescription={age18PlusToggleText.description_vaccination_one_shot_with_percentage}
numFractionDigits={numFractionDigits}
>
{metadata && <Metadata {...metadata} isTileFooter />}
Expand All @@ -145,31 +129,18 @@ export function VaccineCoverageToggleTile({
description={age12PlusToggleText.description_booster_grade}
numFractionDigits={numFractionDigits}
>
{age12Plus.dateUnixBoostered && (
<Metadata
source={source}
date={age12Plus.dateUnixBoostered}
isTileFooter
/>
)}
{age12Plus.dateUnixBoostered && <Metadata source={source} date={age12Plus.dateUnixBoostered} isTileFooter />}
</AgeGroupBlock>
) : (
<NoBoosterBlock
title={labelTexts.booster_grade}
description={
age12PlusToggleText.description_booster_grade_not_available
}
/>
<NoBoosterBlock title={labelTexts.booster_grade} description={age12PlusToggleText.description_booster_grade_not_available} />
)}
<AgeGroupBlock
title={labelTexts.vaccination_grade}
data={age12Plus}
property="fully_vaccinated"
secondProperty="has_one_shot"
description={age12PlusToggleText.description_vaccination_grade}
secondDescription={
age12PlusToggleText.description_vaccination_one_shot_with_percentage
}
secondDescription={age12PlusToggleText.description_vaccination_one_shot_with_percentage}
numFractionDigits={numFractionDigits}
>
{metadata && <Metadata {...metadata} isTileFooter />}
Expand All @@ -195,26 +166,13 @@ interface AgeGroupBlockProps {
children?: React.ReactNode;
}

function AgeGroupBlock({
title,
data,
property,
secondProperty,
description,
secondDescription,
numFractionDigits,
children,
}: AgeGroupBlockProps) {
function AgeGroupBlock({ title, data, property, secondProperty, description, secondDescription, numFractionDigits, children }: AgeGroupBlockProps) {
const { commonTexts } = useIntl();
const formatCoveragePercentage =
useVaccineCoveragePercentageFormatter(numFractionDigits);
const formatCoveragePercentage = useVaccineCoveragePercentageFormatter(numFractionDigits);

const parsedBirthyearRange = parseBirthyearRange(data.birthyear);

assert(
parsedBirthyearRange,
`[${AgeGroupBlock.name}] Something went wrong with parsing the birthyear: ${data.birthyear}`
);
assert(parsedBirthyearRange, `[${AgeGroupBlock.name}] Something went wrong with parsing the birthyear: ${data.birthyear}`);

return (
<Box spacing={2}>
Expand All @@ -228,19 +186,13 @@ function AgeGroupBlock({
<KpiValue text={formatCoveragePercentage(data, property)} />
<Markdown
content={replaceVariablesInText(description, {
birthyear: replaceVariablesInText(
commonTexts.common.birthyear_ranges[parsedBirthyearRange.type],
parsedBirthyearRange
),
birthyear: replaceVariablesInText(commonTexts.common.birthyear_ranges[parsedBirthyearRange.type], parsedBirthyearRange),
})}
/>
{secondDescription && secondProperty && (
<Markdown
content={replaceVariablesInText(secondDescription, {
birthyear: replaceVariablesInText(
commonTexts.common.birthyear_ranges[parsedBirthyearRange.type],
parsedBirthyearRange
),
birthyear: replaceVariablesInText(commonTexts.common.birthyear_ranges[parsedBirthyearRange.type], parsedBirthyearRange),
percentage: formatCoveragePercentage(data, secondProperty),
})}
/>
Expand Down
20 changes: 12 additions & 8 deletions packages/app/src/pages/gemeente/[code]/vaccinaties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { assert, replaceVariablesInText, useReverseRouter, useFormatLokalizePerc
import { getLastInsertionDateOfPage } from '~/utils/get-last-insertion-date-of-page';
import { useDynamicLokalizeTexts } from '~/utils/cms/use-dynamic-lokalize-texts';
import { VaccineCoverageChoroplethVrAndGm } from '~/domain/vaccine/vaccine-coverage-choropleth_vr_and_gm';
import { emptyCoverageData } from '~/data/gm/vaccinations/empty-coverage-data';

const pageMetrics = ['vaccine_coverage_per_age_group', 'vaccine_coverage_per_age_group_archived', 'booster_coverage_archived_20220904'];

Expand Down Expand Up @@ -101,14 +102,17 @@ export const VaccinationsGmPage = (props: StaticProps<typeof getStaticProps>) =>
assert(filteredVaccination.primarySeries, `[${VaccinationsGmPage.name}] Could not find data for the vaccine coverage per age group for the primary series`);
assert(filteredVaccination.autumn2022, `[${VaccinationsGmPage.name}] Could not find data for the vaccine coverage per age group for the autumn 2022 series`);

const boosterCoverage18PlusArchivedValue = data.booster_coverage_archived_20220904?.values?.find((v) => v.age_group === '18+');
const boosterCoverage12PlusArchivedValue = data.booster_coverage_archived_20220904?.values?.find((v) => v.age_group === '12+');
const boosterCoverage18PlusArchivedValue =
data.booster_coverage_archived_20220904?.values?.find((v) => v.age_group === '18+') || emptyCoverageData.booster_coverage_archived_20220904.values[1];
const boosterCoverage12PlusArchivedValue =
data.booster_coverage_archived_20220904?.values?.find((v) => v.age_group === '12+') || emptyCoverageData.booster_coverage_archived_20220904.values[0];

const filteredArchivedAgeGroup18Plus = data.vaccine_coverage_per_age_group_archived_20220908.values.find((x) => x.age_group_range === '18+');
const filteredArchivedAgeGroup12Plus = data.vaccine_coverage_per_age_group_archived_20220908.values.find((x) => x.age_group_range === '12+');

assert(filteredArchivedAgeGroup18Plus, `[${VaccinationsGmPage.name}] Could not find data for the archived vaccine coverage per age group for the age 18+`);
assert(filteredArchivedAgeGroup12Plus, `[${VaccinationsGmPage.name}] Could not find data for the archived vaccine coverage per age group for the age 12+`);
const filteredArchivedAgeGroup18Plus =
data.vaccine_coverage_per_age_group_archived_20220908.values.find((x) => x.age_group_range === '18+') ||
emptyCoverageData.vaccine_coverage_per_age_group_archived_20220908.values[0];
const filteredArchivedAgeGroup12Plus =
data.vaccine_coverage_per_age_group_archived_20220908.values.find((x) => x.age_group_range === '12+') ||
emptyCoverageData.vaccine_coverage_per_age_group_archived_20220908.values[1];

const lastInsertionDateOfPage = getLastInsertionDateOfPage(data, pageMetrics);

Expand Down Expand Up @@ -253,7 +257,7 @@ export const VaccinationsGmPage = (props: StaticProps<typeof getStaticProps>) =>
description={textGm.vaccination_coverage.description}
sortingOrder={['18+', '12+']}
metadata={{
date: data.vaccine_coverage_per_age_group_archived.values[0].date_unix,
date: data.vaccine_coverage_per_age_group_archived.values.length ? data.vaccine_coverage_per_age_group_archived.values[0].date_unix : undefined,
source: textGm.vaccination_coverage.bronnen.rivm,
}}
values={data.vaccine_coverage_per_age_group_archived.values}
Expand Down