From 46caa2b1fb0162188481864f8f2403412027f776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Storl=C3=B8kken=20Melseth?= Date: Thu, 17 Oct 2024 14:08:19 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20[DHIS2-18248]=C2=A0pass=20on=20createdAt?= =?UTF-8?q?=20to=20rules=20engine=20when=20editing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../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), });