Search in sources :

Example 81 with BaseDimensionalObject

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);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Example 82 with BaseDimensionalObject

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);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Example 83 with BaseDimensionalObject

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);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Example 84 with BaseDimensionalObject

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()));
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseNameableObject(org.hisp.dhis.common.BaseNameableObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 85 with BaseDimensionalObject

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) HashMap(java.util.HashMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)108 Test (org.junit.jupiter.api.Test)77 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)69 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)31 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DimensionalObject (org.hisp.dhis.common.DimensionalObject)22 ArrayList (java.util.ArrayList)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)18 Grid (org.hisp.dhis.common.Grid)17 HashMap (java.util.HashMap)14 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)14 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 CategoryCombo (org.hisp.dhis.category.CategoryCombo)11 DataElement (org.hisp.dhis.dataelement.DataElement)11 Test (org.junit.Test)11 Map (java.util.Map)9 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)9 Period (org.hisp.dhis.period.Period)9 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)8 QueryItem (org.hisp.dhis.common.QueryItem)8