Search in sources :

Example 16 with OrganisationUnitGroup

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

the class AbstractDataSetCompletenessService method getDataSetCompleteness.

// -------------------------------------------------------------------------
// DataSetCompleteness
// -------------------------------------------------------------------------
@Override
@Transactional
public List<DataSetCompletenessResult> getDataSetCompleteness(int periodId, int organisationUnitId, Set<Integer> groupIds) {
    final Period period = periodService.getPeriod(periodId);
    final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(organisationUnitId);
    final List<DataSet> dataSets = dataSetService.getAllDataSets();
    final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet(idObjectManager.getObjects(OrganisationUnitGroup.class, groupIds)) : null;
    final List<DataSetCompletenessResult> results = new ArrayList<>();
    for (final DataSet dataSet : dataSets) {
        final List<Integer> periodsBetweenDates = getIdentifiers(periodService.getPeriodsBetweenDates(dataSet.getPeriodType(), period.getStartDate(), period.getEndDate()));
        final Set<Integer> relevantSources = getRelevantSources(dataSet, children, groups);
        final DataSetCompletenessResult result = new DataSetCompletenessResult();
        result.setSources(getSources(dataSet, relevantSources, period));
        if (result.getSources() > 0) {
            result.setName(dataSet.getName());
            result.setRegistrations(getRegistrations(dataSet, relevantSources, periodsBetweenDates));
            result.setRegistrationsOnTime(getRegistrationsOnTime(dataSet, relevantSources, periodsBetweenDates));
            result.setDataSetId(dataSet.getId());
            result.setPeriodId(periodId);
            result.setOrganisationUnitId(organisationUnitId);
            results.add(result);
        }
    }
    return results;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with OrganisationUnitGroup

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

the class MergeServiceTest method mergeOrgUnitGroup.

@Test
public void mergeOrgUnitGroup() {
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    OrganisationUnit organisationUnitB = createOrganisationUnit('B');
    OrganisationUnit organisationUnitC = createOrganisationUnit('C');
    OrganisationUnit organisationUnitD = createOrganisationUnit('D');
    OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
    OrganisationUnitGroup organisationUnitGroupB = createOrganisationUnitGroup('B');
    organisationUnitGroupA.getMembers().add(organisationUnitA);
    organisationUnitGroupA.getMembers().add(organisationUnitB);
    organisationUnitGroupA.getMembers().add(organisationUnitC);
    organisationUnitGroupA.getMembers().add(organisationUnitD);
    OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
    organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
    mergeService.merge(new MergeParams<>(organisationUnitGroupA, organisationUnitGroupB).setMergeMode(MergeMode.REPLACE));
    assertFalse(organisationUnitGroupB.getMembers().isEmpty());
    assertEquals(4, organisationUnitGroupB.getMembers().size());
    assertNotNull(organisationUnitGroupB.getGroupSets());
    assertFalse(organisationUnitGroupB.getGroupSets().isEmpty());
}
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 18 with OrganisationUnitGroup

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

the class BaseAnalyticalObject method getDimensionalObject.

/**
     * Assembles a list of DimensionalObjects based on the concrete objects in
     * this BaseAnalyticalObject.
     * <p>
     * Merges fixed and relative periods into the pe dimension, where the
     * RelativePeriods object is represented by enums (e.g. LAST_MONTH). Merges
     * fixed and user organisation units into the ou dimension, where user
     * organisation units properties are represented by enums (e.g. USER_ORG_UNIT).
     * <p>
     * This method is useful when serializing the AnalyticalObject.
     *
     * @param dimension the dimension identifier.
     * @return a list of DimensionalObjects.
     */
protected DimensionalObject getDimensionalObject(String dimension) {
    if (DATA_X_DIM_ID.equals(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.DATA_X, getDataDimensionNameableObjects());
    } else if (PERIOD_DIM_ID.equals(dimension)) {
        List<Period> periodList = new ArrayList<>(periods);
        if (hasRelativePeriods()) {
            List<RelativePeriodEnum> list = relatives.getRelativePeriodEnums();
            for (RelativePeriodEnum periodEnum : list) {
                periodList.add(new ConfigurablePeriod(periodEnum.toString()));
            }
        }
        Collections.sort(periodList, new AscendingPeriodComparator());
        return new BaseDimensionalObject(dimension, DimensionType.PERIOD, periodList);
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
        List<DimensionalItemObject> ouList = new ArrayList<>();
        ouList.addAll(organisationUnits);
        ouList.addAll(transientOrganisationUnits);
        if (userOrganisationUnit) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT));
        }
        if (userOrganisationUnitChildren) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_CHILDREN));
        }
        if (userOrganisationUnitGrandChildren) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_GRANDCHILDREN));
        }
        if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {
            for (Integer level : organisationUnitLevels) {
                String id = KEY_LEVEL + level;
                ouList.add(new BaseDimensionalItemObject(id));
            }
        }
        if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty()) {
            for (OrganisationUnitGroup group : itemOrganisationUnitGroups) {
                String id = KEY_ORGUNIT_GROUP + group.getUid();
                ouList.add(new BaseDimensionalItemObject(id));
            }
        }
        return new BaseDimensionalObject(dimension, DimensionType.ORGANISATION_UNIT, ouList);
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<>());
    } else if (DATA_COLLAPSED_DIM_ID.contains(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.DATA_COLLAPSED, new ArrayList<>());
    } else if (STATIC_DIMS.contains(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.STATIC, new ArrayList<>());
    } else {
        // Embedded dimensions
        Optional<DimensionalObject> object = Optional.empty();
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        // Tracked entity attribute
        Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
        if (attributes.containsKey(dimension)) {
            TrackedEntityAttributeDimension tead = attributes.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter());
        }
        // Tracked entity data element
        Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
        if (dataElements.containsKey(dimension)) {
            TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter());
        }
        // Tracked entity program indicator
        Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
        if (programIndicators.containsKey(dimension)) {
            TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter());
        }
    }
    throw new IllegalArgumentException("Not a valid dimension: " + dimension);
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) Optional(java.util.Optional) ArrayList(java.util.ArrayList) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) AscendingPeriodComparator(org.hisp.dhis.period.comparator.AscendingPeriodComparator) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ConfigurablePeriod(org.hisp.dhis.period.ConfigurablePeriod) RelativePeriodEnum(org.hisp.dhis.period.RelativePeriodEnum) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with OrganisationUnitGroup

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

the class DataExportParams method getAllOrganisationUnits.

public Set<OrganisationUnit> getAllOrganisationUnits() {
    final Set<OrganisationUnit> orgUnits = Sets.newHashSet();
    orgUnits.addAll(organisationUnits);
    for (OrganisationUnitGroup group : organisationUnitGroups) {
        orgUnits.addAll(group.getMembers());
    }
    return ImmutableSet.copyOf(orgUnits);
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Example 20 with OrganisationUnitGroup

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

the class DefaultAnalyticsService method getOrgUnitTargetMap.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
     * Generates a mapping of permutations keys (organisation unit id or null)
     * and mappings of organisation unit group and counts.
     *
     * @param params the {@link DataQueryParams}.
     * @param indicators the indicators for which formulas to scan for organisation
     *        unit groups.
     * @return a map of maps.
     */
private Map<String, Map<String, Integer>> getOrgUnitTargetMap(DataQueryParams params, Collection<Indicator> indicators) {
    Set<OrganisationUnitGroup> orgUnitGroups = expressionService.getOrganisationUnitGroupsInIndicators(indicators);
    if (orgUnitGroups.isEmpty()) {
        return null;
    }
    DataQueryParams orgUnitTargetParams = DataQueryParams.newBuilder(params).pruneToDimensionType(DimensionType.ORGANISATION_UNIT).addDimension(new BaseDimensionalObject(DimensionalObject.ORGUNIT_GROUP_DIM_ID, null, new ArrayList<DimensionalItemObject>(orgUnitGroups))).withSkipPartitioning(true).build();
    Map<String, Double> orgUnitCountMap = getAggregatedOrganisationUnitTargetMap(orgUnitTargetParams);
    return DataQueryParams.getPermutationOrgUnitGroupCountMap(orgUnitCountMap);
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)

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