Search in sources :

Example 1 with TrackedEntityAttributeDimension

use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.

the class AnalyticalObjectObjectBundleHook method handleAttributeDimensions.

private void handleAttributeDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("attributeDimensions"))
        return;
    for (TrackedEntityAttributeDimension attributeDimension : analyticalObject.getAttributeDimensions()) {
        if (attributeDimension == null) {
            continue;
        }
        attributeDimension.setAttribute(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getAttribute()));
        attributeDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getLegendSet()));
        preheatService.connectReferences(attributeDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(attributeDimension);
    }
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)

Example 2 with TrackedEntityAttributeDimension

use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.

the class BaseAnalyticalObject method getTrackedEntityDimension.

private Optional<DimensionalObject> getTrackedEntityDimension(final String dimension) {
    // Tracked entity attribute
    final Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
    if (attributes.containsKey(dimension)) {
        final TrackedEntityAttributeDimension tead = attributes.get(dimension);
        if (tead != null) {
            final ValueType valueType = tead.getAttribute() != null ? tead.getAttribute().getValueType() : null;
            final OptionSet optionSet = tead.getAttribute() != null ? tead.getAttribute().getOptionSet() : null;
            return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), null, tead.getFilter(), valueType, optionSet));
        }
    }
    // Tracked entity data element
    final Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
    if (dataElements.containsKey(dimension)) {
        final TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
        if (tedd != null) {
            final ValueType valueType = tedd.getDataElement() != null ? tedd.getDataElement().getValueType() : null;
            final OptionSet optionSet = tedd.getDataElement() != null ? tedd.getDataElement().getOptionSet() : null;
            return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getProgramStage(), tedd.getFilter(), valueType, optionSet));
        }
    }
    // Tracked entity program indicator
    final Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
    if (programIndicators.containsKey(dimension)) {
        final TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), null, teid.getFilter()));
    }
    return Optional.empty();
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) OptionSet(org.hisp.dhis.option.OptionSet) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension)

Example 3 with TrackedEntityAttributeDimension

use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.

the class DefaultAnalyticalObjectImportHandler method handleAttributeDimensions.

private void handleAttributeDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("attributeDimensions"))
        return;
    for (TrackedEntityAttributeDimension attributeDimension : analyticalObject.getAttributeDimensions()) {
        if (attributeDimension == null) {
            continue;
        }
        attributeDimension.setAttribute(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getAttribute()));
        attributeDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getLegendSet()));
        preheatService.connectReferences(attributeDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(attributeDimension);
    }
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)

Example 4 with TrackedEntityAttributeDimension

use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetFromAnalyticalObjectB.

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

Example 5 with TrackedEntityAttributeDimension

use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension 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)

Aggregations

TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)12 EventChart (org.hisp.dhis.eventchart.EventChart)6 TrackedEntityDataElementDimension (org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension)6 Test (org.junit.jupiter.api.Test)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 TrackedEntityProgramIndicatorDimension (org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 ArrayList (java.util.ArrayList)2 CategoryDimension (org.hisp.dhis.category.CategoryDimension)2 DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 LegendSet (org.hisp.dhis.legend.LegendSet)2 OptionSet (org.hisp.dhis.option.OptionSet)2 List (java.util.List)1 CategoryOptionGroup (org.hisp.dhis.category.CategoryOptionGroup)1 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)1 CategoryOptionGroupSetDimension (org.hisp.dhis.category.CategoryOptionGroupSetDimension)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1