Skip to content

Commit

Permalink
fix: program stage field in event query select duplicate [DHIS2-15899] (
Browse files Browse the repository at this point in the history
#15355)

* fix: ps in select duplicate

* fix: add integration tests

* fix: add programe stage to test order

* fix: constants
  • Loading branch information
lucaCambi77 authored Oct 16, 2023
1 parent 6f13dc6 commit 709e258
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ private String getEventSelectQuery(
.append("select ")
.append(getEventSelectIdentifiersByIdScheme(params))
.append(" psi.uid as psi_uid, ")
.append("ou.uid as ou_uid, p.uid as p_uid, ps.uid as ps_uid, ")
.append("ou.uid as ou_uid, p.uid as p_uid, ")
.append(
"psi.programstageinstanceid as psi_id, psi.status as psi_status, psi.executiondate as psi_executiondate, ")
.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Constants {
new Program()
.setUid("f1AyMswryyQ")
.setTrackedEntityType(Constants.TRACKED_ENTITY_TYPE)
.setProgramStages(Arrays.asList("PaOOjwLVW23", "nlXNK4b7LVr"));
.setProgramStages(Arrays.asList("PaOOjwLVW23", "nlXNK4b7LVr", "xaOOjwLVW23"));

public static String TRACKER_PROGRAM_ID = "f1AyMswryyQ"; // todo: remove and
// use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,29 @@ public void shouldReturnAscOrderedEventByTEIAttribute() {
List.of("ZwwuwNp6gVd", "olfXZzSGacW"), events, "Events are not in the correct order");
}

@Test
public void
shouldReturnProgramStageListOrderedByProgramStageAscWhenFieldsAndOrderEqualToProgramStage() {
TrackerApiResponse response =
trackerActions
.postAndGetJobReport(
teiWithEnrollmentAndEventsTemplate, new QueryParamsBuilder().add("async=false"))
.validateSuccessfulImport();

List<String> actualPsList =
trackerActions
.get(
"events?order=programStage&fields=programStage&program=f1AyMswryyQ&event=ZwwuwNp6gVd;"
+ response.extractImportedEvents().get(0))
.validateStatus(200)
.extractList("instances.programStage.flatten()");

assertEquals(
List.of("nlXNK4b7LVr", "xaOOjwLVW23"),
actualPsList,
"Program Stage are not in the correct order");
}

@Test
void getTeiByPotentialDuplicateParamNull() {
ApiResponse response = teiActions.get(teiParamsBuilder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@
},
{
"id": "PaOOjwLVW23"
},
{
"id": "xaOOjwLVW23"
}
]
},
Expand Down Expand Up @@ -1149,6 +1152,84 @@
"attributeValues": [],
"programStageSections": []
},
{
"code": "TA_TRACKER_PROGRAM_THIRD_STAGE",
"lastUpdated": "2022-01-07T12:50:38.506",
"id": "xaOOjwLVW23",
"created": "2022-01-07T11:57:37.577",
"name": "TA third stage - repeatable",
"allowGenerateNextVisit": false,
"preGenerateUID": false,
"openAfterEnrollment": false,
"repeatable": true,
"remindCompleted": false,
"displayGenerateEventBox": true,
"generatedByEnrollmentDate": false,
"validationStrategy": "ON_COMPLETE",
"autoGenerateEvent": false,
"sortOrder": 2,
"hideDueDate": false,
"blockEntryForm": false,
"enableUserAssignment": false,
"minDaysFromStart": 3,
"program": {
"id": "f1AyMswryyQ"
},
"sharing": {
"owner": "M5zQapPyTZI",
"userGroups": {
"OPVIvvXzNTw": {
"access": "rwrw----",
"id": "OPVIvvXzNTw"
}
},
"external": false,
"public": "rwrw----",
"users": {}
},
"notificationTemplates": [],
"programStageDataElements": [
{
"lastUpdated": "2022-01-07T12:50:38.507",
"id": "fACOFO8XvbY",
"created": "2022-01-07T12:50:38.507",
"displayInReports": false,
"skipSynchronization": false,
"renderOptionsAsRadio": false,
"skipAnalytics": false,
"allowFutureDate": false,
"compulsory": false,
"allowProvidedElsewhere": false,
"sortOrder": 1,
"favorite": false,
"access": {
"read": true,
"update": true,
"externalize": true,
"write": true,
"delete": true,
"manage": true
},
"programStage": {
"id": "xaOOjwLVW23"
},
"dataElement": {
"id": "mB2QHw1tU96"
},
"sharing": {
"userGroups": {},
"external": false,
"users": {}
},
"favorites": [],
"translations": [],
"attributeValues": []
}
],
"translations": [],
"attributeValues": [],
"programStageSections": []
},
{
"code": "TA_TRACKER_PROGRAM_SECOND_STAGE",
"lastUpdated": "2022-01-07T12:50:38.506",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"scheduledAt": "2019-08-19T13:59:13.688",
"program": "f1AyMswryyQ",
"programStage": "PaOOjwLVW23",
"programStage": "xaOOjwLVW23",
"orgUnit": "O6uvpzGd5pu",
"enrollmentStatus": "ACTIVE",
"status": "ACTIVE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class EventExporterTest extends TrackerTest {

private ProgramStage programStage;

private ProgramStage programStage1;

private Program program;

final Function<EventQueryParams, List<String>> eventsFunction =
Expand Down Expand Up @@ -135,6 +137,7 @@ protected void initTest() throws IOException {
fromJson("tracker/event_and_enrollment.json", importUser.getUid())));
orgUnit = get(OrganisationUnit.class, "h4w96yEMlzO");
programStage = get(ProgramStage.class, "NpsdDv6kKSO");
programStage1 = get(ProgramStage.class, "qLZC0lvvxQH");
program = programStage.getProgram();
trackedEntityInstance = get(TrackedEntityInstance.class, "dUE514NMOlo");

Expand Down Expand Up @@ -1451,6 +1454,24 @@ void testExportEventsWithDatesIncludingTimeStamp() {
() -> assertHasTimeStamp(event.getCompletedDate()));
}

@Test
void testExportEventsWithProgramStageOrder() {

EventQueryParams params = new EventQueryParams();

params.setEvents(Set.of("pTzf9KYMk72", "QRYjLTiJTrA"));
params.addOrders(List.of(new OrderParam("programStage", SortDirection.ASC)));

Events events = eventService.getEvents(params);

assertNotEmpty(events.getEvents());

assertEquals(
List.of("NpsdDv6kKSO", "qLZC0lvvxQH"),
events.getEvents().stream().map(Event::getProgramStage).collect(Collectors.toList()),
"Program Stage are not in the correct order");
}

private void assertNote(User expectedLastUpdatedBy, String expectedNote, Note actual) {
assertEquals(expectedNote, actual.getValue());
UserInfoSnapshot lastUpdatedBy = actual.getLastUpdatedBy();
Expand Down

0 comments on commit 709e258

Please sign in to comment.