use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class AbstractEventService method getEventsGrid.
@Transactional(readOnly = true)
@Override
public Grid getEventsGrid(EventSearchParams params) {
User user = currentUserService.getCurrentUser();
if (params.getProgramStage() == null || params.getProgramStage().getProgram() == null) {
throw new IllegalQueryException("Program stage can not be null");
}
if (params.getProgramStage().getProgramStageDataElements() == null) {
throw new IllegalQueryException("Program stage should have at least one data element");
}
List<OrganisationUnit> organisationUnits = getOrganisationUnits(params, user);
params.handleCurrentUserSelectionMode(user);
if (params.isIncludeAllDataElements()) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
} else {
if (params.getDataElements().isEmpty()) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
if (pde.getDisplayInReports()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
}
}
}
// ---------------------------------------------------------------------
// Grid headers
// ---------------------------------------------------------------------
Grid grid = new ListGrid();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addHeader(new GridHeader(col, col));
}
for (QueryItem item : params.getDataElements()) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName()));
}
List<Map<String, String>> events = eventStore.getEventsGrid(params, organisationUnits);
for (Map<String, String> event : events) {
grid.addRow();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addValue(event.get(col));
}
for (QueryItem item : params.getDataElements()) {
grid.addValue(event.get(item.getItemId()));
}
}
Map<String, Object> metaData = new HashMap<>();
if (params.isPaging()) {
final Pager pager;
if (params.isTotalPages()) {
int count = eventStore.getEventCount(params, organisationUnits);
pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
} else {
pager = handleLastPageFlag(params, grid);
}
metaData.put(PAGER_META_KEY, pager);
}
grid.setMetaData(metaData);
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class DataAggregator method getAggregatedDataValueGrid.
/**
* Returns a grid with aggregated data.
*
* @param params the {@link DataQueryParams}.
* @return a grid with aggregated data.
*/
public Grid getAggregatedDataValueGrid(DataQueryParams params) {
params = preHandleQuery(params);
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
Grid grid = new ListGrid();
headerHandler.addHeaders(params, grid);
// ---------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------
dataHandler.addIndicatorValues(params, grid);
dataHandler.addDataElementValues(params, grid);
dataHandler.addDataElementOperandValues(params, grid);
dataHandler.addReportingRates(params, grid);
dataHandler.addProgramDataElementAttributeIndicatorValues(params, grid);
dataHandler.addDynamicDimensionValues(params, grid);
dataHandler.addValidationResultValues(params, grid);
dataHandler.addPerformanceMetrics(params, grid);
// ---------------------------------------------------------------------
// Meta-data
// ---------------------------------------------------------------------
metaDataHandler.addMetaData(params, grid);
metaDataHandler.handleDataValueSet(params, grid);
metaDataHandler.applyIdScheme(params, grid);
postHandleGrid(params, grid);
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyWithProgramIndicatorAndRelationshipTypeBothSidesTei2.
@Test
void verifyWithProgramIndicatorAndRelationshipTypeBothSidesTei2() {
Date startDate = getDate(2015, 1, 1);
Date endDate = getDate(2017, 4, 8);
Program programB = createProgram('B');
String piSubquery = "distinct psi";
ProgramIndicator programIndicatorA = createProgramIndicator('A', programB, "", "");
RelationshipType relationshipTypeA = createRelationshipType();
EventQueryParams.Builder params = new EventQueryParams.Builder(createRequestParams(programIndicatorA, relationshipTypeA)).withStartDate(startDate).withEndDate(endDate);
when(programIndicatorService.getAnalyticsSql("", programIndicatorA, getDate(2000, 1, 1), getDate(2017, 4, 8), "subax")).thenReturn(piSubquery);
subject.getEnrollments(params.build(), new ListGrid(), 100);
verify(jdbcTemplate).queryForRowSet(sql.capture());
String expected = "ax.\"monthly\",ax.\"ou\",(SELECT avg (" + piSubquery + ") FROM analytics_event_" + programB.getUid().toLowerCase() + " as subax WHERE " + "subax.tei in (select tei.uid from trackedentityinstance tei " + "LEFT JOIN relationshipitem ri on tei.trackedentityinstanceid = ri.trackedentityinstanceid " + "LEFT JOIN relationship r on r.from_relationshipitemid = ri.relationshipitemid " + "LEFT JOIN relationshipitem ri2 on r.to_relationshipitemid = ri2.relationshipitemid " + "LEFT JOIN relationshiptype rty on rty.relationshiptypeid = r.relationshiptypeid " + "LEFT JOIN trackedentityinstance tei on tei.trackedentityinstanceid = ri2.trackedentityinstanceid " + "WHERE rty.relationshiptypeid = " + relationshipTypeA.getId() + " AND tei.uid = ax.tei )) as \"" + programIndicatorA.getUid() + "\" " + "from analytics_enrollment_" + programA.getUid() + " as ax where enrollmentdate >= '2015-01-01' and enrollmentdate < '2017-04-09' and (uidlevel1 = 'ouabcdefghA' ) limit 101";
assertSql(sql.getValue(), expected);
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyWithProgramStageAndTextualDataElementAndFilter.
@Test
void verifyWithProgramStageAndTextualDataElementAndFilter() {
EventQueryParams params = createRequestParamsWithFilter(programStage, ValueType.TEXT);
subject.getEnrollments(params, new ListGrid(), 10000);
verify(jdbcTemplate).queryForRowSet(sql.capture());
String subSelect = "(select \"fWIAEtYVEGk\" from analytics_event_" + programA.getUid() + " where analytics_event_" + programA.getUid() + ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '" + programStage.getUid() + "' order by executiondate desc limit 1 )";
String expected = "ax.\"monthly\",ax.\"ou\"," + subSelect + " from " + getTable(programA.getUid()) + " as ax where ax.\"monthly\" in ('2000Q1') and (uidlevel1 = 'ouabcdefghA' ) " + "and ps = '" + programStage.getUid() + "' and " + subSelect + " > '10' limit 10001";
assertSql(sql.getValue(), expected);
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyWithProgramIndicatorAndRelationshipTypeDifferentConstraint.
@Test
void verifyWithProgramIndicatorAndRelationshipTypeDifferentConstraint() {
Date startDate = getDate(2015, 1, 1);
Date endDate = getDate(2017, 4, 8);
String piSubquery = "distinct psi";
ProgramIndicator programIndicatorA = createProgramIndicator('A', programA, "", "");
RelationshipType relationshipTypeA = createRelationshipType(RelationshipEntity.PROGRAM_INSTANCE);
EventQueryParams.Builder params = new EventQueryParams.Builder(createRequestParams(programIndicatorA, relationshipTypeA)).withStartDate(startDate).withEndDate(endDate);
when(programIndicatorService.getAnalyticsSql("", programIndicatorA, getDate(2000, 1, 1), getDate(2017, 4, 8), "subax")).thenReturn(piSubquery);
subject.getEnrollments(params.build(), new ListGrid(), 100);
verify(jdbcTemplate).queryForRowSet(sql.capture());
String expected = "ax.\"monthly\",ax.\"ou\",(SELECT avg (" + piSubquery + ") FROM analytics_event_" + programA.getUid().toLowerCase() + " as subax WHERE " + " subax.tei in (select tei.uid from trackedentityinstance tei LEFT JOIN relationshipitem ri on tei.trackedentityinstanceid = ri.trackedentityinstanceid " + "LEFT JOIN relationship r on r.from_relationshipitemid = ri.relationshipitemid " + "LEFT JOIN relationshipitem ri2 on r.to_relationshipitemid = ri2.relationshipitemid " + "LEFT JOIN relationshiptype rty on rty.relationshiptypeid = r.relationshiptypeid " + "LEFT JOIN programinstance pi on pi.programinstanceid = ri2.programinstanceid WHERE rty.relationshiptypeid " + "= " + relationshipTypeA.getId() + " AND pi.uid = ax.pi ))" + " as \"" + programIndicatorA.getUid() + "\" " + "from analytics_enrollment_" + programA.getUid() + " as ax where enrollmentdate >= '2015-01-01' and enrollmentdate < '2017-04-09' and (uidlevel1 = 'ouabcdefghA' ) limit 101";
assertSql(sql.getValue(), expected);
}
Aggregations