Skip to content

feat: Event scheduling using program rule [DHIS2-16911] #19868

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

Open
wants to merge 89 commits into
base: master
Choose a base branch
from

Conversation

zubaira
Copy link
Contributor

@zubaira zubaira commented Feb 6, 2025

https://dhis2.atlassian.net/browse/DHIS2-16911
This PR implements the initial support for scheduling events (ProgramRuleActionType.CREATEEVENT) via program rules, triggered from either an enrollment or event context.

It provides the bare minimum functionality required to schedule events based on rule effects.
In the next step, we will handle deduplication logic to avoid scheduling duplicate events when rules are evaluated multiple times.

Copy link

sonarqubecloud bot commented Feb 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 New issue
1 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

final UID programStage = validationEffect.field();

if (!DateUtils.dateIsValid(scheduledAt)) {
return Optional.of(ProgramRuleIssue.warning(programRule, ValidationCode.E1319, scheduledAt));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we validate this when creating the rule action, like the other validations around program stage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not certain whether the user will provide a plain date, a d2: function, or a variable (e.g., V{current_date}).
So validation can only occur after the expression is fully evaluated and transformed into an actual date.

@@ -54,7 +54,7 @@ public enum ProgramRuleActionType {
WARNINGONCOMPLETE("warningoncomplete"),
SHOWERROR("showerror"),
ERRORONCOMPLETE("erroroncomplete"),
CREATEEVENT("createevent"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me, what are the consequences for this renaming an existing action type? Will there be instances out there that has the create event action type somewhere in their DB which would start to fail?

I know we never supported it yet. But just thinking, if some values exist in the DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's possible since we're not restricting the creation of CREATEEVENT via APIs (only UI does not support it). Added CREATEEVENT again

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.

For me now the PR is in good shape but we should have a clear plan on how to avoid duplication of scheduled events.

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