Search in sources :

Example 76 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTypeValue.

@Test
void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTypeValue() {
    // Given
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.COORDINATE);
    item.setProgramStage(programStageWithRepeatableParams);
    item.setProgram(programB);
    RepeatableStageParams repeatableStageParams = new RepeatableStageParams();
    repeatableStageParams.setStartIndex(0);
    repeatableStageParams.setCount(100);
    repeatableStageParams.setStartDate(DateUtils.parseDate("2022-01-01"));
    repeatableStageParams.setEndDate(DateUtils.parseDate("2022-01-31"));
    item.setRepeatableStageParams(repeatableStageParams);
    // When
    String columnSql = subject.getColumn(item);
    // Then
    assertThat(columnSql, is("(select json_agg(t1) from (select \"" + dataElementA.getUid() + "\", incidentdate, duedate, executiondate  from analytics_event_" + programB.getUid() + " where analytics_event_" + programB.getUid() + ".pi = ax.pi and \"" + dataElementA.getUid() + "\" is not null and ps = '" + programStageWithRepeatableParams.getUid() + "' and executiondate >= '2022-01-01'  and executiondate <= '2022-01-31' order by executiondate desc LIMIT 100 ) as t1)"));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 77 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyGetCoordinateColumnWithNoProgram.

@Test
void verifyGetCoordinateColumnWithNoProgram() {
    // Given
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.COORDINATE);
    item.setProgramStage(programStage);
    // When
    String columnSql = subject.getCoordinateColumn(item);
    // Then
    assertThat(columnSql, is(EMPTY));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 78 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EventAnalyticsTest method createRequestParams.

protected EventQueryParams createRequestParams(ProgramStage withProgramStage, ValueType withQueryItemValueType) {
    EventQueryParams.Builder params = new EventQueryParams.Builder(_createRequestParams());
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    params.withProgram(programA);
    if (withProgramStage != null) {
        params.withProgramStage(programStage);
    }
    if (withQueryItemValueType != null) {
        QueryItem queryItem = new QueryItem(dio);
        if (withProgramStage != null) {
            queryItem.setProgramStage(programStage);
        }
        queryItem.setProgram(programA);
        queryItem.setValueType(withQueryItemValueType);
        params.addItem(queryItem);
    }
    return params.build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Example 79 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testSetItemsForDimensionFilters.

@Test
void testSetItemsForDimensionFilters() {
    TrackedEntityAttribute tea = new TrackedEntityAttribute();
    tea.setAutoFields();
    TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:2");
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.getColumnDimensions().add(tea.getUid());
    eventChart.getAttributeDimensions().add(tead);
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(tea.getUid(), tea.getName()));
    grid.addRow().addValue("1");
    grid.addRow().addValue("2");
    grid.addRow().addValue("3");
    grid.addRow().addValue(null);
    eventChart.populateAnalyticalProperties();
    DimensionalObject dim = eventChart.getColumns().get(0);
    DimensionalObjectUtils.setDimensionItemsForFilters(dim, grid, true);
    assertNotNull(dim);
    assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
    assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
    assertEquals(tead.getFilter(), dim.getFilter());
    List<DimensionalItemObject> items = dim.getItems();
    assertEquals(4, items.size());
    assertNotNull(items.get(0).getUid());
    assertNotNull(items.get(0).getName());
    assertNotNull(items.get(0).getCode());
    assertNotNull(items.get(0).getShortName());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) EventChart(org.hisp.dhis.eventchart.EventChart) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 80 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class QueryPlannerTest method testGetDataPeriodAggregationPeriodMap.

@Test
void testGetDataPeriodAggregationPeriodMap() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000Q3"), createPeriod("2000Q4"), createPeriod("2001Q1"), createPeriod("2001Q2"))).withPeriodType(QuarterlyPeriodType.NAME).withDataPeriodType(new YearlyPeriodType()).build();
    ListMap<DimensionalItemObject, DimensionalItemObject> map = params.getDataPeriodAggregationPeriodMap();
    assertEquals(2, map.size());
    assertTrue(map.containsKey(createPeriod("2000")));
    assertTrue(map.containsKey(createPeriod("2001")));
    assertEquals(4, map.get(createPeriod("2000")).size());
    assertEquals(2, map.get(createPeriod("2001")).size());
    assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q1")));
    assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q2")));
    assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q3")));
    assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q4")));
    assertTrue(map.get(createPeriod("2001")).contains(createPeriod("2001Q1")));
    assertTrue(map.get(createPeriod("2001")).contains(createPeriod("2001Q2")));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)178 Test (org.junit.jupiter.api.Test)63 ArrayList (java.util.ArrayList)51 DimensionalObject (org.hisp.dhis.common.DimensionalObject)48 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)42 Period (org.hisp.dhis.period.Period)41 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)40 HashMap (java.util.HashMap)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)22 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)20 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)20 DataElement (org.hisp.dhis.dataelement.DataElement)20 List (java.util.List)17 Indicator (org.hisp.dhis.indicator.Indicator)17 Grid (org.hisp.dhis.common.Grid)16 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)16 ListMap (org.hisp.dhis.common.ListMap)15 QueryItem (org.hisp.dhis.common.QueryItem)15