use of org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetFromAnalyticalObjectB.
@Test
public void testGetFromAnalyticalObjectB() {
EventChart eventChart = new EventChart();
eventChart.setAutoFields();
eventChart.setProgram(prA);
eventChart.getColumnDimensions().add(atA.getUid());
eventChart.getColumnDimensions().add(deA.getUid());
eventChart.getRowDimensions().add(DimensionalObject.PERIOD_DIM_ID);
eventChart.getFilterDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
eventChart.getAttributeDimensions().add(new TrackedEntityAttributeDimension(atA, null, "LE:5"));
eventChart.getDataElementDimensions().add(new TrackedEntityDataElementDimension(deA, null, "GE:100"));
eventChart.getPeriods().add(peA);
eventChart.getPeriods().add(peB);
eventChart.getOrganisationUnits().add(ouA);
eventChart.getOrganisationUnits().add(ouB);
EventQueryParams params = dataQueryService.getFromAnalyticalObject(eventChart);
assertNotNull(params);
assertEquals(2, params.getItems().size());
assertEquals(2, params.getPeriods().size());
assertEquals(2, params.getFilterOrganisationUnits().size());
}
use of org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension in project dhis2-core by dhis2.
the class AnalyticalObjectObjectBundleHook method handleDataElementDimensions.
private void handleDataElementDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
if (!schema.havePersistedProperty("dataElementDimensions"))
return;
for (TrackedEntityDataElementDimension dataElementDimension : analyticalObject.getDataElementDimensions()) {
if (dataElementDimension == null) {
continue;
}
dataElementDimension.setDataElement(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataElementDimension.getDataElement()));
dataElementDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataElementDimension.getLegendSet()));
preheatService.connectReferences(dataElementDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
session.save(dataElementDimension);
}
}
use of org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension 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.trackedentity.TrackedEntityDataElementDimension in project dhis2-core by dhis2.
the class BaseAnalyticalObject method getDimensionalObject.
/**
* Assembles a DimensionalObject based on the persisted properties of this
* AnalyticalObject. Collapses indicators, data elements, data element
* operands and data sets into the dx dimension.
* <p>
* Collapses fixed and relative periods into the pe dimension. Collapses
* fixed and user organisation units into the ou dimension.
*
* @param dimension the dimension identifier.
* @param date the date used for generating relative periods.
* @param user the current user.
* @param dynamicNames whether to use dynamic or static names.
* @param format the I18nFormat.
* @return a DimensionalObject.
*/
protected DimensionalObject getDimensionalObject(String dimension, Date date, User user, boolean dynamicNames, List<OrganisationUnit> organisationUnitsAtLevel, List<OrganisationUnit> organisationUnitsInGroups, I18nFormat format) {
List<DimensionalItemObject> items = new ArrayList<>();
DimensionType type = null;
if (DATA_X_DIM_ID.equals(dimension)) {
items.addAll(getDataDimensionNameableObjects());
type = DimensionType.DATA_X;
} else if (PERIOD_DIM_ID.equals(dimension)) {
setPeriodNames(periods, dynamicNames, format);
items.addAll(periods);
if (hasRelativePeriods()) {
items.addAll(relatives.getRelativePeriods(date, format, dynamicNames));
}
type = DimensionType.PERIOD;
} else if (ORGUNIT_DIM_ID.equals(dimension)) {
items.addAll(organisationUnits);
items.addAll(transientOrganisationUnits);
if (userOrganisationUnit && user != null && user.hasOrganisationUnit()) {
items.addAll(user.getOrganisationUnits());
}
if (userOrganisationUnitChildren && user != null && user.hasOrganisationUnit()) {
user.getOrganisationUnits().forEach(ou -> items.addAll(ou.getSortedChildren()));
}
if (userOrganisationUnitGrandChildren && user != null && user.hasOrganisationUnit()) {
user.getOrganisationUnits().forEach(ou -> items.addAll(ou.getSortedGrandChildren()));
}
if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty() && organisationUnitsAtLevel != null) {
// Must be set externally
items.addAll(organisationUnitsAtLevel);
}
if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty() && organisationUnitsInGroups != null) {
// Must be set externally
items.addAll(organisationUnitsInGroups);
}
type = DimensionType.ORGANISATION_UNIT;
} else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
items.addAll(transientCategoryOptionCombos);
type = DimensionType.CATEGORY_OPTION_COMBO;
} else if (STATIC_DIMS.contains(dimension)) {
type = DimensionType.STATIC;
} else {
// Embedded dimensions
Optional<DimensionalObject> object = Optional.empty();
if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
items.addAll(object.get().getItems());
type = DimensionType.DATA_ELEMENT_GROUP_SET;
}
if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
items.addAll(object.get().getItems());
type = DimensionType.ORGANISATION_UNIT_GROUP_SET;
}
if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
items.addAll(object.get().getItems());
type = DimensionType.CATEGORY;
}
if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
items.addAll(object.get().getItems());
type = DimensionType.CATEGORY_OPTION_GROUP_SET;
}
// 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());
}
}
IdentifiableObjectUtils.removeDuplicates(items);
return new BaseDimensionalObject(dimension, type, items);
}
use of org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetFromAnalyticalObjectC.
@Test
public void testGetFromAnalyticalObjectC() {
EventChart eventChart = new EventChart();
eventChart.setAutoFields();
eventChart.setProgram(prA);
eventChart.getColumnDimensions().add(deA.getUid());
eventChart.getColumnDimensions().add(atA.getUid());
eventChart.getRowDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
eventChart.getFilterDimensions().add(DimensionalObject.PERIOD_DIM_ID);
eventChart.getDataElementDimensions().add(new TrackedEntityDataElementDimension(deA, null, "GT:2000"));
eventChart.getAttributeDimensions().add(new TrackedEntityAttributeDimension(atA, null, "LE:5"));
eventChart.getPeriods().add(peA);
eventChart.getPeriods().add(peB);
eventChart.getOrganisationUnits().add(ouA);
EventQueryParams params = dataQueryService.getFromAnalyticalObject(eventChart);
assertNotNull(params);
assertEquals(2, params.getItems().size());
assertEquals(1, params.getOrganisationUnits().size());
assertEquals(2, params.getFilterPeriods().size());
}
Aggregations