use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryValidatorTest method validateSuccessSingleIndicatorFilter.
@Test
void validateSuccessSingleIndicatorFilter() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(inA))).build();
queryValidator.validate(params);
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryValidatorTest method validateFailureSkipTotalDataElements.
/**
* Asserts that the total value cannot be retrieved for data elements with
* category combinations with skip total enabled.
*/
@Test
void validateFailureSkipTotalDataElements() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deC))).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA))).build();
assertValidatonError(ErrorCode.E7134, params);
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryValidatorTest method validateFailureAggregationType.
@Test
void validateFailureAggregationType() {
deB.setAggregationType(AggregationType.CUSTOM);
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB))).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
assertValidatonError(ErrorCode.E7115, params);
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class AnalyticsServiceMetadataTest method metadataContainsRelativePeriodItem.
@SuppressWarnings("unchecked")
@Test
void metadataContainsRelativePeriodItem() {
List<DimensionalItemObject> periods = new ArrayList<>();
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
BaseDimensionalObject periodDimension = new BaseDimensionalObject("pe", DimensionType.PERIOD, periods);
DimensionItemKeywords dimensionalKeywords = new DimensionItemKeywords();
dimensionalKeywords.addKeyword(THIS_QUARTER.name(), "This quarter");
periodDimension.setDimensionalKeywords(dimensionalKeywords);
DataQueryParams params = DataQueryParams.newBuilder().withDimensions(Lists.newArrayList(periodDimension, new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo()))))).withSkipData(true).build();
initMock(params);
Grid grid = target.getAggregatedDataValueGrid(params);
Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
assertTrue(items.containsKey(THIS_QUARTER.name()));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class AnalyticsServiceReportingRateTest method verifyReportingRatesValueWhenPeriodIsFilter.
@Test
void verifyReportingRatesValueWhenPeriodIsFilter() {
int timeUnit = 10;
double expectedReports = 100D;
DataSet dataSetA = createDataSet('A');
ReportingRate reportingRateA = new ReportingRate(dataSetA);
reportingRateA.setMetric(ReportingRateMetric.REPORTING_RATE);
ReportingRate reportingRateB = new ReportingRate(dataSetA);
reportingRateB.setMetric(ReportingRateMetric.ACTUAL_REPORTS);
ReportingRate reportingRateC = new ReportingRate(dataSetA);
reportingRateC.setMetric(ReportingRateMetric.EXPECTED_REPORTS);
List<DimensionalItemObject> periods = new ArrayList<>();
Stream.iterate(1, i -> i + 1).limit(timeUnit).forEach(x -> periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, x, 1, 0, 0).toDate())));
OrganisationUnit ou = new OrganisationUnit("aaaa");
DataQueryParams params = DataQueryParams.newBuilder().withOrganisationUnit(ou).withDataElements(newArrayList(reportingRateA, reportingRateB, reportingRateC)).withIgnoreLimit(true).withFilters(singletonList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods))).build();
initMock(params);
Map<String, Object> actualReports = new HashMap<>();
actualReports.put(dataSetA.getUid() + "-" + ou.getUid(), 500D);
when(analyticsManager.getAggregatedDataValues(any(DataQueryParams.class), eq(AnalyticsTableType.COMPLETENESS), eq(0))).thenReturn(CompletableFuture.completedFuture(actualReports));
Map<String, Object> reportingRate = new HashMap<>();
reportingRate.put(dataSetA.getUid() + "-" + ou.getUid(), expectedReports);
when(analyticsManager.getAggregatedDataValues(any(DataQueryParams.class), eq(AnalyticsTableType.COMPLETENESS_TARGET), eq(0))).thenReturn(CompletableFuture.completedFuture(reportingRate));
Grid grid = target.getAggregatedDataValueGrid(params);
assertEquals(expectedReports * timeUnit, getValueFromGrid(grid.getRows(), makeKey(dataSetA, ReportingRateMetric.EXPECTED_REPORTS)).get(), 0);
assertEquals(50D, getValueFromGrid(grid.getRows(), makeKey(dataSetA, ReportingRateMetric.REPORTING_RATE)).get(), 0);
assertEquals(500D, getValueFromGrid(grid.getRows(), makeKey(dataSetA, ReportingRateMetric.ACTUAL_REPORTS)).get(), 0);
}
Aggregations