Search in sources :

Example 36 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class User method getDimensionConstraints.

/**
 * Returns the dimensions to use as constrains (filters) in data analytics
 * aggregation.
 */
public Set<DimensionalObject> getDimensionConstraints() {
    Set<DimensionalObject> constraints = new HashSet<>();
    for (CategoryOptionGroupSet cogs : cogsDimensionConstraints) {
        cogs.setDimensionType(DimensionType.CATEGORY_OPTION_GROUP_SET);
        constraints.add(cogs);
    }
    for (Category cat : catDimensionConstraints) {
        cat.setDimensionType(DimensionType.CATEGORY);
        constraints.add(cat);
    }
    return constraints;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject) HashSet(java.util.HashSet)

Example 37 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultAnalyticsDimensionService method getRecommendedDimensions.

@Override
public List<DimensionalObject> getRecommendedDimensions(DataQueryParams params) {
    User user = currentUserService.getCurrentUser();
    Set<DimensionalObject> dimensions = new HashSet<>();
    if (!params.getDataElements().isEmpty()) {
        dimensions.addAll(params.getDataElements().stream().map(de -> ((DataElement) de).getCategoryCombos()).flatMap(cc -> cc.stream()).map(cc -> cc.getCategories()).flatMap(c -> c.stream()).filter(Category::isDataDimension).collect(Collectors.toSet()));
        dimensions.addAll(params.getDataElements().stream().map(de -> ((DataElement) de).getDataSets()).flatMap(ds -> ds.stream()).map(ds -> ds.getCategoryCombo().getCategories()).flatMap(c -> c.stream()).filter(Category::isDataDimension).collect(Collectors.toSet()));
    }
    dimensions.addAll(idObjectManager.getDataDimensions(OrganisationUnitGroupSet.class));
    return dimensions.stream().filter(d -> aclService.canDataOrMetadataRead(user, d)).sorted().collect(Collectors.toList());
}
Also used : DataQueryService(org.hisp.dhis.analytics.DataQueryService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Category(org.hisp.dhis.category.Category) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Service(org.springframework.stereotype.Service) AclService(org.hisp.dhis.security.acl.AclService) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) User(org.hisp.dhis.user.User) User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject) HashSet(java.util.HashSet)

Example 38 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class AnalyticsDimensionServiceTest method testGetRecommendedDimensions.

@Test
void testGetRecommendedDimensions() {
    CategoryOption coA = createCategoryOption('A');
    CategoryOption coB = createCategoryOption('B');
    CategoryOption coC = createCategoryOption('C');
    CategoryOption coD = createCategoryOption('D');
    Category caA = createCategory('A', coA);
    Category caB = createCategory('B', coB);
    Category caC = createCategory('C', coC);
    Category caD = createCategory('D', coD);
    caD.setDataDimension(false);
    CategoryCombo ccA = createCategoryCombo('A', caA, caB);
    CategoryCombo ccB = createCategoryCombo('A', caC, caD);
    DataSet dsA = createDataSet('A');
    dsA.setCategoryCombo(ccB);
    DataElement deA = createDataElement('A', ccA);
    DataElement deB = createDataElement('B', ccA);
    dsA.addDataSetElement(deB);
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA, deB)).build();
    List<DimensionalObject> dimensons = dimensionService.getRecommendedDimensions(params);
    assertEquals(3, dimensons.size());
    assertTrue(dimensons.contains(caA));
    assertTrue(dimensons.contains(caB));
    assertTrue(dimensons.contains(caC));
    params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA)).build();
    dimensons = dimensionService.getRecommendedDimensions(params);
    assertEquals(2, dimensons.size());
    assertTrue(dimensons.contains(caA));
    assertTrue(dimensons.contains(caB));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) CategoryOption(org.hisp.dhis.category.CategoryOption) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 39 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultDimensionService method getDimensionType.

@Override
public DimensionType getDimensionType(String uid) {
    Category cat = idObjectManager.get(Category.class, uid);
    if (cat != null) {
        return DimensionType.CATEGORY;
    }
    DataElementGroupSet degs = idObjectManager.get(DataElementGroupSet.class, uid);
    if (degs != null) {
        return DimensionType.DATA_ELEMENT_GROUP_SET;
    }
    OrganisationUnitGroupSet ougs = idObjectManager.get(OrganisationUnitGroupSet.class, uid);
    if (ougs != null) {
        return DimensionType.ORGANISATION_UNIT_GROUP_SET;
    }
    CategoryOptionGroupSet cogs = idObjectManager.get(CategoryOptionGroupSet.class, uid);
    if (cogs != null) {
        return DimensionType.CATEGORY_OPTION_GROUP_SET;
    }
    TrackedEntityAttribute tea = idObjectManager.get(TrackedEntityAttribute.class, uid);
    if (tea != null) {
        return DimensionType.PROGRAM_ATTRIBUTE;
    }
    DataElement pde = idObjectManager.get(DataElement.class, uid);
    if (pde != null && DataElementDomain.TRACKER.equals(pde.getDomainType())) {
        return DimensionType.PROGRAM_DATA_ELEMENT;
    }
    ProgramIndicator pin = idObjectManager.get(ProgramIndicator.class, uid);
    if (pin != null) {
        return DimensionType.PROGRAM_INDICATOR;
    }
    final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
    dimObjectTypeMap.put(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X);
    dimObjectTypeMap.put(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD);
    dimObjectTypeMap.put(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT);
    return dimObjectTypeMap.get(uid);
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionType(org.hisp.dhis.common.DimensionType) Category(org.hisp.dhis.category.Category) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) HashMap(java.util.HashMap) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 40 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultDimensionService method getAllDimensions.

@Override
public List<DimensionalObject> getAllDimensions() {
    Collection<Category> dcs = idObjectManager.getDataDimensions(Category.class);
    Collection<CategoryOptionGroupSet> cogs = idObjectManager.getDataDimensions(CategoryOptionGroupSet.class);
    Collection<DataElementGroupSet> degs = idObjectManager.getDataDimensions(DataElementGroupSet.class);
    Collection<OrganisationUnitGroupSet> ougs = idObjectManager.getDataDimensions(OrganisationUnitGroupSet.class);
    final List<DimensionalObject> dimensions = new ArrayList<>();
    dimensions.addAll(dcs);
    dimensions.addAll(cogs);
    dimensions.addAll(degs);
    dimensions.addAll(ougs);
    User user = currentUserService.getCurrentUser();
    return getCanReadObjects(user, dimensions);
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) Category(org.hisp.dhis.category.Category) User(org.hisp.dhis.user.User) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject)

Aggregations

Category (org.hisp.dhis.category.Category)61 CategoryOption (org.hisp.dhis.category.CategoryOption)25 CategoryCombo (org.hisp.dhis.category.CategoryCombo)22 Test (org.junit.jupiter.api.Test)21 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)13 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)13 ArrayList (java.util.ArrayList)12 User (org.hisp.dhis.user.User)12 DataElement (org.hisp.dhis.dataelement.DataElement)11 HashSet (java.util.HashSet)8 DataSet (org.hisp.dhis.dataset.DataSet)8 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)8 HashMap (java.util.HashMap)7 Date (java.util.Date)5 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 List (java.util.List)4 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 Attribute (org.hisp.dhis.attribute.Attribute)4