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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations