Search in sources :

Example 1 with EventChart

use of org.hisp.dhis.eventchart.EventChart in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetFromAnalyticalObjectB.

@Test
public void testGetFromAnalyticalObjectB() {
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.setProgram(prA);
    eventChart.getColumnDimensions().add(atA.getUid());
    eventChart.getColumnDimensions().add(deA.getUid());
    eventChart.getRowDimensions().add(DimensionalObject.PERIOD_DIM_ID);
    eventChart.getFilterDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
    eventChart.getAttributeDimensions().add(new TrackedEntityAttributeDimension(atA, null, "LE:5"));
    eventChart.getDataElementDimensions().add(new TrackedEntityDataElementDimension(deA, null, "GE:100"));
    eventChart.getPeriods().add(peA);
    eventChart.getPeriods().add(peB);
    eventChart.getOrganisationUnits().add(ouA);
    eventChart.getOrganisationUnits().add(ouB);
    EventQueryParams params = dataQueryService.getFromAnalyticalObject(eventChart);
    assertNotNull(params);
    assertEquals(2, params.getItems().size());
    assertEquals(2, params.getPeriods().size());
    assertEquals(2, params.getFilterOrganisationUnits().size());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventChart(org.hisp.dhis.eventchart.EventChart) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with EventChart

use of org.hisp.dhis.eventchart.EventChart in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testSetItemsForDimensionFilters.

@Test
public 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.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with EventChart

use of org.hisp.dhis.eventchart.EventChart in project dhis2-core by dhis2.

the class AbstractWebApiTest method createTestObject.

@SuppressWarnings("unchecked")
protected T createTestObject(Class<?> clazz, char uniqueName, Object... params) {
    if (DataElementGroup.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroup(uniqueName);
    } else if (DataElementCategoryCombo.class.isAssignableFrom(clazz)) {
        return (T) createCategoryCombo(uniqueName, Arrays.copyOf(params, params.length, DataElementCategory[].class));
    } else if (DataElementCategoryOption.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOption(uniqueName);
    } else if (DataElement.class.isAssignableFrom(clazz)) {
        return (T) createDataElement(uniqueName);
    } else if (DataElementCategory.class.isAssignableFrom(clazz)) {
        return (T) createDataElementCategory(uniqueName, Arrays.copyOf(params, params.length, DataElementCategoryOption[].class));
    } else if (Program.class.isAssignableFrom(clazz)) {
        OrganisationUnit organisationUnitA = createOrganisationUnit(uniqueName);
        manager.save(organisationUnitA);
        return (T) createProgram(uniqueName, new HashSet<>(), organisationUnitA);
    } else if (DataElementOperand.class.isAssignableFrom(clazz)) {
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        DataElementCategoryOptionCombo coc = createCategoryOptionCombo(cc, co);
        manager.save(coc);
        return (T) new DataElementOperand(deA, coc);
    } else if (DataElementGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroupSet(uniqueName);
    } else if (DataElementCategoryOptionCombo.class.isAssignableFrom(clazz)) {
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        return (T) createCategoryOptionCombo(cc, co);
    } else if (CategoryOptionGroup.class.isAssignableFrom(clazz)) {
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(co);
        return (T) createCategoryOptionGroup(uniqueName, co);
    } else if (CategoryOptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOptionGroupSet(uniqueName);
    } else if (EventChart.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventChart ecA = new EventChart("evc" + uniqueName);
        ecA.setProgram(prA);
        ecA.setType(ChartType.COLUMN);
        return (T) ecA;
    } else if (EventReport.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventReport erA = new EventReport("er" + uniqueName);
        erA.setProgram(prA);
        return (T) erA;
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        return (T) new ProgramDataElementDimensionItem(prA, deA);
    } else if (ProgramIndicator.class.isAssignableFrom(clazz)) {
        Program program = (Program) createTestObject(Program.class, uniqueName);
        manager.save(program);
        Constant constantA = createConstant(uniqueName, 7.0);
        manager.save(constantA);
        String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
        return (T) createProgramIndicator(uniqueName, program, expressionA, null);
    } else if (Indicator.class.isAssignableFrom(clazz)) {
        IndicatorType indicatorType = createIndicatorType(uniqueName);
        manager.save(indicatorType);
        return (T) createIndicator(uniqueName, indicatorType);
    } else if (IndicatorGroup.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroup(uniqueName);
    } else if (IndicatorGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroupSet(uniqueName);
    } else if (IndicatorType.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorType(uniqueName);
    } else if (Legend.class.isAssignableFrom(clazz)) {
        return (T) createLegend(uniqueName, 0d, 10d);
    } else if (LegendSet.class.isAssignableFrom(clazz)) {
        return (T) createLegendSet(uniqueName);
    } else if (OrganisationUnit.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnit(uniqueName);
    } else if (OrganisationUnitGroup.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroup(uniqueName);
    } else if (OrganisationUnitGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroupSet(uniqueName);
    } else if (OrganisationUnitLevel.class.isAssignableFrom(clazz)) {
        return (T) new OrganisationUnitLevel(uniqueName, "OrgLevel" + uniqueName);
    } else if (Color.class.isAssignableFrom(clazz)) {
        Color color = new Color("#ff3200");
        color.setName("Color" + uniqueName);
        return (T) color;
    } else if (ColorSet.class.isAssignableFrom(clazz)) {
        ColorSet colorSet = new ColorSet();
        colorSet.setName("ColorSet" + uniqueName);
        return (T) colorSet;
    } else if (org.hisp.dhis.mapping.Map.class.isAssignableFrom(clazz)) {
        org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
        map.setName("Map" + uniqueName);
        map.setDisplayName("DisplayName" + uniqueName);
        map.setLatitude(952175.62553525);
        map.setLongitude(-1378543.6774686);
        return (T) map;
    } else if (ExternalMapLayer.class.isAssignableFrom(clazz)) {
        ExternalMapLayer externalMapLayer = new ExternalMapLayer("ExternalMapLayer" + uniqueName);
        externalMapLayer.setMapService(MapService.WMS);
        externalMapLayer.setUrl("testUrl");
        externalMapLayer.setImageFormat(ImageFormat.JPG);
        externalMapLayer.setMapLayerPosition(MapLayerPosition.BASEMAP);
        return (T) externalMapLayer;
    } else if (OptionGroup.class.isAssignableFrom(clazz)) {
        OptionGroup optionGroup = new OptionGroup("OptionGroup" + uniqueName);
        optionGroup.setShortName("Group" + uniqueName);
        return (T) optionGroup;
    } else if (OptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionGroupSet("OptionGroupSet" + uniqueName);
    } else if (Option.class.isAssignableFrom(clazz)) {
        return (T) new Option("Option" + uniqueName, "code" + uniqueName);
    } else if (OptionSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionSet("OptionSet" + uniqueName, ValueType.TEXT);
    } else if (ProgramTrackedEntityAttributeGroup.class.isAssignableFrom(clazz)) {
        ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup(uniqueName);
        ProgramTrackedEntityAttribute attr = createProgramTrackedEntityAttribute(uniqueName);
        group.addAttribute(attr);
        return (T) group;
    } else if (ProgramTrackedEntityAttribute.class.isAssignableFrom(clazz)) {
        return (T) createProgramTrackedEntityAttribute(uniqueName);
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        return (T) createProgramDataElement(uniqueName);
    }
    return null;
}
Also used : ColorSet(org.hisp.dhis.color.ColorSet) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ExternalMapLayer(org.hisp.dhis.mapping.ExternalMapLayer) Legend(org.hisp.dhis.legend.Legend) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Constant(org.hisp.dhis.constant.Constant) EventReport(org.hisp.dhis.eventreport.EventReport) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) IndicatorType(org.hisp.dhis.indicator.IndicatorType) OptionGroup(org.hisp.dhis.option.OptionGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) Color(org.hisp.dhis.color.Color) EventChart(org.hisp.dhis.eventchart.EventChart) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.option.Option) ProgramTrackedEntityAttributeGroup(org.hisp.dhis.program.ProgramTrackedEntityAttributeGroup) OptionSet(org.hisp.dhis.option.OptionSet) Map(java.util.Map) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 4 with EventChart

use of org.hisp.dhis.eventchart.EventChart in project dhis2-core by dhis2.

the class AnalyticalObjectEmbeddedDimensionUpgrader method executeInTransaction.

@Override
public void executeInTransaction() {
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> dataElementGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        DataElementGroupSetDimension dimension = new DataElementGroupSetDimension();
        dimension.setDimension((DataElementGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addDataElementGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> orgUnitGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        OrganisationUnitGroupSetDimension dimension = new OrganisationUnitGroupSetDimension();
        dimension.setDimension((OrganisationUnitGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addOrganisationUnitGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> categoryOptionGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        CategoryOptionGroupSetDimension dimension = new CategoryOptionGroupSetDimension();
        dimension.setDimension((CategoryOptionGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addCategoryOptionGroupSetDimension(dimension);
    };
    try {
        upgradeGrupSetDimensions("reporttable", "orgunitgroupset", "orgunitgroup", ReportTable.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "dataelementgroupset", "dataelementgroup", ReportTable.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "categoryoptiongroupset", "categoryoptiongroup", ReportTable.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "orgunitgroupset", "orgunitgroup", Chart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "dataelementgroupset", "dataelementgroup", Chart.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "categoryoptiongroupset", "categoryoptiongroup", Chart.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("eventreport", "orgunitgroupset", "orgunitgroup", EventReport.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("eventchart", "orgunitgroupset", "orgunitgroup", EventChart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
    } catch (Exception ex) {
        log.debug("Error during group set dimensions upgrade of favorite, probably because upgrade was already done", ex);
        return;
    }
}
Also used : AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) Autowired(org.springframework.beans.factory.annotation.Autowired) EventReport(org.hisp.dhis.eventreport.EventReport) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) EventChart(org.hisp.dhis.eventchart.EventChart) ReportTable(org.hisp.dhis.reporttable.ReportTable) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) BiConsumer(java.util.function.BiConsumer) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) Chart(org.hisp.dhis.chart.Chart) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) TransactionContextStartupRoutine(org.hisp.dhis.system.startup.TransactionContextStartupRoutine) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) List(java.util.List) DimensionalObject(org.hisp.dhis.common.DimensionalObject) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TextUtils(org.hisp.dhis.commons.util.TextUtils) Assert(org.springframework.util.Assert) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject)

Example 5 with EventChart

use of org.hisp.dhis.eventchart.EventChart in project dhis2-core by dhis2.

the class BaseAnalyticalObjectTest method testPopulateAnalyticalProperties.

@Test
public void testPopulateAnalyticalProperties() {
    TrackedEntityAttribute tea = new TrackedEntityAttribute();
    tea.setAutoFields();
    TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:10");
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.getColumnDimensions().add(tea.getUid());
    eventChart.getAttributeDimensions().add(tead);
    eventChart.populateAnalyticalProperties();
    assertEquals(1, eventChart.getColumns().size());
    DimensionalObject dim = eventChart.getColumns().get(0);
    assertNotNull(dim);
    assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
    assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
    assertEquals(tead.getFilter(), dim.getFilter());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) EventChart(org.hisp.dhis.eventchart.EventChart) Test(org.junit.Test)

Aggregations

EventChart (org.hisp.dhis.eventchart.EventChart)11 Test (org.junit.Test)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)5 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 CategoryOptionGroup (org.hisp.dhis.dataelement.CategoryOptionGroup)2 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)2 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 EventReport (org.hisp.dhis.eventreport.EventReport)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 BiConsumer (java.util.function.BiConsumer)1 Log (org.apache.commons.logging.Log)1