Search in sources :

Example 11 with CategoryOption

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

the class AttributeOptionComboDateCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    CategoryOptionCombo attributeOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
    Date executionDate = null;
    if (event.getEventDate() != null) {
        executionDate = DateUtils.parseDate(event.getEventDate());
    }
    Date dueDate = new Date();
    if (event.getDueDate() != null) {
        dueDate = DateUtils.parseDate(event.getDueDate());
    }
    Date eventDate = executionDate != null ? executionDate : dueDate;
    if (eventDate == null) {
        return error("Event date can not be empty", event.getEvent());
    }
    Program program = ctx.getProgramsMap().get(event.getProgram());
    for (CategoryOption categoryOption : attributeOptionCombo.getCategoryOptions()) {
        if (categoryOption.getStartDate() != null && eventDate.compareTo(categoryOption.getStartDate()) < 0) {
            return error("Event date " + getMediumDateString(eventDate) + " is before start date " + getMediumDateString(categoryOption.getStartDate()) + " for attributeOption '" + categoryOption.getName() + "'", event.getEvent());
        }
        if (categoryOption.getEndDate() != null && eventDate.compareTo(categoryOption.getAdjustedEndDate(program)) > 0) {
            return error("Event date " + getMediumDateString(eventDate) + " is after end date " + getMediumDateString(categoryOption.getAdjustedEndDate(program)) + " for attributeOption '" + categoryOption.getName() + "' in program '" + program.getName() + "'", event.getEvent());
        }
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Example 12 with CategoryOption

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

the class DefaultAclService method checkOptionComboSharingPermission.

private boolean checkOptionComboSharingPermission(User user, IdentifiableObject object, Permission permission) {
    CategoryOptionCombo optionCombo = (CategoryOptionCombo) object;
    if (optionCombo.isDefault() || optionCombo.getCategoryOptions().isEmpty()) {
        return true;
    }
    List<Long> accessibleOptions = new ArrayList<>();
    for (CategoryOption option : optionCombo.getCategoryOptions()) {
        if (checkSharingPermission(user, option, permission)) {
            accessibleOptions.add(option.getId());
        }
    }
    return accessibleOptions.size() == optionCombo.getCategoryOptions().size();
}
Also used : ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 13 with CategoryOption

use of org.hisp.dhis.category.CategoryOption 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)

Example 14 with CategoryOption

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

the class DefaultDataApprovalLevelService method getLowestDataApprovalLevel.

@Override
@Transactional(readOnly = true)
public DataApprovalLevel getLowestDataApprovalLevel(OrganisationUnit orgUnit, CategoryOptionCombo attributeOptionCombo) {
    Set<CategoryOptionGroupSet> cogSets = null;
    if (attributeOptionCombo != null && attributeOptionCombo != categoryService.getDefaultCategoryOptionCombo()) {
        cogSets = new HashSet<>();
        for (CategoryOption option : attributeOptionCombo.getCategoryOptions()) {
            if (option.getGroupSets() != null) {
                cogSets.addAll(option.getGroupSets());
            }
        }
    }
    int orgUnitLevel = orgUnit.getLevel();
    List<DataApprovalLevel> approvalLevels = getDataApprovalLevelsByOrgUnitLevel(orgUnitLevel);
    for (DataApprovalLevel level : Lists.reverse(approvalLevels)) {
        if (level.getCategoryOptionGroupSet() == null) {
            if (cogSets == null) {
                return level;
            }
        } else if (cogSets != null && cogSets.contains(level.getCategoryOptionGroupSet())) {
            return level;
        }
    }
    return null;
}
Also used : CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOption(org.hisp.dhis.category.CategoryOption) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with CategoryOption

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

the class DefaultCategoryService method getCoDimensionConstraints.

@Override
@Transactional(readOnly = true)
public Set<CategoryOption> getCoDimensionConstraints(User user) {
    Set<CategoryOption> options = null;
    Set<Category> catConstraints = user.getCatDimensionConstraints();
    if (catConstraints != null && !catConstraints.isEmpty()) {
        options = new HashSet<>();
        for (Category category : catConstraints) {
            options.addAll(getCategoryOptions(category));
        }
    }
    return options;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryOption(org.hisp.dhis.category.CategoryOption) Transactional(org.springframework.transaction.annotation.Transactional)

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