Skip to content

Commit

Permalink
Add village and other fields based on kobo form changes (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Boucher <[email protected]>
  • Loading branch information
wadhwamatic and ericboucher authored Sep 23, 2024
1 parent 6f6cd31 commit 1b9df6c
Show file tree
Hide file tree
Showing 27 changed files with 246 additions and 341 deletions.
35 changes: 27 additions & 8 deletions apps/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@

## Documentation

- 🏛️ [Project architecture](./docs/architecture.md)
- 💅 [Design](./docs/design.md)
- 🔒 [Authentication](./docs/authentication.md)
- 🚨 [Linter and Editor Configuration](./docs/linter-editor.md)
- 💃 [Error handling](./docs/error-handling.md)
- ⬆️ [Upgrading Dependencies](./docs/upgrading-dependencies.md)
- ⬆️ [Audit dependencies](./docs/dependency-security-audit.md)
- 🚀 [Deploy](./docs/deploy.md)
- 🏛️ [Project architecture](./docs/architecture.md)
- 💅 [Design](./docs/design.md)
- 🔒 [Authentication](./docs/authentication.md)
- 🚨 [Linter and Editor Configuration](./docs/linter-editor.md)
- 💃 [Error handling](./docs/error-handling.md)
- ⬆️ [Upgrading Dependencies](./docs/upgrading-dependencies.md)
- ⬆️ [Audit dependencies](./docs/dependency-security-audit.md)
- 🚀 [Deploy](./docs/deploy.md)

## Updating KOBO Tables

If changes have been made to the KOBO forms, you can follow the step by step below to update the DMP tables and reports.

1. In `/packages/interfaces`:

- Add the new fields to the corresponding Dto file. Eg. [FloodDto.ts](../../packages/interfaces/src/kobo/FloodDto.ts)
- Update the mapping file. Eg. [flood.ts](../../packages/interfaces/src/kobo/mapping/flood.ts)

2. In `frontend`:

- Add the new fields to the table configuration for the main tables. Eg. `FloodFormValidation/tablesConfig/Agriculture.tsx`
- Add the new fields to the report table configuration if required. Eg. `Report/FloodReport/tablesConfig/ReportFoodNeeds.tsx`
- Add the new fields to the summary table configuration if requried. Eg. `Report/FloodReport/tablesConfig/SummaryReport.tsx`

3. In `translations`

- Add the necessary key mapping to both the `en.json` and `km.json` files.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type DroughtFormType = {
province: string[];
district: string[];
commune: string[];
village: string;
};
interviewer: string;
disTyp: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const DroughtFormValidation = ({
province: [formattedForm.province],
district: [formattedForm.district],
commune: [formattedForm.commune],
village: formattedForm.village,
},
interviewer: formattedForm.entryName,
disTyp: formattedForm.disTyp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type FloodFormType = {
province: string[];
district: string[];
commune: string[];
village: string;
};
interviewer: string;
disTyp: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const FloodFormValidation = ({
province: [formattedForm.province],
district: [formattedForm.district],
commune: [formattedForm.commune],
village: formattedForm.village,
},
interviewer: formattedForm.entryName,
disTyp: formattedForm.disTyp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import {
const colWidth = 8 * 9;

const AgricultureColumns: GridColDef[] = [
getColumnSetup({
field: FloodSpecific.ToNamAgriAff,
disaster: FLOOD,
width: colWidth + 8 * 2,
}),
getColumnSetup({
field: FloodSpecific.NumFarmCroAff,
disaster: FLOOD,
width: colWidth + 8 * 2,
}),
getColumnSetup({
field: FloodSpecific.FarmAff,
disaster: FLOOD,
Expand All @@ -23,6 +33,7 @@ const AgricultureColumns: GridColDef[] = [
}),
getColumnSetup({ field: FloodSpecific.SamNabAff, disaster: FLOOD }),
getColumnSetup({ field: FloodSpecific.SamNabDam, disaster: FLOOD }),
getColumnSetup({ field: FloodSpecific.NumFarmPaddyAff, disaster: FLOOD }),
getColumnSetup({ field: FloodSpecific.PaddyAff, disaster: FLOOD }),
getColumnSetup({ field: FloodSpecific.PaddyDam, disaster: FLOOD }),
getColumnSetup({ field: FloodSpecific.CowEva, disaster: FLOOD }),
Expand All @@ -37,6 +48,13 @@ const AgricultureColumns: GridColDef[] = [
];

const AgricultureColumnGroup: GridColumnGroupingModel = [
{
...getGroupSetup('families', FLOOD),
children: [
{ field: FloodSpecific.ToNamAgriAff },
{ field: FloodSpecific.NumFarmCroAff },
],
},
{
...getGroupSetup('plantation', FLOOD),
children: [
Expand All @@ -47,6 +65,7 @@ const AgricultureColumnGroup: GridColumnGroupingModel = [
{
...getGroupSetup('seedling', FLOOD),
children: [
{ field: FloodSpecific.NumFarmPaddyAff },
{ field: FloodSpecific.SamNabAff },
{ field: FloodSpecific.SamNabDam },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IncidentFormType extends FieldValues {
province: string[];
district: string[];
commune: string[];
village: string;
};
interviewer: string;
disTyp: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const IncidentFormValidation = ({
province: [formattedForm.province],
district: [formattedForm.district],
commune: [formattedForm.commune],
village: formattedForm.village,
},
interviewer: formattedForm.entryName,
disTyp: formattedForm.disTyp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const SocialColumns: GridColDef[] = [
getColumnSetup({ field: IncidentSpecific.StorageDam, disaster: INCIDENT }),
getColumnSetup({ field: IncidentSpecific.CraftAff, disaster: INCIDENT }),
getColumnSetup({ field: IncidentSpecific.CraftDam, disaster: INCIDENT }),
getColumnSetup({
field: IncidentSpecific.integer_ws0la67,
disaster: INCIDENT,
}),
getColumnSetup({
field: IncidentSpecific.integer_da9ns07,
disaster: INCIDENT,
}),
];

const SocialColumnGroup: GridColumnGroupingModel = [
Expand Down Expand Up @@ -64,6 +72,13 @@ const SocialColumnGroup: GridColumnGroupingModel = [
{ field: IncidentSpecific.CraftDam },
],
},
{
...getGroupSetup('factory', INCIDENT),
children: [
{ field: IncidentSpecific.integer_ws0la67 },
{ field: IncidentSpecific.integer_da9ns07 },
],
},
];

const groupParams: ColumnSetupParams = {
Expand Down
18 changes: 14 additions & 4 deletions apps/frontend/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"10": "Drowning",
"11": "Collapse",
"12": "Unexploded Weapon",
"13": "Shipwreck",
"99": "Other Incidents",
"ALL_INCIDENTS": "All Incidents"
},
Expand Down Expand Up @@ -157,7 +158,7 @@
"FLOOD": {
"floodN": "Flood Number",
"column": {
"NumVillAff": "Villages",
"NumVillAff": "Villages (Old)",
"NumFamAff": "Families",
"NumPeoAff": "Total People",
"NumFeAff": "Women",
Expand Down Expand Up @@ -211,8 +212,11 @@
"NumWareHDam": "Damaged",
"NumCraftAff": "Affected",
"NumCraftDam": "Damaged",
"ToNamAgriAff": "Affected",
"NumFarmCroAff": "Affected",
"FarmAff": "Affected",
"FarmDam": "Damaged",
"NumFarmPaddyAff": "Affected",
"SamNabAff": "Affected",
"SamNabDam": "Damaged",
"PaddyAff": "Affected",
Expand Down Expand Up @@ -386,6 +390,8 @@
"NumFeEva": "Women Evacuated",
"NumHouAff": "Houses Affected",
"NumSchoAff": "Schools Affected",
"ToNamAgriAff": "Total number of households affecting farmland",
"NumFarmCroAff": "Number of households affected by mixed crops",
"SamNabAff": "Seedlings Affected (ha)",
"SamNabDam": "Seedlings Damaged (ha)",
"PaddyAff": "Paddies Affected (ha)",
Expand All @@ -398,7 +404,7 @@
},
"DROUGHT": {
"column": {
"NumVillAff": "Villages",
"NumVillAff": "Villages (Old)",
"NumFamAff": "Families",
"NumPeoAff": "Total People",
"NumMe": "Men",
Expand Down Expand Up @@ -561,7 +567,7 @@
},
"INCIDENT": {
"column": {
"NumVillAff": "Villages",
"NumVillAff": "Villages (Old)",
"NumPeoAff": "Total People",
"NumFamAff": "Families",
"NumFeAff": "Women",
Expand Down Expand Up @@ -618,6 +624,8 @@
"StorageDam": "Damaged",
"CraftAff": "Affected",
"CraftDam": "Damaged",
"integer_ws0la67": "Affected",
"integer_da9ns07": "Damaged",
"CropAff": "Affected",
"CropDam": "Damaged",
"SamnabAff": "Affected",
Expand Down Expand Up @@ -651,6 +659,7 @@
"market": "Market (number)",
"warehouse": "Warehouse (number)",
"workshop": "Workshop (number)",
"factory": "Factory (number)",
"agricultureForest": "Agriculture and Forest Affected",
"crop": "Crop/subsidiary plants (ha)",
"transplanted": "Seedlings ()ha",
Expand Down Expand Up @@ -685,7 +694,8 @@
"COMMON": {
"column": {
"district": "District",
"commune": "Commune"
"commune": "Commune",
"village": "Villages"
}
}
},
Expand Down
18 changes: 14 additions & 4 deletions apps/frontend/translations/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"10": "លង់ទឹក",
"11": "បាក់អគារ",
"12": "យុទ្ធភណ្ឌមិនទាន់ផ្ទុះ",
"13": "លិចទូក",
"99": "ផ្សេងៗ",
"100": "ឧប្បត្តិហេតុទាំងអស់។",
"ALL_INCIDENTS": "ឧប្បត្តិហេតុទាំងអស់។"
Expand Down Expand Up @@ -166,7 +167,7 @@
"FLOOD": {
"floodN": "ចំនួនលើកទឹកជំនន់",
"column": {
"NumVillAff": "ភូមិ",
"NumVillAff": "ភូមិ (ចាស់)",
"NumFamAff": "គ្រួសារ",
"NumPeoAff": "ចំំនួនមនុស្ស",
"NumFeAff": "ស្រ្តី",
Expand Down Expand Up @@ -220,8 +221,11 @@
"NumWareHDam": "ខូចខាត",
"NumCraftAff": "ប៉ះពាល់",
"NumCraftDam": "ខូចខាត",
"ToNamAgriAff": "ប៉ះពាល់",
"NumFarmCroAff": "ប៉ះពាល់",
"FarmAff": "ប៉ះពាល់",
"FarmDam": "ខូចខាត",
"NumFarmPaddyAff": "ប៉ះពាល់",
"SamNabAff": "ប៉ះពាល់",
"SamNabDam": "ខូចខាត",
"PaddyAff": "ប៉ះពាល់",
Expand Down Expand Up @@ -395,6 +399,8 @@
"NumFeEva": "ចំនួនស្រ្តីដែលបានជម្លៀស",
"NumHouAff": "ចំនួនផ្ទះដែលរងផលប៉ះពាល់",
"NumSchoAff": "ចំនួនសាលាដែលរងផលប៉ះពាល់",
"ToNamAgriAff": "ចំនួនគ្រួសារសរុប៉ះពាល់ដីស្រែ/ចម្ការ",
"NumFarmCroAff": "ចំនួនគ្រួសារប៉ះពាល់ដំណាំរួមផ្សំ",
"SamNabAff": "ចំនួនសំណាបដែលរងផលប៉ះពាល់ (ហិចតា)",
"SamNabDam": "ចំនួនសំណាបដែលខូចខាត (ហិចតា)",
"PaddyAff": "ចំនួនស្រែដែលរងផលប៉ះពាល់ (ហិចតា)",
Expand All @@ -407,7 +413,7 @@
},
"DROUGHT": {
"column": {
"NumVillAff": "ភូមិ",
"NumVillAff": "ភូមិ (ចាស់)",
"NumFamAff": "គ្រួសារ",
"NumPeoAff": "ចំំនួនមនុស្ស",
"NumMe": "បុរស",
Expand Down Expand Up @@ -570,7 +576,7 @@
},
"INCIDENT": {
"column": {
"NumVillAff": "ភូមិ",
"NumVillAff": "ភូមិ (ចាស់)",
"NumPeoAff": "ចំំនួនមនុស្ស",
"NumFamAff": "គ្រួសារ",
"NumFeAff": "ស្រ្តី",
Expand Down Expand Up @@ -627,6 +633,8 @@
"StorageDam": "ខូចខាត",
"CraftAff": "ប៉ះពាល់",
"CraftDam": "ខូចខាត",
"integer_ws0la67": "ប៉ះពាល់",
"integer_da9ns07": "ខូចខាត",
"CropAff": "ប៉ះពាល់",
"CropDam": "ខូចខាត",
"SamnabAff": "ប៉ះពាល់",
Expand Down Expand Up @@ -660,6 +668,7 @@
"market": "ទីផ្សារ (ចំនួន)",
"warehouse": "ឃ្លាំងស្តុកទំនិញ (កន្លែង)",
"workshop": "សិប្បកម្ម/រោងជាង (កន្លែង)",
"factory": "រោងចក្រ (កន្លែង)",
"agricultureForest": "ផលប៉ះពាល់កសិកម្ម និងព្រៃឈើ",
"crop": "ដំណាំចម្ការ/ដំណាំរួមផ្សំ (ហ.ត)",
"transplanted": "សំណាប (ហត)",
Expand Down Expand Up @@ -694,7 +703,8 @@
"COMMON": {
"column": {
"district": "ស្រុក",
"commune": "ឃុំ"
"commune": "ឃុំ",
"village": "ភូមិ"
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/utils/aggregate/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { countAgg } from './countAgg';
import { countCategoriesAgg } from './countCategoriesAgg';
import { countMultipleChoicesAgg } from './countMultipleChoicesAgg';
import { firstAgg } from './firstAgg';
import { getUniqueValuesSet } from './setAgg';
import { sumAgg } from './sumAgg';

interface IProps {
Expand All @@ -14,6 +15,7 @@ interface IProps {
countKeys?: string[];
countCategoriesKeys?: string[];
countMultipleChoicesKeys?: string[];
setAggKeys?: string[];
}

export const aggregate = ({
Expand All @@ -24,6 +26,7 @@ export const aggregate = ({
countKeys = [],
countCategoriesKeys = [],
countMultipleChoicesKeys = [],
setAggKeys = [],
}: IProps) => {
const groupedData = groupBy(data, groupKey);
const aggregatedData = map(groupedData, (array, keyValue) => {
Expand All @@ -37,13 +40,16 @@ export const aggregate = ({
countMultipleChoicesAgg(key, array),
);

const setAggValues = setAggKeys.map(key => getUniqueValuesSet(key, array));

return assign(
{ [groupKey]: keyValue },
...firstValues,
...sumValues,
...countValues,
...countCategoriesValues,
...countMultipleChoicesValues,
...setAggValues,
) as Record<string, string | number | undefined>;
});

Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/utils/aggregate/generateFloodReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const sumKeys = Object.values(

const countCategoriesKeys = [FloodSpecific.RicePrice];
const countMultipleChoicesKeys = [FloodSpecific.threat];
const setAggKeys = [KoboCommonKeys.village];

export const generateFloodCommuneLevelReport = (
data: Record<string, string | undefined>[],
Expand All @@ -37,6 +38,7 @@ export const generateFloodCommuneLevelReport = (
sumKeys,
countCategoriesKeys,
countMultipleChoicesKeys,
setAggKeys,
});
};

Expand All @@ -57,5 +59,6 @@ export const generateFloodProvinceLevelReport = (
countKeys: provinceLevelReportCountKeys,
countCategoriesKeys,
countMultipleChoicesKeys,
setAggKeys,
});
};
Loading

0 comments on commit 1b9df6c

Please sign in to comment.