Skip to content

Commit

Permalink
feat: Filter chartData based on measurmentData
Browse files Browse the repository at this point in the history
  • Loading branch information
edvinstava committed Apr 24, 2024
1 parent 524be2c commit 007d927
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-04-23T10:55:58.423Z\n"
"PO-Revision-Date: 2024-04-23T10:55:58.423Z\n"
"POT-Creation-Date: 2024-04-24T10:57:45.778Z\n"
"PO-Revision-Date: 2024-04-24T10:57:45.778Z\n"

msgid "Growth Chart"
msgstr "Growth Chart"
Expand All @@ -17,12 +17,18 @@ msgstr "There was an error fetching the config for the growth chart."
msgid "Please check the configuration in Datastore Management and try again."
msgstr "Please check the configuration in Datastore Management and try again."

msgid "There was an error fetching the custom references for the growth chart."
msgstr "There was an error fetching the custom references for the growth chart."

msgid "Date"
msgstr "Date"

msgid "Age"
msgstr "Age"

msgid "Year"
msgstr "Year"

msgid "Years"
msgstr "Years"

Expand Down
10 changes: 8 additions & 2 deletions src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import { useMappedTrackedEntityVariables } from './utils/DataFetching/Sorting/us
import { ChartConfigError } from './UI/GenericError/ChartConfigError';
import { GenericLoading } from './UI/GenericLoading';
import { useCustomReferences } from './utils/DataFetching/Hooks/useCustomReferences';
import { chartData } from './DataSets/WhoStandardDataSets/ChartData';
import { chartData as chartDataWHO } from './DataSets/WhoStandardDataSets/ChartData';
import { CustomReferencesError } from './UI/GenericError/CustomReferencesError';
import { useFilterByMissingData } from './utils/DataFetching/Sorting';

const queryClient = new QueryClient();

Expand All @@ -40,6 +41,11 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => {
isWeightInGrams: chartConfig?.settings.weightInGrams || false,
});

const { chartData } = useFilterByMissingData(
mappedGrowthVariables,
chartConfig?.settings.customReferences ? customReferences : chartDataWHO,
);

const isPercentiles = chartConfig?.settings.usePercentiles || false;

const [open, setOpen] = useState(true);
Expand Down Expand Up @@ -81,7 +87,7 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => {
<GrowthChart
trackedEntity={mappedTrackedEntity}
measurementData={mappedGrowthVariables}
chartData={chartConfig.settings.customReferences ? customReferences : chartData}
chartData={chartData}
isPercentiles={isPercentiles}
/>
</WidgetCollapsible>
Expand Down
1 change: 0 additions & 1 deletion src/components/GrowthChart/GrowthChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const GrowthChart = ({
chartData,
}: GrowthChartProps) => {
const trackedEntityGender = trackedEntity?.gender;

const [gender, setGender] = useState<string>(trackedEntityGender !== undefined ? trackedEntityGender : GenderCodes.CGC_Female);
const { chartDataForGender } = useChartDataForGender({ gender, chartData });

Expand Down
3 changes: 3 additions & 0 deletions src/utils/DataFetching/Sorting/useFilterByMissingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { useMemo } from 'react';
import { ChartData, MeasurementData } from '../../../types/chartDataTypes';

export const useFilterByMissingData = (measurementData: MeasurementData[], chartData: ChartData) => {
if (!chartData || !measurementData) {
return {};
}
const requiredData = Object.freeze({
hcfa_b: { headCircumference: true },
hcfa_g: { headCircumference: true },
Expand Down

0 comments on commit 007d927

Please sign in to comment.