Search in sources :

Example 1 with ProfileItem

use of org.hisp.dhis.orgunitprofile.ProfileItem in project dhis2-core by dhis2.

the class DefaultOrgUnitProfileService method getDataItems.

/**
 * Retrieves a list of data items for the given org unit profile and org
 * unit. A data item can be of type data element, indicator, data set and
 * program indicator. Data element can be of type aggregate and tracker.
 *
 * @param profile the {@link OrganisationUnitProfile}.
 * @param orgUnit the {@link OrganisationUnit}.
 * @param period the {@link Period}.
 * @return a list of {@link ProfileItem}.
 */
private List<ProfileItem> getDataItems(OrgUnitProfile profile, OrganisationUnit orgUnit, Period period) {
    if (CollectionUtils.isEmpty(profile.getDataItems())) {
        return ImmutableList.of();
    }
    List<DimensionalItemObject> dataItems = idObjectManager.getByUid(DATA_ITEM_CLASSES, profile.getDataItems());
    if (CollectionUtils.isEmpty(dataItems)) {
        return ImmutableList.of();
    }
    DataQueryParams params = DataQueryParams.newBuilder().withDataDimensionItems(dataItems).withFilterOrganisationUnit(orgUnit).withFilterPeriod(period).build();
    Map<String, Object> values = analyticsService.getAggregatedDataValueMapping(params);
    if (MapUtils.isEmpty(values)) {
        return ImmutableList.of();
    }
    List<ProfileItem> items = new ArrayList<>();
    for (DimensionalItemObject dataItem : dataItems) {
        Object value = values.get(dataItem.getUid());
        if (value != null) {
            items.add(new ProfileItem(dataItem.getUid(), dataItem.getDisplayName(), value));
        }
    }
    return items;
}
Also used : ProfileItem(org.hisp.dhis.orgunitprofile.ProfileItem) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 2 with ProfileItem

use of org.hisp.dhis.orgunitprofile.ProfileItem in project dhis2-core by dhis2.

the class DefaultOrgUnitProfileService method getAttributes.

/**
 * Retrieves a list of attribute data items for the given org unit profile
 * and org unit.
 *
 * @param profile the {@link OrganisationUnitProfile}.
 * @param orgUnit the {@link OrganisationUnit}.
 * @return a list of {@link ProfileItem}.
 */
private List<ProfileItem> getAttributes(OrgUnitProfile profile, OrganisationUnit orgUnit) {
    if (CollectionUtils.isEmpty(profile.getAttributes())) {
        return ImmutableList.of();
    }
    List<Attribute> attributes = idObjectManager.getByUid(Attribute.class, profile.getAttributes());
    if (CollectionUtils.isEmpty(attributes)) {
        return ImmutableList.of();
    }
    List<ProfileItem> items = new ArrayList<>();
    for (Attribute attribute : attributes) {
        AttributeValue attributeValue = orgUnit.getAttributeValue(attribute);
        if (attributeValue != null) {
            items.add(new ProfileItem(attribute.getUid(), attribute.getDisplayName(), attributeValue.getValue()));
        }
    }
    return items;
}
Also used : ProfileItem(org.hisp.dhis.orgunitprofile.ProfileItem) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) ArrayList(java.util.ArrayList)

Example 3 with ProfileItem

use of org.hisp.dhis.orgunitprofile.ProfileItem in project dhis2-core by dhis2.

the class DefaultOrgUnitProfileService method getGroupSets.

/**
 * Retrieves a list of org unit group set data items for the given org unit
 * profile and org unit.
 *
 * @param profile the {@link OrganisationUnitProfile}.
 * @param orgUnit the {@link OrganisationUnit}.
 * @return a list of {@link ProfileItem}.
 */
private List<ProfileItem> getGroupSets(OrgUnitProfile profile, OrganisationUnit orgUnit) {
    if (CollectionUtils.isEmpty(profile.getGroupSets())) {
        return ImmutableList.of();
    }
    List<OrganisationUnitGroupSet> groupSets = idObjectManager.getByUid(OrganisationUnitGroupSet.class, profile.getGroupSets());
    if (CollectionUtils.isEmpty(groupSets)) {
        return ImmutableList.of();
    }
    List<ProfileItem> items = new ArrayList<>();
    Set<OrganisationUnitGroup> groups = orgUnit.getGroups();
    if (CollectionUtils.isEmpty(groups)) {
        return ImmutableList.of();
    }
    for (OrganisationUnitGroupSet groupSet : groupSets) {
        OrganisationUnitGroup group = groupService.getOrgUnitGroupInGroupSet(groups, groupSet);
        if (group != null) {
            items.add(new ProfileItem(groupSet.getUid(), groupSet.getDisplayName(), group.getDisplayName()));
        }
    }
    return items;
}
Also used : ProfileItem(org.hisp.dhis.orgunitprofile.ProfileItem) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ArrayList(java.util.ArrayList) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

ArrayList (java.util.ArrayList)3 ProfileItem (org.hisp.dhis.orgunitprofile.ProfileItem)3 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 Attribute (org.hisp.dhis.attribute.Attribute)1 AttributeValue (org.hisp.dhis.attribute.AttributeValue)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)1 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)1