Skip to content

fix: [DHIS2-21727] program rules on enrollment+event registration page - #4707

Open
superskip wants to merge 10 commits into
masterfrom
DHIS2-21727
Open

fix: [DHIS2-21727] program rules on enrollment+event registration page#4707
superskip wants to merge 10 commits into
masterfrom
DHIS2-21727

Conversation

@superskip

@superskip superskip commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Introduces a new argument isEnrollmentFormWithEvent in the rule engine, which should be set to true when the user is in a combined enrollment+event registration form. The enrollment registration page for Child Programme is an example of such a form. The rule engine will now use evaluateAll when evaluating the rules for this kind of form.

The rule engine runs once during the form initialization step, but in the case of a combined enrollment+event registration form the event data is missing. I've addressed this problem in the first commit. Ideally we should build the event object in the same way as we do for subsequent rule engine runs, and I looked into whether this would be possible, but it turns out subsequent runs gets data from the redux store that is not present at the time we do the initial run. So what I did instead was to just create a dummy event that looks exactly like the object would have, had it been generated by means of a common procedure.

@superskip
superskip requested a review from a team as a code owner August 20, 2026 10:53
@github-actions

Copy link
Copy Markdown

@simonadomnisoru simonadomnisoru left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👏

executionContext,
);
}
const duplicateActionIds = new Set<string>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I know it works, but the missing parentheses on the constructor just feel strange to me. Could we use new Set<string>(); instead?

Comment on lines +74 to +77
const fabricateFirstStageEvent = (stage: ProgramStage) => ({
programStageId: stage.id,
programStageName: stage.name,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ideal, but since the alternative would require a big refactor, I agree with using this fabricateFirstStageEvent workaround to serve as a dummy event during the form initialization run.

@superskip superskip added testing and removed testing labels Aug 24, 2026
currentEvent: RuleEventJs | null | undefined,
events: Array<RuleEventJs>,
executionContext: RuleEngineContextJs,
isFirstStageEventForm: boolean | undefined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Can we improve the name? isEnrollmentFormWithFirstStageEvent/isEnrollmentFormWithEvent/isEnrollmentWithFirstStageEventForm/isEnrollmentWithEventForm or something like that.

@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

@superskip superskip added testing and removed testing labels Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants