Search in sources :

Example 91 with CategoryCombo

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

the class DataSetDeletionHandler method deleteCategoryCombo.

private void deleteCategoryCombo(CategoryCombo categoryCombo) {
    CategoryCombo defaultCategoryCombo = categoryService.getCategoryComboByName(DEFAULT_CATEGORY_COMBO_NAME);
    Collection<DataSet> dataSets = idObjectManager.getAllNoAcl(DataSet.class);
    for (DataSet dataSet : dataSets) {
        if (dataSet != null && categoryCombo.equals(dataSet.getCategoryCombo())) {
            dataSet.setCategoryCombo(defaultCategoryCombo);
            idObjectManager.updateNoAcl(dataSet);
        }
    }
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo)

Example 92 with CategoryCombo

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

the class DefaultCategoryService method generateDefaultDimension.

@Override
@Transactional
public void generateDefaultDimension() {
    // ---------------------------------------------------------------------
    // CategoryOption
    // ---------------------------------------------------------------------
    CategoryOption categoryOption = new CategoryOption(CategoryOption.DEFAULT_NAME);
    categoryOption.setUid("xYerKDKCefk");
    categoryOption.setCode("default");
    addCategoryOption(categoryOption);
    categoryOption.setPublicAccess(AccessStringHelper.CATEGORY_OPTION_DEFAULT);
    updateCategoryOption(categoryOption);
    // ---------------------------------------------------------------------
    // Category
    // ---------------------------------------------------------------------
    Category category = new Category(Category.DEFAULT_NAME, DataDimensionType.DISAGGREGATION);
    category.setUid("GLevLNI9wkl");
    category.setCode("default");
    category.setShortName("default");
    category.setDataDimension(false);
    category.addCategoryOption(categoryOption);
    addCategory(category);
    category.setPublicAccess(AccessStringHelper.CATEGORY_NO_DATA_SHARING_DEFAULT);
    updateCategory(category);
    // ---------------------------------------------------------------------
    // CategoryCombo
    // ---------------------------------------------------------------------
    CategoryCombo categoryCombo = new CategoryCombo(CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME, DataDimensionType.DISAGGREGATION);
    categoryCombo.setUid("bjDvmb4bfuf");
    categoryCombo.setCode("default");
    categoryCombo.setDataDimensionType(DataDimensionType.DISAGGREGATION);
    categoryCombo.addCategory(category);
    addCategoryCombo(categoryCombo);
    categoryCombo.setPublicAccess(AccessStringHelper.CATEGORY_NO_DATA_SHARING_DEFAULT);
    updateCategoryCombo(categoryCombo);
    // ---------------------------------------------------------------------
    // CategoryOptionCombo
    // ---------------------------------------------------------------------
    CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
    categoryOptionCombo.setUid("HllvX50cXC0");
    categoryOptionCombo.setCode("default");
    categoryOptionCombo.setCategoryCombo(categoryCombo);
    categoryOptionCombo.addCategoryOption(categoryOption);
    addCategoryOptionCombo(categoryOptionCombo);
    categoryOptionCombo.setPublicAccess(AccessStringHelper.CATEGORY_NO_DATA_SHARING_DEFAULT);
    updateCategoryOptionCombo(categoryOptionCombo);
    Set<CategoryOptionCombo> categoryOptionCombos = new HashSet<>();
    categoryOptionCombos.add(categoryOptionCombo);
    categoryCombo.setOptionCombos(categoryOptionCombos);
    updateCategoryCombo(categoryCombo);
    categoryOption.setCategoryOptionCombos(categoryOptionCombos);
    updateCategoryOption(categoryOption);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 93 with CategoryCombo

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

the class DefaultCategoryService method getOperands.

@Override
@Transactional(readOnly = true)
public List<DataElementOperand> getOperands(Collection<DataElement> dataElements, boolean includeTotals) {
    List<DataElementOperand> operands = Lists.newArrayList();
    for (DataElement dataElement : dataElements) {
        Set<CategoryCombo> categoryCombos = dataElement.getCategoryCombos();
        boolean anyIsDefault = categoryCombos.stream().anyMatch(cc -> cc.isDefault());
        if (includeTotals && !anyIsDefault) {
            operands.add(new DataElementOperand(dataElement));
        }
        for (CategoryCombo categoryCombo : categoryCombos) {
            operands.addAll(getOperands(dataElement, categoryCombo));
        }
    }
    return operands;
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 94 with CategoryCombo

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

the class PredictionServiceTest method testPredictMultipleAttributeOptionCombos.

@Test
void testPredictMultipleAttributeOptionCombos() {
    CategoryOption optionJ = new CategoryOption("CategoryOptionJ");
    CategoryOption optionK = new CategoryOption("CategoryOptionK");
    CategoryOption optionL = new CategoryOption("CategoryOptionL");
    categoryService.addCategoryOption(optionJ);
    categoryService.addCategoryOption(optionK);
    categoryService.addCategoryOption(optionL);
    Category categoryJ = createCategory('J', optionJ, optionK);
    Category categoryL = createCategory('L', optionL);
    categoryJ.setDataDimension(true);
    categoryL.setDataDimension(true);
    categoryService.addCategory(categoryJ);
    categoryService.addCategory(categoryL);
    CategoryCombo categoryComboJL = createCategoryCombo('A', categoryJ, categoryL);
    categoryService.addCategoryCombo(categoryComboJL);
    CategoryOptionCombo optionComboJL = createCategoryOptionCombo(categoryComboJL, optionJ, optionK);
    CategoryOptionCombo optionComboKL = createCategoryOptionCombo(categoryComboJL, optionK, optionL);
    categoryService.addCategoryOptionCombo(optionComboJL);
    categoryService.addCategoryOptionCombo(optionComboKL);
    useDataValue(dataElementA, makeMonth(2011, 6), sourceA, optionComboJL, 1);
    useDataValue(dataElementB, makeMonth(2011, 6), sourceA, optionComboJL, 2);
    useDataValue(dataElementA, makeMonth(2011, 6), sourceA, optionComboKL, 3);
    useDataValue(dataElementB, makeMonth(2011, 6), sourceA, optionComboKL, 4);
    dataValueBatchHandler.flush();
    Predictor p = createPredictor(dataElementX, defaultCombo, "A", expressionG, null, periodTypeMonthly, orgUnitLevel1, 1, 0, 0);
    predictionService.predict(p, monthStart(2011, 7), monthStart(2011, 8), summary);
    assertEquals("Pred 1 Ins 2 Upd 0 Del 0 Unch 0", shortSummary(summary));
    assertEquals("3.0", getDataValue(dataElementX, defaultCombo, optionComboJL, sourceA, makeMonth(2011, 7)));
    assertEquals("7.0", getDataValue(dataElementX, defaultCombo, optionComboKL, sourceA, makeMonth(2011, 7)));
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 95 with CategoryCombo

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

the class ValidationServiceTest method testValidateWithAttributeOptions.

@Test
void testValidateWithAttributeOptions() {
    CategoryOption optionA = new CategoryOption("CategoryOptionA");
    CategoryOption optionB = new CategoryOption("CategoryOptionB");
    CategoryOption optionC = new CategoryOption("CategoryOptionC");
    categoryService.addCategoryOption(optionA);
    categoryService.addCategoryOption(optionB);
    categoryService.addCategoryOption(optionC);
    Category categoryA = createCategory('A', optionA, optionB);
    Category categoryB = createCategory('B', optionC);
    categoryA.setDataDimension(true);
    categoryB.setDataDimension(true);
    categoryService.addCategory(categoryA);
    categoryService.addCategory(categoryB);
    CategoryCombo categoryComboAB = createCategoryCombo('A', categoryA, categoryB);
    categoryService.addCategoryCombo(categoryComboAB);
    CategoryOptionCombo optionComboAC = createCategoryOptionCombo(categoryComboAB, optionA, optionC);
    CategoryOptionCombo optionComboBC = createCategoryOptionCombo(categoryComboAB, optionB, optionC);
    categoryService.addCategoryOptionCombo(optionComboAC);
    categoryService.addCategoryOptionCombo(optionComboBC);
    useDataValue(dataElementA, periodA, sourceA, "4", optionCombo, optionComboAC);
    useDataValue(dataElementB, periodA, sourceA, "3", optionCombo, optionComboAC);
    useDataValue(dataElementA, periodA, sourceA, "2", optionCombo, optionComboBC);
    useDataValue(dataElementB, periodA, sourceA, "1", optionCombo, optionComboBC);
    // deA + deB < deB * 2
    validationRuleService.saveValidationRule(ruleD);
    // deA + deB = deB * 2
    validationRuleService.saveValidationRule(ruleX);
    // 
    // optionComboAC
    // 
    Collection<ValidationResult> results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).withAttributeOptionCombo(optionComboAC).build());
    Collection<ValidationResult> reference = new HashSet<>();
    reference.add(new ValidationResult(ruleD, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleX, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    assertResultsEquals(reference, results);
    // 
    // All optionCombos
    // 
    results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).build());
    reference = new HashSet<>();
    reference.add(new ValidationResult(ruleD, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleX, periodA, sourceA, optionComboAC, 7.0, 6.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleD, periodA, sourceA, optionComboBC, 3.0, 2.0, dayInPeriodA));
    reference.add(new ValidationResult(ruleX, periodA, sourceA, optionComboBC, 3.0, 2.0, dayInPeriodA));
    assertResultsEquals(reference, results);
    // 
    // Default optionCombo
    // 
    results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).withAttributeOptionCombo(optionCombo).build());
    assertResultsEmpty(results);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

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