Skip to content

Commit

Permalink
Merge pull request #2066 from dhis2/androsdk-1782
Browse files Browse the repository at this point in the history
fix: [ANDROSDK-1782] Support search by trackedEntity in TEI search
  • Loading branch information
vgarciabnz authored Nov 8, 2023
2 parents b47f48b + 38433a3 commit 24c8d0d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class TrackedEntityInstanceQueryCollectionRepository internal constructor(
}

override fun uid(uid: String?): ReadOnlyObjectRepository<TrackedEntityInstance> {
return objectRepository(
return byTrackedEntities().eq(uid).objectRepository(
object : Transformer<List<TrackedEntityInstance>, TrackedEntityInstance?> {
override fun transform(o: List<TrackedEntityInstance>): TrackedEntityInstance? {
return o.find { uid == it.uid() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class TrackedEntitySearchCollectionRepository internal constructor(
}

override fun uid(uid: String?): ReadOnlyObjectRepository<TrackedEntitySearchItem> {
return objectRepository(
return byTrackedEntities().eq(uid).objectRepository(
object : Transformer<List<TrackedEntitySearchItem>, TrackedEntitySearchItem?> {
override fun transform(o: List<TrackedEntitySearchItem>): TrackedEntitySearchItem? {
return o.find { uid == it.uid() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ abstract class TrackedEntitySearchOperators<R : BaseRepository> internal constru
}
}

/**
* Filter by trackedEntity uid
*
* @return Repository connector
*/
fun byTrackedEntities(): ListFilterConnector<R, String> {
return connectorFactory.listConnector { list: List<String> ->
scope.toBuilder().uids(list).build()
}
}

/**
* Whether to allow or not cached results for online queries. Its value is 'false' by default.
*
Expand Down

0 comments on commit 24c8d0d

Please sign in to comment.