Skip to content

Commit

Permalink
fix: Fix enrollment queyr to get correct orgUnit [DHIS2-14829] (#19130)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante authored Nov 12, 2024
1 parent a76769a commit 286f75c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static String getQuery() {
+ "join program p on en.programid = p.programid "
+ "join trackedentity te on en.trackedentityid = te.trackedentityid "
+ "join trackedentitytype tet on te.trackedentitytypeid = tet.trackedentitytypeid "
+ "join organisationunit o on te.organisationunitid = o.organisationunitid "
+ "join organisationunit o on en.organisationunitid = o.organisationunitid "
+ "where en.trackedentityid in (:ids) ";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void setUp() {
enrollmentA.setFollowup(true);
manager.save(enrollmentA, false);

enrollmentB = createEnrollment(programB, trackedEntityA, orgUnitA);
enrollmentB = createEnrollment(programB, trackedEntityA, orgUnitB);
manager.save(enrollmentB);
trackedEntityA.getEnrollments().add(enrollmentB);
manager.update(trackedEntityA);
Expand Down Expand Up @@ -642,6 +642,42 @@ void shouldReturnTrackedEntityIncludingAllAttributesEnrollmentsEventsRelationshi
.collect(Collectors.toSet())));
}

@Test
void shouldReturnTrackedEntityIncludingAllEnrollments()
throws ForbiddenException, NotFoundException, BadRequestException {
TrackedEntityOperationParams operationParams =
TrackedEntityOperationParams.builder()
.organisationUnits(orgUnitA)
.orgUnitMode(SELECTED)
.trackedEntityType(trackedEntityTypeA)
.trackedEntityParams(TrackedEntityParams.TRUE)
.build();

final List<TrackedEntity> trackedEntities =
trackedEntityService.getTrackedEntities(operationParams);

assertContainsOnly(List.of(trackedEntityA.getUid()), uids(trackedEntities));
assertContainsOnly(
Set.of(enrollmentA.getUid(), enrollmentB.getUid()),
uids(trackedEntities.get(0).getEnrollments()));
assertEquals(
orgUnitA.getUid(),
trackedEntities.get(0).getEnrollments().stream()
.filter(e -> e.getUid().equals(enrollmentA.getUid()))
.findFirst()
.get()
.getOrganisationUnit()
.getUid());
assertEquals(
orgUnitB.getUid(),
trackedEntities.get(0).getEnrollments().stream()
.filter(e -> e.getUid().equals(enrollmentB.getUid()))
.findFirst()
.get()
.getOrganisationUnit()
.getUid());
}

@Test
void shouldReturnTrackedEntityIncludeSpecificProtectedProgram()
throws ForbiddenException, NotFoundException, BadRequestException {
Expand Down

0 comments on commit 286f75c

Please sign in to comment.