Search in sources :

Example 1 with OrganisationUnitGroup

use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.

the class DhisConvenienceTest method createOrganisationUnitGroup.

/**
     * @param uniqueCharacter A unique character to identify the object.
     */
public static OrganisationUnitGroup createOrganisationUnitGroup(char uniqueCharacter) {
    OrganisationUnitGroup group = new OrganisationUnitGroup();
    group.setAutoFields();
    group.setUid(BASE_UID + uniqueCharacter);
    group.setName("OrganisationUnitGroup" + uniqueCharacter);
    group.setShortName("OrganisationUnitGroupShort" + uniqueCharacter);
    group.setCode("OrganisationUnitGroupCode" + uniqueCharacter);
    return group;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup)

Example 2 with OrganisationUnitGroup

use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.

the class DefaultExpressionService method getOrganisationUnitGroupsInIndicators.

@Override
public Set<OrganisationUnitGroup> getOrganisationUnitGroupsInIndicators(Collection<Indicator> indicators) {
    Set<OrganisationUnitGroup> groups = new HashSet<>();
    if (indicators != null) {
        for (Indicator indicator : indicators) {
            groups.addAll(getOrganisationUnitGroupsInExpression(indicator.getNumerator()));
            groups.addAll(getOrganisationUnitGroupsInExpression(indicator.getDenominator()));
        }
    }
    return groups;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Indicator(org.hisp.dhis.indicator.Indicator) HashSet(java.util.HashSet)

Example 3 with OrganisationUnitGroup

use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.

the class DefaultExpressionService method substituteExpression.

private String substituteExpression(String expression, Map<String, Constant> constants, Map<String, OrganisationUnitGroup> orgUnitGroups, Integer days) {
    if (expression == null || expression.isEmpty()) {
        return null;
    }
    // ---------------------------------------------------------------------
    // Constants
    // ---------------------------------------------------------------------
    StringBuffer sb = new StringBuffer();
    Matcher matcher = CONSTANT_PATTERN.matcher(expression);
    while (matcher.find()) {
        String co = matcher.group(GROUP_ID);
        Constant constant = constants.get(co);
        String replacement = constant != null ? String.valueOf(constant.getValue()) : NULL_REPLACEMENT;
        matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
    }
    expression = TextUtils.appendTail(matcher, sb);
    // ---------------------------------------------------------------------
    // Org unit groups
    // ---------------------------------------------------------------------
    sb = new StringBuffer();
    matcher = OU_GROUP_PATTERN.matcher(expression);
    while (matcher.find()) {
        String oug = matcher.group(GROUP_ID);
        OrganisationUnitGroup group = orgUnitGroups.get(oug);
        String replacement = group != null ? String.valueOf(group.getMembers().size()) : NULL_REPLACEMENT;
        matcher.appendReplacement(sb, replacement);
    // TODO sub tree
    }
    expression = TextUtils.appendTail(matcher, sb);
    // ---------------------------------------------------------------------
    // Days
    // ---------------------------------------------------------------------
    sb = new StringBuffer();
    matcher = DAYS_PATTERN.matcher(expression);
    while (matcher.find()) {
        String replacement = days != null ? String.valueOf(days) : NULL_REPLACEMENT;
        matcher.appendReplacement(sb, replacement);
    }
    return TextUtils.appendTail(matcher, sb);
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Matcher(java.util.regex.Matcher) Constant(org.hisp.dhis.constant.Constant)

Example 4 with OrganisationUnitGroup

use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.

the class MergeServiceTest method mergeOrgUnitGroupSet.

@Test
public void mergeOrgUnitGroupSet() {
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    OrganisationUnit organisationUnitB = createOrganisationUnit('B');
    OrganisationUnit organisationUnitC = createOrganisationUnit('C');
    OrganisationUnit organisationUnitD = createOrganisationUnit('D');
    OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
    organisationUnitGroupA.getMembers().add(organisationUnitA);
    organisationUnitGroupA.getMembers().add(organisationUnitB);
    organisationUnitGroupA.getMembers().add(organisationUnitC);
    organisationUnitGroupA.getMembers().add(organisationUnitD);
    OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
    OrganisationUnitGroupSet organisationUnitGroupSetB = createOrganisationUnitGroupSet('B');
    organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
    mergeService.merge(new MergeParams<>(organisationUnitGroupSetA, organisationUnitGroupSetB).setMergeMode(MergeMode.REPLACE));
    assertFalse(organisationUnitGroupSetB.getOrganisationUnitGroups().isEmpty());
    assertEquals(organisationUnitGroupSetA.getName(), organisationUnitGroupSetB.getName());
    assertEquals(organisationUnitGroupSetA.getDescription(), organisationUnitGroupSetB.getDescription());
    assertEquals(organisationUnitGroupSetA.isCompulsory(), organisationUnitGroupSetB.isCompulsory());
    assertEquals(organisationUnitGroupSetA.isIncludeSubhierarchyInAnalytics(), organisationUnitGroupSetB.isIncludeSubhierarchyInAnalytics());
    assertEquals(1, organisationUnitGroupSetB.getOrganisationUnitGroups().size());
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MergeParams(org.hisp.dhis.schema.MergeParams) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with OrganisationUnitGroup

use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.

the class AbstractDataSetCompletenessService method getRelevantSources.

private Set<Integer> getRelevantSources(DataSet dataSet, Set<Integer> sources, Set<OrganisationUnitGroup> groups) {
    Set<Integer> dataSetSources = new HashSet<>(getIdentifiers(dataSet.getSources()));
    if (groups != null) {
        for (OrganisationUnitGroup group : groups) {
            List<Integer> ids = getIdentifiers(group.getMembers());
            dataSetSources.retainAll(ids);
        }
    }
    return Sets.intersection(dataSetSources, sources);
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) HashSet(java.util.HashSet)

Aggregations

OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)22 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 ArrayList (java.util.ArrayList)10 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Transactional (org.springframework.transaction.annotation.Transactional)5 HashSet (java.util.HashSet)4 Period (org.hisp.dhis.period.Period)4 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3 Constant (org.hisp.dhis.constant.Constant)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Matcher (java.util.regex.Matcher)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 AttributeValue (org.hisp.dhis.attribute.AttributeValue)2 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 Grid (org.hisp.dhis.common.Grid)2 DataSetCompletenessResult (org.hisp.dhis.completeness.DataSetCompletenessResult)2 Indicator (org.hisp.dhis.indicator.Indicator)2