use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class JdbcEventStore method buildGridSql.
private String buildGridSql(EventSearchParams params, List<OrganisationUnit> organisationUnits) {
SqlHelper hlp = new SqlHelper();
// ---------------------------------------------------------------------
// Select clause
// ---------------------------------------------------------------------
StringBuilder sqlBuilder = new StringBuilder().append("select ").append(COLUMNS_ALIAS_MAP.entrySet().stream().map(col -> col.getKey() + " as " + col.getValue()).collect(Collectors.joining(", "))).append(" , ");
for (QueryItem item : params.getDataElementsAndFilters()) {
final String col = item.getItemId();
final String dataValueValueSql = "psi.eventdatavalues #>> '{" + col + ", value}'";
String queryCol = item.isNumeric() ? castToNumber(dataValueValueSql) : dataValueValueSql;
queryCol += " as " + col + ", ";
sqlBuilder.append(queryCol);
}
String intermediateSql = sqlBuilder.toString();
sqlBuilder = new StringBuilder().append(removeLastComma(intermediateSql)).append(" ");
// ---------------------------------------------------------------------
// From and where clause
// ---------------------------------------------------------------------
sqlBuilder.append(getFromWhereClause(params, hlp, organisationUnits));
// ---------------------------------------------------------------------
// Order clause
// ---------------------------------------------------------------------
sqlBuilder.append(getGridOrderQuery(params));
// ---------------------------------------------------------------------
// Paging clause
// ---------------------------------------------------------------------
sqlBuilder.append(getEventPagingQuery(params));
return sqlBuilder.toString();
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class EventXmlImportTest method testNoAccessEvent.
@Test
void testNoAccessEvent() throws IOException {
InputStream is = createEventXmlInputStream();
ImportSummaries importSummaries = eventService.addEventsXml(is, null);
assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
// Get by admin
Events events = eventService.getEvents(new EventSearchParams().setProgram(programA).setOrgUnitSelectionMode(OrganisationUnitSelectionMode.ACCESSIBLE));
assertEquals(1, events.getEvents().size());
// Get by user without access
User user = createUser("A");
userService.addUser(user);
injectSecurityContext(user);
events = eventService.getEvents(new EventSearchParams().setProgram(programA).setOrgUnitSelectionMode(OrganisationUnitSelectionMode.ACCESSIBLE));
assertEquals(0, events.getEvents().size());
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class EventXmlImportTest method testGeometry.
@Test
void testGeometry() throws IOException {
InputStream is = createEventXmlInputStream();
ImportSummaries importSummaries = eventService.addEventsXml(is, null);
assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
Events events = eventService.getEvents(new EventSearchParams().setProgram(programA).setOrgUnitSelectionMode(OrganisationUnitSelectionMode.ACCESSIBLE));
assertEquals(1, events.getEvents().size());
assertTrue(events.getEvents().stream().allMatch(e -> e.getGeometry().getGeometryType().equals("Point")));
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testDeleteEnrollmentWithEvents.
@Test
void testDeleteEnrollmentWithEvents() {
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
eventService.addEvent(event, null, false);
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
enrollment.setEvents(Lists.newArrayList(event));
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
Enrollment retrievedEnrlollment = enrollmentService.getEnrollment(tei.getEnrollments().get(0).getEnrollment());
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
Event retrievedEvent = enrollment.getEvents().get(0);
assertNotNull(retrievedEnrlollment);
assertNotNull(retrievedEvent);
enrollmentService.deleteEnrollment(retrievedEnrlollment.getEnrollment());
assertNull(enrollmentService.getEnrollment(tei.getEnrollments().get(0).getEnrollment()));
assertEquals(1, eventService.getEvents(params).getEvents().size());
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class RegistrationSingleEventServiceTest method testSavingMultipleEventsShouldOnlyUpdate.
@Test
@Disabled
void testSavingMultipleEventsShouldOnlyUpdate() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
assertEquals(1, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(1, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(1, eventService.getEvents(params).getEvents().size());
}
Aggregations