Skip to content

Commit

Permalink
fix: [DHIS2-18855] add error logging for program indicators missing e…
Browse files Browse the repository at this point in the history
…xpressions (#3981)

* fix: add error logging for program indicators missing expressions

* chore: signed commit
  • Loading branch information
eirikhaugstulen authored Feb 26, 2025
1 parent f35178a commit 7f356d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ src/locales/

# DHIS2 Platform
.d2

# Cursor
.cursorrules
.cursor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @flow
import log from 'loglevel';
import { errorCreator } from 'capture-core-utils';
import type { ProgramRulesContainer } from '@dhis2/rules-engine-javascript';
import { getTrackedEntityAttributeId, getDataElementId, getProgramId, getProgramRuleActions, getProgramStageId } from '../helpers';
import { getRulesAndVariablesFromProgramIndicators } from '../../../../metaDataMemoryStoreBuilders/programs/getRulesAndVariablesFromIndicators';
Expand All @@ -22,7 +24,22 @@ const addProgramRules = (program, programRules) => {
};

const addRulesAndVariablesFromProgramIndicators = (program, programIndicators) => {
const indicators = programIndicators.map(programIndicator => ({
const validProgramIndicators = programIndicators.filter((indicator) => {
if (!indicator.expression) {
log.error(
errorCreator('WidgetProfile: Program indicator is missing an expression and will be skipped.')(
{
method: 'addRulesAndVariablesFromProgramIndicators',
object: indicator,
},
),
);
return false;
}
return true;
});

const indicators = validProgramIndicators.map(programIndicator => ({
...programIndicator,
programId: getProgramId(programIndicator),
}));
Expand All @@ -36,6 +53,7 @@ const addRulesAndVariablesFromProgramIndicators = (program, programIndicators) =
}
};


export const buildRulesContainer = async ({
programAPI,
programRules,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import isString from 'd2-utilizr/lib/isString';

import log from 'loglevel';
import { errorCreator } from 'capture-core-utils';
import type { ProgramRule, ProgramRuleAction, ProgramRuleVariable } from '@dhis2/rules-engine-javascript';
import { variableSourceTypes } from '@dhis2/rules-engine-javascript';

Expand Down Expand Up @@ -186,7 +187,23 @@ function buildIndicatorRuleAndVariables(programIndicator: CachedProgramIndicator
export function getRulesAndVariablesFromProgramIndicators(
cachedProgramIndicators: Array<CachedProgramIndicator>,
programId: string) {
return cachedProgramIndicators
// Filter out program indicators without an expression
const validProgramIndicators = cachedProgramIndicators.filter((indicator) => {
if (!indicator.expression) {
log.error(
errorCreator('Program indicator is missing an expression and will be skipped.')(
{
method: 'getRulesAndVariablesFromProgramIndicators',
object: indicator,
},
),
);
return false;
}
return true;
});

return validProgramIndicators
.map(programIndicator => buildIndicatorRuleAndVariables(programIndicator, programId))
.filter(container => container)
.reduce((accOneLevelContainer, container) => {
Expand Down

0 comments on commit 7f356d5

Please sign in to comment.