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