fix: [DHIS2-21727] program rules on enrollment+event registration page - #4707
fix: [DHIS2-21727] program rules on enrollment+event registration page#4707superskip wants to merge 10 commits into
Conversation
Refactored out `evaluateRules` to fix complexity issue
|
🚀 Deployed on https://deploy-preview-4707.capture.netlify.dhis2.org |
| executionContext, | ||
| ); | ||
| } | ||
| const duplicateActionIds = new Set<string>; |
There was a problem hiding this comment.
NIT: I know it works, but the missing parentheses on the constructor just feel strange to me. Could we use new Set<string>(); instead?
| const fabricateFirstStageEvent = (stage: ProgramStage) => ({ | ||
| programStageId: stage.id, | ||
| programStageName: stage.name, | ||
| }); |
There was a problem hiding this comment.
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.
| currentEvent: RuleEventJs | null | undefined, | ||
| events: Array<RuleEventJs>, | ||
| executionContext: RuleEngineContextJs, | ||
| isFirstStageEventForm: boolean | undefined, |
There was a problem hiding this comment.
NIT: Can we improve the name? isEnrollmentFormWithFirstStageEvent/isEnrollmentFormWithEvent/isEnrollmentWithFirstStageEventForm/isEnrollmentWithEventForm or something like that.
|



Introduces a new argument
isEnrollmentFormWithEventin the rule engine, which should be set totruewhen 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 useevaluateAllwhen 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.