use of org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID in project dhis2-core by dhis2.
the class EventTimeFieldSqlRenderer method getSqlConditionForPeriods.
@Override
protected String getSqlConditionForPeriods(EventQueryParams params) {
final List<DimensionalItemObject> periods = params.getDimensionOrFilterItems(PERIOD_DIM_ID);
Optional<TimeField> timeField = getTimeField(params);
StringBuilder sql = new StringBuilder();
if (timeField.isPresent()) {
sql.append(periods.stream().filter(dimensionalItemObject -> dimensionalItemObject instanceof Period).map(dimensionalItemObject -> (Period) dimensionalItemObject).map(period -> toSqlCondition(period, timeField.get())).collect(Collectors.joining(" or ", "(", ")")));
} else {
String alias = getPeriodAlias(params);
sql.append(quote(alias, params.getPeriodType().toLowerCase())).append(OPEN_IN).append(getQuotedCommaDelimitedString(getUids(periods))).append(") ");
}
return sql.toString();
}
use of org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID in project dhis2-core by dhis2.
the class MetadataHandler method addMetaData.
/**
* Adds meta data values to the given grid based on the given data query
* parameters.
*
* @param params the {@link DataQueryParams}.
* @param grid the grid.
*/
void addMetaData(DataQueryParams params, Grid grid) {
if (!params.isSkipMeta()) {
Map<String, Object> metaData = new HashMap<>();
Map<String, Object> internalMetaData = new HashMap<>();
// -----------------------------------------------------------------
// Items / names element
// -----------------------------------------------------------------
Map<String, String> cocNameMap = getCocNameMap(params);
metaData.put(ITEMS.getKey(), getDimensionMetadataItemMap(params));
// -----------------------------------------------------------------
// Item order elements
// -----------------------------------------------------------------
Map<String, Object> dimensionItems = new HashMap<>();
Calendar calendar = PeriodType.getCalendar();
List<String> periodUids = calendar.isIso8601() ? getUids(params.getDimensionOrFilterItems(PERIOD_DIM_ID)) : getLocalPeriodIdentifiers(params.getDimensionOrFilterItems(PERIOD_DIM_ID), calendar);
dimensionItems.put(PERIOD_DIM_ID, periodUids);
dimensionItems.put(CATEGORYOPTIONCOMBO_DIM_ID, Sets.newHashSet(cocNameMap.keySet()));
for (DimensionalObject dim : params.getDimensionsAndFilters()) {
if (!dimensionItems.containsKey(dim.getDimension())) {
dimensionItems.put(dim.getDimension(), getDimensionalItemIds(dim.getItems()));
}
}
metaData.put(DIMENSIONS.getKey(), dimensionItems);
// -----------------------------------------------------------------
// Organisation unit hierarchy
// -----------------------------------------------------------------
List<OrganisationUnit> organisationUnits = asTypedList(params.getDimensionOrFilterItems(ORGUNIT_DIM_ID));
List<OrganisationUnit> roots = dataQueryService.getUserOrgUnits(params, null);
if (params.isHierarchyMeta()) {
metaData.put(ORG_UNIT_HIERARCHY.getKey(), getParentGraphMap(organisationUnits, roots));
}
if (params.isShowHierarchy()) {
Map<Object, List<?>> ancestorMap = organisationUnits.stream().collect(toMap(OrganisationUnit::getUid, ou -> ou.getAncestorNames(roots, true)));
internalMetaData.put(ORG_UNIT_ANCESTORS.getKey(), ancestorMap);
metaData.put(ORG_UNIT_NAME_HIERARCHY.getKey(), getParentNameGraphMap(organisationUnits, roots, true));
}
grid.setMetaData(copyOf(metaData));
grid.setInternalMetaData(copyOf(internalMetaData));
}
}
use of org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID in project dhis2-core by dhis2.
the class DataQueryServiceTest method testPeriodGetDimension.
@Test
void testPeriodGetDimension() {
DimensionalObject dimension = dataQueryService.getDimension(PERIOD_DIM_ID, List.of("TODAY:EVENT_DATE", "YESTERDAY:ENROLLMENT_DATE", "20210101:INCIDENT_DATE", "20210101_20210201:LAST_UPDATED", "2021-02-01_2021-03-01:SCHEDULED_DATE"), null, null, null, true, true, null);
assertThat(dimension.getItems(), hasSize(5));
assertThat(dimension.getItems().stream().map(dimensionalItemObject -> (Period) dimensionalItemObject).map(Period::getDateField).collect(Collectors.toList()), containsInAnyOrder("EVENT_DATE", "ENROLLMENT_DATE", "INCIDENT_DATE", "LAST_UPDATED", "SCHEDULED_DATE"));
assertEquals(getPeriod(dimension, "INCIDENT_DATE").getStartDate(), getMediumDate("2021-01-01"));
assertEquals(getPeriod(dimension, "INCIDENT_DATE").getEndDate(), getMediumDate("2021-01-01"));
assertEquals(getPeriod(dimension, "LAST_UPDATED").getStartDate(), getMediumDate("2021-01-01"));
assertEquals(getPeriod(dimension, "LAST_UPDATED").getEndDate(), getMediumDate("2021-02-01"));
assertEquals(getPeriod(dimension, "SCHEDULED_DATE").getStartDate(), getMediumDate("2021-02-01"));
assertEquals(getPeriod(dimension, "SCHEDULED_DATE").getEndDate(), getMediumDate("2021-03-01"));
}
Aggregations