Search in sources :

Example 11 with CategoryCombo

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

the class CategoryOptionComboNameResourceTable method getPopulateTempTableContent.

@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (CategoryCombo combo : objects) {
        if (!combo.isValid()) {
            log.warn("Ignoring category combo, not valid: " + combo);
            continue;
        }
        for (CategoryOptionCombo coc : combo.getOptionCombos()) {
            List<Object> values = new ArrayList<>();
            values.add(coc.getId());
            values.add(coc.getName());
            values.add(coc.isIgnoreApproval() ? APPROVAL_LEVEL_HIGHEST : null);
            values.add(coc.getLatestStartDate());
            values.add(coc.getEarliestEndDate());
            batchArgs.add(values.toArray());
        }
    }
    return Optional.of(batchArgs);
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 12 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(DataSet dataSet, boolean includeTotals) {
    List<DataElementOperand> operands = Lists.newArrayList();
    for (DataSetElement element : dataSet.getDataSetElements()) {
        CategoryCombo categoryCombo = element.getResolvedCategoryCombo();
        if (includeTotals && !categoryCombo.isDefault()) {
            operands.add(new DataElementOperand(element.getDataElement()));
        }
        operands.addAll(getOperands(element.getDataElement(), element.getResolvedCategoryCombo()));
    }
    return operands;
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSetElement(org.hisp.dhis.dataset.DataSetElement) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with CategoryCombo

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

the class DataElementDeletionHandler method deleteCategoryCombo.

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

Example 14 with CategoryCombo

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

the class DefaultCsvImportService method dataElementsFromCsv.

// -------------------------------------------------------------------------
// Private methods
// -------------------------------------------------------------------------
private List<DataElement> dataElementsFromCsv(CsvReader reader) throws IOException {
    CategoryCombo categoryCombo = categoryService.getDefaultCategoryCombo();
    List<DataElement> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            DataElement object = new DataElement();
            setIdentifiableObject(object, values);
            object.setShortName(getSafe(values, 3, object.getName(), 50));
            object.setDescription(getSafe(values, 4));
            object.setFormName(getSafe(values, 5, 230));
            String domainType = getSafe(values, 6, DataElementDomain.AGGREGATE.getValue(), 16);
            object.setDomainType(DataElementDomain.fromValue(domainType));
            object.setValueType(ValueType.valueOf(getSafe(values, 7, ValueType.INTEGER.toString(), 50)));
            object.setAggregationType(AggregationType.valueOf(getSafe(values, 8, AggregationType.SUM.toString(), 50)));
            String categoryComboUid = getSafe(values, 9, 11);
            object.setUrl(getSafe(values, 10, 255));
            object.setZeroIsSignificant(Boolean.parseBoolean(getSafe(values, 11, "false", null)));
            String optionSetUid = getSafe(values, 12, 11);
            String commentOptionSetUid = getSafe(values, 13, 11);
            object.setAutoFields();
            CategoryCombo cc = new CategoryCombo();
            cc.setUid(categoryComboUid);
            cc.setAutoFields();
            if (categoryComboUid == null) {
                cc.setUid(categoryCombo.getUid());
            }
            object.setCategoryCombo(cc);
            if (optionSetUid != null) {
                OptionSet optionSet = new OptionSet();
                optionSet.setUid(optionSetUid);
                optionSet.setAutoFields();
                object.setOptionSet(optionSet);
            }
            if (commentOptionSetUid != null) {
                OptionSet optionSet = new OptionSet();
                optionSet.setUid(commentOptionSetUid);
                optionSet.setAutoFields();
                object.setCommentOptionSet(optionSet);
            }
            list.add(object);
        }
    }
    return list;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList) OptionSet(org.hisp.dhis.option.OptionSet)

Example 15 with CategoryCombo

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

the class DefaultCsvImportService method categoryCombosFromCsv.

private List<CategoryCombo> categoryCombosFromCsv(CsvReader reader) throws IOException {
    List<CategoryCombo> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            CategoryCombo object = new CategoryCombo();
            setIdentifiableObject(object, values);
            object.setDataDimensionType(DataDimensionType.valueOf(getSafe(values, 3, DataDimensionType.DISAGGREGATION.toString(), 40)));
            object.setSkipTotal(Boolean.parseBoolean(getSafe(values, 4, Boolean.FALSE.toString(), 40)));
            list.add(object);
        }
    }
    return list;
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList)

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