Search in sources :

Example 6 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo 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 7 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo 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 8 with CategoryCombo

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

the class AnalyticsUtilsTest method testGetByDataDimensionType.

@Test
void testGetByDataDimensionType() {
    Program prA = createProgram('A');
    DataElement deA = createDataElement('A', new CategoryCombo());
    DataElement deB = createDataElement('B', new CategoryCombo());
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
    ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
    List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
    assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
    assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 9 with CategoryCombo

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

the class AnalyticsUtilsTest method testGetCocNameMap.

@Test
void testGetCocNameMap() {
    CategoryCombo ccA = createCategoryCombo('A', new Category[0]);
    CategoryCombo ccB = createCategoryCombo('B', new Category[0]);
    CategoryOptionCombo cocA = createCategoryOptionCombo('A');
    CategoryOptionCombo cocB = createCategoryOptionCombo('B');
    ccA.getOptionCombos().add(cocA);
    ccB.getOptionCombos().add(cocB);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.setCategoryCombo(ccA);
    deB.setCategoryCombo(ccB);
    DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB));
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, String> map = AnalyticsUtils.getCocNameMap(params);
    assertEquals(map.get(cocA.getUid()), cocA.getName());
    assertEquals(map.get(cocB.getUid()), cocB.getName());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 10 with CategoryCombo

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

the class DataSetOrganisationUnitCategoryResourceTable method getPopulateTempTableContent.

/**
 * Iterate over data sets and associated organisation units. If data set has
 * a category combination and the organisation unit has category options,
 * find the intersection of the category option combinations linked to the
 * organisation unit through its category options, and the category option
 * combinations linked to the data set through its category combination. If
 * not, use the default category option combo.
 */
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (DataSet dataSet : objects) {
        CategoryCombo categoryCombo = dataSet.getCategoryCombo();
        for (OrganisationUnit orgUnit : dataSet.getSources()) {
            if (!categoryCombo.isDefault()) {
                if (orgUnit.hasCategoryOptions()) {
                    Set<CategoryOption> orgUnitOptions = orgUnit.getCategoryOptions();
                    for (CategoryOptionCombo optionCombo : categoryCombo.getOptionCombos()) {
                        Set<CategoryOption> optionComboOptions = optionCombo.getCategoryOptions();
                        if (orgUnitOptions.containsAll(optionComboOptions)) {
                            Date startDate = DateUtils.min(optionComboOptions.stream().map(co -> co.getStartDate()).collect(Collectors.toSet()));
                            Date endDate = DateUtils.max(optionComboOptions.stream().map(co -> co.getAdjustedEndDate(dataSet)).collect(Collectors.toSet()));
                            List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), optionCombo.getId(), startDate, endDate);
                            batchArgs.add(values.toArray());
                        }
                    }
                }
            } else {
                List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), defaultOptionCombo.getId(), null, null);
                batchArgs.add(values.toArray());
            }
        }
    }
    return Optional.of(batchArgs);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Aggregations

CategoryCombo (org.hisp.dhis.category.CategoryCombo)114 Test (org.junit.jupiter.api.Test)66 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)53 CategoryOption (org.hisp.dhis.category.CategoryOption)47 Category (org.hisp.dhis.category.Category)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)36 Program (org.hisp.dhis.program.Program)31 Event (org.hisp.dhis.tracker.domain.Event)27 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 Collectors (java.util.stream.Collectors)21 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 Collections (java.util.Collections)20 CategoryService (org.hisp.dhis.category.CategoryService)20 CodeGenerator (org.hisp.dhis.common.CodeGenerator)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)20 Sets (com.google.common.collect.Sets)19