use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.
the class AnalyticalObjectObjectBundleHook method handleAttributeDimensions.
private void handleAttributeDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
if (!schema.havePersistedProperty("attributeDimensions"))
return;
for (TrackedEntityAttributeDimension attributeDimension : analyticalObject.getAttributeDimensions()) {
if (attributeDimension == null) {
continue;
}
attributeDimension.setAttribute(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getAttribute()));
attributeDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getLegendSet()));
preheatService.connectReferences(attributeDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
session.save(attributeDimension);
}
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.
the class BaseAnalyticalObject method getTrackedEntityDimension.
private Optional<DimensionalObject> getTrackedEntityDimension(final String dimension) {
// Tracked entity attribute
final Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
if (attributes.containsKey(dimension)) {
final TrackedEntityAttributeDimension tead = attributes.get(dimension);
if (tead != null) {
final ValueType valueType = tead.getAttribute() != null ? tead.getAttribute().getValueType() : null;
final OptionSet optionSet = tead.getAttribute() != null ? tead.getAttribute().getOptionSet() : null;
return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), null, tead.getFilter(), valueType, optionSet));
}
}
// Tracked entity data element
final Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
if (dataElements.containsKey(dimension)) {
final TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
if (tedd != null) {
final ValueType valueType = tedd.getDataElement() != null ? tedd.getDataElement().getValueType() : null;
final OptionSet optionSet = tedd.getDataElement() != null ? tedd.getDataElement().getOptionSet() : null;
return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getProgramStage(), tedd.getFilter(), valueType, optionSet));
}
}
// Tracked entity program indicator
final Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
if (programIndicators.containsKey(dimension)) {
final TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), null, teid.getFilter()));
}
return Optional.empty();
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.
the class DefaultAnalyticalObjectImportHandler method handleAttributeDimensions.
private void handleAttributeDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
if (!schema.havePersistedProperty("attributeDimensions"))
return;
for (TrackedEntityAttributeDimension attributeDimension : analyticalObject.getAttributeDimensions()) {
if (attributeDimension == null) {
continue;
}
attributeDimension.setAttribute(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getAttribute()));
attributeDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), attributeDimension.getLegendSet()));
preheatService.connectReferences(attributeDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
session.save(attributeDimension);
}
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetFromAnalyticalObjectB.
@Test
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, 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.TrackedEntityAttributeDimension in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testSetItemsForDimensionFilters.
@Test
void testSetItemsForDimensionFilters() {
TrackedEntityAttribute tea = new TrackedEntityAttribute();
tea.setAutoFields();
TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:2");
EventChart eventChart = new EventChart();
eventChart.setAutoFields();
eventChart.getColumnDimensions().add(tea.getUid());
eventChart.getAttributeDimensions().add(tead);
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(tea.getUid(), tea.getName()));
grid.addRow().addValue("1");
grid.addRow().addValue("2");
grid.addRow().addValue("3");
grid.addRow().addValue(null);
eventChart.populateAnalyticalProperties();
DimensionalObject dim = eventChart.getColumns().get(0);
DimensionalObjectUtils.setDimensionItemsForFilters(dim, grid, true);
assertNotNull(dim);
assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
assertEquals(tead.getFilter(), dim.getFilter());
List<DimensionalItemObject> items = dim.getItems();
assertEquals(4, items.size());
assertNotNull(items.get(0).getUid());
assertNotNull(items.get(0).getName());
assertNotNull(items.get(0).getCode());
assertNotNull(items.get(0).getShortName());
}
Aggregations