Skip to content

feat: Prevent duplicate event creation from SCHEDULEEVENT rule action [DHIS2-19849] #21433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 100 commits into
base: master
Choose a base branch
from

Conversation

zubaira
Copy link
Contributor

@zubaira zubaira commented Jul 17, 2025

DO NOT MERGE. This PR should be merged after this one. #19868.

https://dhis2.atlassian.net/browse/DHIS2-19849

This PR continues the work from #19868. It introduces a validation step in the rule-engine–based scheduling logic to avoid creating duplicate events.

If the program stage is non-repeatable, the system will skip scheduling a new event if an existing one is already present for the same enrollment.
If the program stage is repeatable, the scheduling logic will proceed and allow the new event to be created.

Copy link
Contributor

@enricocolasante enricocolasante left a comment

Choose a reason for hiding this comment

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

We need to review the logic:

If the program stage is non-repeatable, the system will skip scheduling a new event if an existing one is already present for the same enrollment.
If the program stage is repeatable, the scheduling logic will proceed and allow the new event to be created.

I don't think this is enough to prevent duplicates. If the program stage is repeatable then every time there is a small change to the event (like change the value of a data value, update the status), a new event is scheduled. We need to prevent this kind of creation. The scheduled event should be created only once, no matter the type of the program stage

@@ -106,8 +107,8 @@ public Map<ProgramRuleActionType, ProgramRuleActionValidator> programRuleActionV
ProgramRuleActionType.HIDEFIELD,
getProgramRuleActionValidatorByClass(BaseProgramRuleActionValidator.class))
.put(
ProgramRuleActionType.CREATEEVENT,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep the base validator for CREATEEVENT?

@@ -81,9 +81,10 @@ public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) {

List<String> notRepeatableProgramStageUids =
trackerObjects.getEvents().stream()
.map(Event::getProgramStage)
.map(Event::getProgram)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to change this code?
We are potentially introducing a lot of unnecessary data into the Preheat.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change here? Do you need to rebase?

@ameenhere
Copy link
Contributor

Just a thought, would be a good first version if we only allow one scheduled event to exist even if it is a repeatable program stage? So if there already is a scheduled event for that program stage, then no new scheduled event is created. @enricocolasante @zubaira thoughts?

@zubaira
Copy link
Contributor Author

zubaira commented Jul 23, 2025

Just a thought, would be a good first version if we only allow one scheduled event to exist even if it is a repeatable program stage? So if there already is a scheduled event for that program stage, then no new scheduled event is created. @enricocolasante @zubaira thoughts?

@ameenhere that's what we agreed upon.

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants