diff --git a/packages/rules-engine/src/services/VariableService/variableService.types.js b/packages/rules-engine/src/services/VariableService/variableService.types.js index 9640354c46..2977933c29 100644 --- a/packages/rules-engine/src/services/VariableService/variableService.types.js +++ b/packages/rules-engine/src/services/VariableService/variableService.types.js @@ -27,6 +27,7 @@ type EventMain = { +status?: $Values, +occurredAt?: string, +scheduledAt?: string, + +createdAt?: string, }; export type EventValues = { diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/DataEntry/epics/editEventDataEntry.epics.js b/src/core_modules/capture-core/components/WidgetEventEdit/DataEntry/epics/editEventDataEntry.epics.js index 69d7a4ab24..05515b4bcc 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/DataEntry/epics/editEventDataEntry.epics.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/DataEntry/epics/editEventDataEntry.epics.js @@ -65,14 +65,21 @@ const runRulesForEditSingleEvent = ({ if (program instanceof TrackerProgram) { const { enrollment, attributeValues } = state.enrollmentDomain; + const { apiOtherEvents, apiCurrentEventOriginal } = enrollment.events.reduce((acc, apiEvent) => { + if (apiEvent.event === currentEvent.eventId) { + acc.apiCurrentEventOriginal = apiEvent; + } else { + acc.apiOtherEvents.push(apiEvent); + } + return acc; + }, { apiOtherEvents: [] }); + effects = getApplicableRuleEffectsForTrackerProgram({ program, stage, orgUnit, - currentEvent, - otherEvents: prepareEnrollmentEventsForRulesEngine( - enrollment?.events.filter(enrollmentEvent => enrollmentEvent.event !== currentEvent.eventId), - ), + currentEvent: { ...currentEvent, createdAt: apiCurrentEventOriginal.createdAt }, + otherEvents: prepareEnrollmentEventsForRulesEngine(apiOtherEvents), enrollmentData: getEnrollmentForRulesEngine(enrollment), attributeValues: getAttributeValuesForRulesEngine(attributeValues, program.attributes), });