Search in sources :

Example 26 with CategoryCombo

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

the class ProgramDeletionHandler method deleteCategoryCombo.

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

Example 27 with CategoryCombo

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

the class ProgramStageSectionIntegrationTest method setUpTest.

@Override
public void setUpTest() {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    sectionA = createProgramStageSection('A', 1);
    programStageSectionService.saveProgramStageSection(sectionA);
    CategoryCombo categoryCombo = createCategoryCombo('A');
    categoryService.addCategoryCombo(categoryCombo);
    DataElement dataElementA = createDataElement('A', categoryCombo);
    dataElementService.addDataElement(dataElementA);
    programStageDataElementA = createProgramStageDataElement(stageA, dataElementA, 1);
    program = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(program);
    stageA = new ProgramStage("A", program);
    stageA.setUid("UID-A");
    stageA.setProgramStageSections(Sets.newHashSet(sectionA));
    stageA.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) HashSet(java.util.HashSet)

Example 28 with CategoryCombo

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

the class ProgramMapperTest method testCategoryComboIsSetForDefaultCategoryCombos.

@Test
void testCategoryComboIsSetForDefaultCategoryCombos() {
    Program program = new Program();
    CategoryCombo cc = createCategoryCombo('A');
    cc.setName(CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
    assertTrue(cc.isDefault(), "tests rely on this CC being the default one");
    program.setCategoryCombo(cc);
    Program mappedProgram = ProgramMapper.INSTANCE.map(program);
    assertEquals(cc, mappedProgram.getCategoryCombo());
}
Also used : Program(org.hisp.dhis.program.Program) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 29 with CategoryCombo

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

the class GetMetaDataAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(CategoryCombo.class), identifiableObjectManager.getLastUpdated(Category.class), identifiableObjectManager.getLastUpdated(CategoryOption.class)));
    String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
    if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
        return SUCCESS;
    }
    if (user != null && user.getOrganisationUnits().isEmpty()) {
        emptyOrganisationUnits = true;
        return SUCCESS;
    }
    significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
    dataElements = dataElementService.getDataElementsWithDataSets();
    for (DataElement dataElement : dataElements) {
        if (dataElement != null && dataElement.getOptionSet() != null) {
            dataElementsWithOptionSet.add(dataElement);
        }
    }
    indicators = indicatorService.getIndicatorsWithDataSets();
    expressionService.substituteIndicatorExpressions(indicators);
    dataSets = dataSetService.getUserDataWrite(user);
    Set<CategoryCombo> categoryComboSet = new HashSet<>();
    Set<Category> categorySet = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        if (dataSet.getCategoryCombo() != null) {
            categoryComboSet.add(dataSet.getCategoryCombo());
        }
    }
    for (CategoryCombo categoryCombo : categoryComboSet) {
        if (categoryCombo.getCategories() != null) {
            categorySet.addAll(categoryCombo.getCategories());
        }
    }
    categoryCombos = new ArrayList<>(categoryComboSet);
    categories = new ArrayList<>(categorySet);
    for (Category category : categories) {
        List<CategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataWriteCategoryOptions(category, user));
        Collections.sort(categoryOptions);
        categoryOptionMap.put(category.getUid(), categoryOptions);
    }
    Set<String> nonAccessibleDataSetIds = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        CategoryCombo categoryCombo = dataSet.getCategoryCombo();
        if (categoryCombo != null && categoryCombo.getCategories() != null) {
            for (Category category : categoryCombo.getCategories()) {
                if (!categoryOptionMap.containsKey(category.getUid()) || categoryOptionMap.get(category.getUid()).isEmpty()) {
                    nonAccessibleDataSetIds.add(dataSet.getUid());
                    break;
                }
            }
        }
    }
    dataSets = dataSets.stream().filter(dataSet -> !nonAccessibleDataSetIds.contains(dataSet.getUid())).collect(Collectors.toList());
    lockExceptions = dataSetService.getAllLockExceptions();
    Collections.sort(dataSets);
    Collections.sort(categoryCombos);
    Collections.sort(categories);
    defaultCategoryCombo = categoryService.getDefaultCategoryCombo();
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) HashSet(java.util.HashSet)

Example 30 with CategoryCombo

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

the class LoadFormAction method processSectionForAutoOrdering.

private void processSectionForAutoOrdering(Section section) {
    List<CategoryCombo> sortedCategoryCombos = getSortedCategoryCombos(section.getCategoryCombos());
    for (CategoryCombo categoryCombo : sortedCategoryCombos) {
        sectionCategoryComboDataElements.put(section.getId() + "-" + categoryCombo.getId(), section.getDataElementsByCategoryCombo(categoryCombo));
        orderedSectionCategoryCombos.put(String.valueOf(categoryCombo.getId()), categoryCombo.getId());
    }
    sectionCombos.put(section.getId(), sortedCategoryCombos.stream().map(ca -> String.valueOf(ca.getId())).collect(Collectors.toList()));
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo)

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