From 38433a34a31cb781538a00320a2ec627cf61e10f Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Wed, 8 Nov 2023 09:28:57 +0100 Subject: [PATCH] [ANDROSDK-1782] Support search by trackedEntity in TEI search --- ...eQueryCollectionRepositoryMockIntegrationShould.kt | 9 +++++++++ ...SearchCollectionRepositoryMockIntegrationShould.kt | 10 ++++++++++ .../TrackedEntityInstanceQueryCollectionRepository.kt | 2 +- .../search/TrackedEntitySearchCollectionRepository.kt | 2 +- .../search/TrackedEntitySearchOperators.kt | 11 +++++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt index 24b8a3d1d8..d1ce02196f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt @@ -126,6 +126,15 @@ class TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould : assertThat(trackedEntityInstances.size).isEqualTo(1) } + @Test + fun find_by_uid() { + val trackedEntityInstances = d2.trackedEntityModule().trackedEntityInstanceQuery() + .byTrackedEntities().eq("nWrB0TfWlvh") + .blockingGet() + + assertThat(trackedEntityInstances.size).isEqualTo(1) + } + @Test fun exclude_uids() { val trackedEntityInstances = d2.trackedEntityModule().trackedEntityInstanceQuery() diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntitySearchCollectionRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntitySearchCollectionRepositoryMockIntegrationShould.kt index c3d2ec69c5..03c269e854 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntitySearchCollectionRepositoryMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/trackedentity/search/TrackedEntitySearchCollectionRepositoryMockIntegrationShould.kt @@ -80,6 +80,16 @@ class TrackedEntitySearchCollectionRepositoryMockIntegrationShould : assertThat(trackedEntityInstances[1].header).isEqualTo("654321, ") } + @Test + fun should_return_header_in_object_repository() { + val trackedEntity = d2.trackedEntityModule().trackedEntitySearch() + .byProgram().eq("IpHINAT79UW") + .uid("nWrB0TfWlvh") + .blockingGet() + + assertThat(trackedEntity?.header).isEqualTo("4081507, befryEfXge5") + } + @Test fun should_return_ordered_attributes() { val trackedEntity = d2.trackedEntityModule().trackedEntitySearch() diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepository.kt index 054d6953d5..6dcaccfc44 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepository.kt @@ -199,7 +199,7 @@ class TrackedEntityInstanceQueryCollectionRepository internal constructor( } override fun uid(uid: String?): ReadOnlyObjectRepository { - return objectRepository( + return byTrackedEntities().eq(uid).objectRepository( object : Transformer, TrackedEntityInstance?> { override fun transform(o: List): TrackedEntityInstance? { return o.find { uid == it.uid() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchCollectionRepository.kt index 1dd52a86d4..11eb47415c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchCollectionRepository.kt @@ -167,7 +167,7 @@ class TrackedEntitySearchCollectionRepository internal constructor( } override fun uid(uid: String?): ReadOnlyObjectRepository { - return objectRepository( + return byTrackedEntities().eq(uid).objectRepository( object : Transformer, TrackedEntitySearchItem?> { override fun transform(o: List): TrackedEntitySearchItem? { return o.find { uid == it.uid() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchOperators.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchOperators.kt index d1a01cf58d..e0ff967c51 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchOperators.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntitySearchOperators.kt @@ -345,6 +345,17 @@ abstract class TrackedEntitySearchOperators internal constru } } + /** + * Filter by trackedEntity uid + * + * @return Repository connector + */ + fun byTrackedEntities(): ListFilterConnector { + return connectorFactory.listConnector { list: List -> + scope.toBuilder().uids(list).build() + } + } + /** * Whether to allow or not cached results for online queries. Its value is 'false' by default. *