Search in sources :

Example 1 with TrackedEntityDataElementDimension

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

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

the class AnalyticalObjectObjectBundleHook method handleDataElementDimensions.

private void handleDataElementDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("dataElementDimensions"))
        return;
    for (TrackedEntityDataElementDimension dataElementDimension : analyticalObject.getDataElementDimensions()) {
        if (dataElementDimension == null) {
            continue;
        }
        dataElementDimension.setDataElement(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataElementDimension.getDataElement()));
        dataElementDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataElementDimension.getLegendSet()));
        preheatService.connectReferences(dataElementDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(dataElementDimension);
    }
}
Also used : TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension)

Example 3 with TrackedEntityDataElementDimension

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

the class BaseAnalyticalObject method getDimensionalObject.

/**
     * Assembles a list of DimensionalObjects based on the concrete objects in
     * this BaseAnalyticalObject.
     * <p>
     * Merges fixed and relative periods into the pe dimension, where the
     * RelativePeriods object is represented by enums (e.g. LAST_MONTH). Merges
     * fixed and user organisation units into the ou dimension, where user
     * organisation units properties are represented by enums (e.g. USER_ORG_UNIT).
     * <p>
     * This method is useful when serializing the AnalyticalObject.
     *
     * @param dimension the dimension identifier.
     * @return a list of DimensionalObjects.
     */
protected DimensionalObject getDimensionalObject(String dimension) {
    if (DATA_X_DIM_ID.equals(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.DATA_X, getDataDimensionNameableObjects());
    } else if (PERIOD_DIM_ID.equals(dimension)) {
        List<Period> periodList = new ArrayList<>(periods);
        if (hasRelativePeriods()) {
            List<RelativePeriodEnum> list = relatives.getRelativePeriodEnums();
            for (RelativePeriodEnum periodEnum : list) {
                periodList.add(new ConfigurablePeriod(periodEnum.toString()));
            }
        }
        Collections.sort(periodList, new AscendingPeriodComparator());
        return new BaseDimensionalObject(dimension, DimensionType.PERIOD, periodList);
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
        List<DimensionalItemObject> ouList = new ArrayList<>();
        ouList.addAll(organisationUnits);
        ouList.addAll(transientOrganisationUnits);
        if (userOrganisationUnit) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT));
        }
        if (userOrganisationUnitChildren) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_CHILDREN));
        }
        if (userOrganisationUnitGrandChildren) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_GRANDCHILDREN));
        }
        if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {
            for (Integer level : organisationUnitLevels) {
                String id = KEY_LEVEL + level;
                ouList.add(new BaseDimensionalItemObject(id));
            }
        }
        if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty()) {
            for (OrganisationUnitGroup group : itemOrganisationUnitGroups) {
                String id = KEY_ORGUNIT_GROUP + group.getUid();
                ouList.add(new BaseDimensionalItemObject(id));
            }
        }
        return new BaseDimensionalObject(dimension, DimensionType.ORGANISATION_UNIT, ouList);
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<>());
    } else if (DATA_COLLAPSED_DIM_ID.contains(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.DATA_COLLAPSED, new ArrayList<>());
    } else if (STATIC_DIMS.contains(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.STATIC, new ArrayList<>());
    } else {
        // Embedded dimensions
        Optional<DimensionalObject> object = Optional.empty();
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        // Tracked entity attribute
        Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
        if (attributes.containsKey(dimension)) {
            TrackedEntityAttributeDimension tead = attributes.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter());
        }
        // Tracked entity data element
        Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
        if (dataElements.containsKey(dimension)) {
            TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter());
        }
        // Tracked entity program indicator
        Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
        if (programIndicators.containsKey(dimension)) {
            TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter());
        }
    }
    throw new IllegalArgumentException("Not a valid dimension: " + dimension);
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) Optional(java.util.Optional) ArrayList(java.util.ArrayList) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) AscendingPeriodComparator(org.hisp.dhis.period.comparator.AscendingPeriodComparator) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ConfigurablePeriod(org.hisp.dhis.period.ConfigurablePeriod) RelativePeriodEnum(org.hisp.dhis.period.RelativePeriodEnum) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with TrackedEntityDataElementDimension

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

the class BaseAnalyticalObject method getDimensionalObject.

/**
     * Assembles a DimensionalObject based on the persisted properties of this
     * AnalyticalObject. Collapses indicators, data elements, data element
     * operands and data sets into the dx dimension.
     * <p>
     * Collapses fixed and relative periods into the pe dimension. Collapses
     * fixed and user organisation units into the ou dimension.
     *
     * @param dimension    the dimension identifier.
     * @param date         the date used for generating relative periods.
     * @param user         the current user.
     * @param dynamicNames whether to use dynamic or static names.
     * @param format       the I18nFormat.
     * @return a DimensionalObject.
     */
protected DimensionalObject getDimensionalObject(String dimension, Date date, User user, boolean dynamicNames, List<OrganisationUnit> organisationUnitsAtLevel, List<OrganisationUnit> organisationUnitsInGroups, I18nFormat format) {
    List<DimensionalItemObject> items = new ArrayList<>();
    DimensionType type = null;
    if (DATA_X_DIM_ID.equals(dimension)) {
        items.addAll(getDataDimensionNameableObjects());
        type = DimensionType.DATA_X;
    } else if (PERIOD_DIM_ID.equals(dimension)) {
        setPeriodNames(periods, dynamicNames, format);
        items.addAll(periods);
        if (hasRelativePeriods()) {
            items.addAll(relatives.getRelativePeriods(date, format, dynamicNames));
        }
        type = DimensionType.PERIOD;
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
        items.addAll(organisationUnits);
        items.addAll(transientOrganisationUnits);
        if (userOrganisationUnit && user != null && user.hasOrganisationUnit()) {
            items.addAll(user.getOrganisationUnits());
        }
        if (userOrganisationUnitChildren && user != null && user.hasOrganisationUnit()) {
            user.getOrganisationUnits().forEach(ou -> items.addAll(ou.getSortedChildren()));
        }
        if (userOrganisationUnitGrandChildren && user != null && user.hasOrganisationUnit()) {
            user.getOrganisationUnits().forEach(ou -> items.addAll(ou.getSortedGrandChildren()));
        }
        if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty() && organisationUnitsAtLevel != null) {
            // Must be set externally
            items.addAll(organisationUnitsAtLevel);
        }
        if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty() && organisationUnitsInGroups != null) {
            // Must be set externally
            items.addAll(organisationUnitsInGroups);
        }
        type = DimensionType.ORGANISATION_UNIT;
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
        items.addAll(transientCategoryOptionCombos);
        type = DimensionType.CATEGORY_OPTION_COMBO;
    } else if (STATIC_DIMS.contains(dimension)) {
        type = DimensionType.STATIC;
    } else {
        // Embedded dimensions
        Optional<DimensionalObject> object = Optional.empty();
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.DATA_ELEMENT_GROUP_SET;
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.ORGANISATION_UNIT_GROUP_SET;
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.CATEGORY;
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.CATEGORY_OPTION_GROUP_SET;
        }
        // Tracked entity attribute
        Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
        if (attributes.containsKey(dimension)) {
            TrackedEntityAttributeDimension tead = attributes.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter());
        }
        // Tracked entity data element
        Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
        if (dataElements.containsKey(dimension)) {
            TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter());
        }
        // Tracked entity program indicator
        Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
        if (programIndicators.containsKey(dimension)) {
            TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter());
        }
    }
    IdentifiableObjectUtils.removeDuplicates(items);
    return new BaseDimensionalObject(dimension, type, items);
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) ArrayList(java.util.ArrayList) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 5 with TrackedEntityDataElementDimension

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

the class EventDataQueryServiceTest method testGetFromAnalyticalObjectC.

@Test
public void testGetFromAnalyticalObjectC() {
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.setProgram(prA);
    eventChart.getColumnDimensions().add(deA.getUid());
    eventChart.getColumnDimensions().add(atA.getUid());
    eventChart.getRowDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
    eventChart.getFilterDimensions().add(DimensionalObject.PERIOD_DIM_ID);
    eventChart.getDataElementDimensions().add(new TrackedEntityDataElementDimension(deA, null, "GT:2000"));
    eventChart.getAttributeDimensions().add(new TrackedEntityAttributeDimension(atA, null, "LE:5"));
    eventChart.getPeriods().add(peA);
    eventChart.getPeriods().add(peB);
    eventChart.getOrganisationUnits().add(ouA);
    EventQueryParams params = dataQueryService.getFromAnalyticalObject(eventChart);
    assertNotNull(params);
    assertEquals(2, params.getItems().size());
    assertEquals(1, params.getOrganisationUnits().size());
    assertEquals(2, params.getFilterPeriods().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)

Aggregations

TrackedEntityDataElementDimension (org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension)7 TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)6 ArrayList (java.util.ArrayList)4 TrackedEntityProgramIndicatorDimension (org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension)4 List (java.util.List)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)2 DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 CategoryDimension (org.hisp.dhis.dataelement.CategoryDimension)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 Period (org.hisp.dhis.period.Period)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1