diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt index ee3073f305..83ad09e136 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt @@ -185,7 +185,7 @@ internal abstract class IdentifiableDataHandlerImpl( relatives: RelationshipItemRelatives?, ) - protected fun beforeCollectionHandled( + protected open fun beforeCollectionHandled( oCollection: Collection, params: IdentifiableDataHandlerParams, ): Collection { diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventHandler.kt index 39e8e207f1..0f014418bc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventHandler.kt @@ -40,6 +40,8 @@ import org.hisp.dhis.android.core.note.Note import org.hisp.dhis.android.core.note.internal.NoteDHISVersionManager import org.hisp.dhis.android.core.note.internal.NoteHandler import org.hisp.dhis.android.core.note.internal.NoteUniquenessManager +import org.hisp.dhis.android.core.program.ProgramType +import org.hisp.dhis.android.core.program.internal.ProgramStore import org.hisp.dhis.android.core.relationship.internal.EventRelationshipOrphanCleaner import org.hisp.dhis.android.core.relationship.internal.RelationshipDHISVersionManager import org.hisp.dhis.android.core.relationship.internal.RelationshipHandler @@ -53,6 +55,7 @@ internal class EventHandler( relationshipVersionManager: RelationshipDHISVersionManager, relationshipHandler: RelationshipHandler, eventStore: EventStore, + private val programStore: ProgramStore, private val trackedEntityDataValueHandler: TrackedEntityDataValueHandler, private val noteHandler: NoteHandler, private val noteVersionManager: NoteDHISVersionManager, @@ -60,11 +63,25 @@ internal class EventHandler( private val relationshipOrphanCleaner: EventRelationshipOrphanCleaner, ) : IdentifiableDataHandlerImpl(eventStore, relationshipVersionManager, relationshipHandler) { + override fun beforeCollectionHandled( + oCollection: Collection, + params: IdentifiableDataHandlerParams, + ): Collection { + val programTypes = programStore.selectAll().associate { it.uid() to it.programType() } + + val updatedEvents = oCollection.map { + it.takeUnless { programTypes[it.program()] == ProgramType.WITHOUT_REGISTRATION } + ?: it.toBuilder().enrollment(null).build() + } + + return super.beforeCollectionHandled(updatedEvents, params) + } + override fun beforeObjectHandled(o: Event, params: IdentifiableDataHandlerParams): Event { return if (GeometryHelper.isValid(o.geometry())) { o } else { - Log.i(this.javaClass.simpleName, "Event " + o.uid() + " has invalid geometry value") + Log.i(this::class.simpleName, "Event ${o.uid()} has an invalid geometry value") o.toBuilder().geometry(null).build() } } diff --git a/core/src/sharedTest/resources/event/new_tracker_importer_events.json b/core/src/sharedTest/resources/event/new_tracker_importer_events.json index 8f0c0dccbe..ea755b4054 100644 --- a/core/src/sharedTest/resources/event/new_tracker_importer_events.json +++ b/core/src/sharedTest/resources/event/new_tracker_importer_events.json @@ -10,6 +10,7 @@ "program": "lxAQ7Zs9VYR", "event": "single1", "status": "COMPLETED", + "enrollment": "u9mt5Z8assp", "occurredAt": "2018-02-27T00:00:00.000", "createdAt": "2017-08-07T15:47:25.959", "completedAt": "2016-02-27T00:00:00.000", @@ -112,6 +113,7 @@ "program": "lxAQ7Zs9VYR", "event": "single2", "status": "ACTIVE", + "enrollment": "u9mt5Z8assp", "occurredAt": "2017-02-27T00:00:00.000", "createdAt": "2018-08-07T15:47:25.959", "completedAt": "2018-02-27T00:00:00.000", diff --git a/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventHandlerShould.kt b/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventHandlerShould.kt index ab677fbae6..d81357bcea 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventHandlerShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/event/internal/EventHandlerShould.kt @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.note.Note import org.hisp.dhis.android.core.note.internal.NoteDHISVersionManager import org.hisp.dhis.android.core.note.internal.NoteHandler import org.hisp.dhis.android.core.note.internal.NoteUniquenessManager +import org.hisp.dhis.android.core.program.internal.ProgramStore import org.hisp.dhis.android.core.relationship.internal.EventRelationshipOrphanCleaner import org.hisp.dhis.android.core.relationship.internal.RelationshipDHISVersionManager import org.hisp.dhis.android.core.relationship.internal.RelationshipHandler @@ -51,6 +52,7 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class EventHandlerShould { private val eventStore: EventStore = mock() + private val programStore: ProgramStore = mock() private val trackedEntityDataValueHandler: TrackedEntityDataValueHandler = mock() private val trackedEntityDataValue: TrackedEntityDataValue = mock() private val noteHandler: NoteHandler = mock() @@ -84,6 +86,7 @@ class EventHandlerShould { relationshipVersionManager, relationshipHandler, eventStore, + programStore, trackedEntityDataValueHandler, noteHandler, noteVersionManager,