From c1910ec34dd31008c94a874a27d5be25d64df3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Storl=C3=B8kken=20Melseth?= Date: Fri, 1 Nov 2024 12:03:46 +0100 Subject: [PATCH] fix: [DHIS2-18248] pass on createdAt to rules engine when editing --- .../VariableService/variableService.types.js | 1 + .../DataEntry/epics/editEventDataEntry.epics.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) 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), });