Search in sources :

Example 6 with CategoryOption

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

the class CategoryOptionResolver method resolve.

@Override
public String resolve(String expression) {
    Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
    for (DimensionalItemId id : dimItemIds) {
        if (id.getItem() != null && id.getId1() != null && id.getId1().startsWith(CATEGORY_OPTION_PREFIX)) {
            CategoryOption co = categoryOptionStore.getByUid(id.getId1().replace(CATEGORY_OPTION_PREFIX, EMPTY_STRING));
            if (co != null) {
                List<String> resolved = co.getCategoryOptionCombos().stream().map(coc -> id.getItem().replace(id.getId1(), coc.getUid())).collect(Collectors.toList());
                expression = expression.replace(id.getItem(), LEFT_BRACKET + Joiner.on("+").join(resolved) + RIGHT_BRACKET);
            }
        }
    }
    return expression;
}
Also used : List(java.util.List) ExpressionService(org.hisp.dhis.expression.ExpressionService) CategoryOption(org.hisp.dhis.category.CategoryOption) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Service(org.springframework.stereotype.Service) Set(java.util.Set) INDICATOR_EXPRESSION(org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION) AllArgsConstructor(lombok.AllArgsConstructor) Collectors(java.util.stream.Collectors) CategoryOptionStore(org.hisp.dhis.category.CategoryOptionStore) Joiner(com.google.common.base.Joiner) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 7 with CategoryOption

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

the class ExpressionService2Test method setUp.

@BeforeEach
public void setUp() {
    target = new DefaultExpressionService(hibernateGenericStore, constantService, dimensionService, idObjectManager, statementBuilder, i18nManager, cacheProvider);
    categoryOptionA = new CategoryOption("Under 5");
    categoryOptionB = new CategoryOption("Over 5");
    categoryOptionC = new CategoryOption("Male");
    categoryOptionD = new CategoryOption("Female");
    categoryA = new Category("Age", DataDimensionType.DISAGGREGATION);
    categoryB = new Category("Gender", DataDimensionType.DISAGGREGATION);
    categoryA.getCategoryOptions().add(categoryOptionA);
    categoryA.getCategoryOptions().add(categoryOptionB);
    categoryB.getCategoryOptions().add(categoryOptionC);
    categoryB.getCategoryOptions().add(categoryOptionD);
    categoryCombo = new CategoryCombo("Age and gender", DataDimensionType.DISAGGREGATION);
    categoryCombo.getCategories().add(categoryA);
    categoryCombo.getCategories().add(categoryB);
    categoryCombo.generateOptionCombos();
    List<CategoryOptionCombo> optionCombos = Lists.newArrayList(categoryCombo.getOptionCombos());
    cocA = optionCombos.get(0);
    cocA.setUid(CodeGenerator.generateUid());
    cocB = optionCombos.get(1);
    cocB.setUid(CodeGenerator.generateUid());
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    deD = createDataElement('D');
    deE = createDataElement('E', categoryCombo);
    coc = rnd.nextObject(CategoryOptionCombo.class);
    coc.setName(DEFAULT_CATEGORY_COMBO_NAME);
    optionCombos.add(coc);
    opA = new DataElementOperand(deA, coc);
    opB = new DataElementOperand(deB, coc);
    opC = new DataElementOperand(deC, coc);
    opD = new DataElementOperand(deD, coc);
    opE = new DataElementOperand(deB, cocA);
    opF = new DataElementOperand(deA, cocA, cocB);
    period = createPeriod(getDate(2000, 1, 1), getDate(2000, 1, 31));
    pteaA = rnd.nextObject(ProgramTrackedEntityAttributeDimensionItem.class);
    pdeA = rnd.nextObject(ProgramDataElementDimensionItem.class);
    piA = rnd.nextObject(ProgramIndicator.class);
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B');
    unitC = createOrganisationUnit('C');
    constantA = rnd.nextObject(Constant.class);
    constantA.setName("ConstantA");
    constantA.setValue(2.0);
    constantB = rnd.nextObject(Constant.class);
    constantB.setName("ConstantB");
    constantB.setValue(5.0);
    groupA = createOrganisationUnitGroup('A');
    groupA.addOrganisationUnit(unitA);
    groupA.addOrganisationUnit(unitB);
    groupA.addOrganisationUnit(unitC);
    groupB = createOrganisationUnitGroup('B');
    groupB.addOrganisationUnit(unitB);
    DataSet dataSetA = createDataSet('A');
    dataSetA.setUid("a23dataSetA");
    dataSetA.addOrganisationUnit(unitA);
    reportingRate = new ReportingRate(dataSetA);
    expressionA = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
    expressionB = "#{" + deC.getUid() + SEPARATOR + coc.getUid() + "}-#{" + deD.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionC = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+#{" + deE.getUid() + "}-10";
    expressionD = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+" + SYMBOL_DAYS;
    expressionE = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*C{" + constantA.getUid() + "}";
    expressionF = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionG = expressionF + "+#{" + deB.getUid() + "}-#{" + deC.getUid() + "}";
    expressionH = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*OUG{" + groupA.getUid() + "}";
    expressionI = "#{" + opA.getDimensionItem() + "}*" + "#{" + deB.getDimensionItem() + "}+" + "C{" + constantA.getUid() + "}+5-" + "D{" + pdeA.getDimensionItem() + "}+" + "A{" + pteaA.getDimensionItem() + "}-10+" + "I{" + piA.getDimensionItem() + "}";
    expressionJ = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
    expressionK = "1.5*avg(" + expressionJ + ")";
    expressionL = expressionA + "+avg(" + expressionJ + ")+1.5*stddev(" + expressionJ + ")+" + expressionB;
    expressionM = "#{" + deA.getUid() + SEPARATOR + SYMBOL_WILDCARD + "}-#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionN = "#{" + deA.getUid() + SEPARATOR + cocA.getUid() + SEPARATOR + cocB.getUid() + "}-#{" + deB.getUid() + SEPARATOR + cocA.getUid() + "}";
    expressionO = "#{" + opA.getDimensionItem() + "}+sum(#{" + opB.getDimensionItem() + "})";
    expressionP = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionR = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}" + " + R{" + reportingRate.getUid() + ".REPORTING_RATE}";
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) Constant(org.hisp.dhis.constant.Constant) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with CategoryOption

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

the class DataApprovalStoreUserTest method testGetDataApprovalStatuses.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testGetDataApprovalStatuses() {
    CategoryOption catOptionA = new CategoryOption("CategoryOptionA");
    catOptionA.addOrganisationUnit(orgUnitB);
    categoryService.addCategoryOption(catOptionA);
    org.hisp.dhis.category.Category catA = createCategory('A', catOptionA);
    categoryService.addCategory(catA);
    CategoryCombo catComboA = createCategoryCombo('A', catA);
    categoryService.addCategoryCombo(catComboA);
    CategoryOptionCombo catOptionComboA = createCategoryOptionCombo(catComboA, catOptionA);
    categoryService.addCategoryOptionCombo(catOptionComboA);
    List<DataApprovalStatus> statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitA), orgUnitA.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
    assertEquals(1, statuses.size());
    DataApprovalStatus status = statuses.get(0);
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, status.getState());
    assertEquals(orgUnitA.getUid(), status.getOrganisationUnitUid());
    assertEquals(orgUnitA.getName(), status.getOrganisationUnitName());
    assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
    statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitB), orgUnitB.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
    assertEquals(1, statuses.size());
    status = statuses.get(0);
    assertEquals(DataApprovalState.UNAPPROVED_WAITING, status.getState());
    assertEquals(orgUnitB.getUid(), status.getOrganisationUnitUid());
    assertEquals(orgUnitB.getName(), status.getOrganisationUnitName());
    assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
    statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitC), orgUnitC.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
    assertEquals(1, statuses.size());
    status = statuses.get(0);
    assertEquals(DataApprovalState.UNAPPROVED_READY, status.getState());
    assertEquals(orgUnitC.getUid(), status.getOrganisationUnitUid());
    assertEquals(orgUnitC.getName(), status.getOrganisationUnitName());
    assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
    statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitD), orgUnitD.getHierarchyLevel(), catComboA, null, null, null);
    assertEquals(0, statuses.size());
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 9 with CategoryOption

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

the class DefaultAnalyticalObjectImportHandler method handleCategoryDimensions.

private void handleCategoryDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("categoryDimensions"))
        return;
    for (CategoryDimension categoryDimension : analyticalObject.getCategoryDimensions()) {
        if (categoryDimension == null) {
            continue;
        }
        categoryDimension.setDimension(bundle.getPreheat().get(bundle.getPreheatIdentifier(), categoryDimension.getDimension()));
        List<CategoryOption> categoryOptions = new ArrayList<>(categoryDimension.getItems());
        categoryDimension.getItems().clear();
        categoryOptions.forEach(co -> {
            CategoryOption categoryOption = bundle.getPreheat().get(bundle.getPreheatIdentifier(), co);
            if (categoryOption != null)
                categoryDimension.getItems().add(categoryOption);
        });
        preheatService.connectReferences(categoryDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(categoryDimension);
    }
}
Also used : CategoryDimension(org.hisp.dhis.category.CategoryDimension) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 10 with CategoryOption

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

the class CategoryOptionResolverTest method setUp.

@BeforeEach
public void setUp() {
    uid1 = CodeGenerator.generateUid();
    uid2 = CodeGenerator.generateUid();
    uid3 = CodeGenerator.generateUid();
    CategoryOption categoryOption = createCategoryOption('A');
    coc1 = createCategoryOptionCombo('X');
    categoryOption.addCategoryOptionCombo(coc1);
    coc2 = createCategoryOptionCombo('Y');
    categoryOption.addCategoryOptionCombo(coc2);
    coc3 = createCategoryOptionCombo('Z');
    categoryOption.addCategoryOptionCombo(coc3);
    resolver = new CategoryOptionResolver(expressionService, categoryOptionStore);
    when(categoryOptionStore.getByUid(anyString())).thenReturn(categoryOption);
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) DhisConvenienceTest.createCategoryOption(org.hisp.dhis.DhisConvenienceTest.createCategoryOption) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CategoryOption (org.hisp.dhis.category.CategoryOption)87 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)47 CategoryCombo (org.hisp.dhis.category.CategoryCombo)38 Category (org.hisp.dhis.category.Category)34 Test (org.junit.jupiter.api.Test)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)26 Program (org.hisp.dhis.program.Program)19 ArrayList (java.util.ArrayList)18 Event (org.hisp.dhis.tracker.domain.Event)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 DataElement (org.hisp.dhis.dataelement.DataElement)13 Collections (java.util.Collections)12 DataSet (org.hisp.dhis.dataset.DataSet)12 CodeGenerator (org.hisp.dhis.common.CodeGenerator)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)11 CategoryService (org.hisp.dhis.category.CategoryService)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10