use of org.hisp.dhis.common.FoundDimensionItemValue in project dhis2-core by dhis2.
the class PredictionDataValueFetcher method mapToValues.
/**
* Convert the value map to a list of found values.
*/
private List<FoundDimensionItemValue> mapToValues(OrganisationUnit orgUnit, MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> map) {
List<FoundDimensionItemValue> values = new ArrayList<>();
for (Map.Entry<CategoryOptionCombo, MapMap<Period, DimensionalItemObject, Object>> e1 : map.entrySet()) {
CategoryOptionCombo aoc = e1.getKey();
for (Map.Entry<Period, Map<DimensionalItemObject, Object>> e2 : e1.getValue().entrySet()) {
Period period = e2.getKey();
for (Map.Entry<DimensionalItemObject, Object> e3 : e2.getValue().entrySet()) {
DimensionalItemObject obj = e3.getKey();
Object value = e3.getValue();
values.add(new FoundDimensionItemValue(orgUnit, period, aoc, obj, value));
}
}
}
return values;
}
use of org.hisp.dhis.common.FoundDimensionItemValue in project dhis2-core by dhis2.
the class PredictionAnalyticsDataFetcher method getValuesInternal.
/**
* Queries analytics for data.
*/
private List<FoundDimensionItemValue> getValuesInternal(List<OrganisationUnit> orgUnits, Set<DimensionalItemObject> dimensionItems, boolean hasAttributeOptions) {
List<FoundDimensionItemValue> values = new ArrayList<>();
if (dimensionItems.isEmpty()) {
return values;
}
DataQueryParams.Builder paramsBuilder = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(periods)).withDataDimensionItems(Lists.newArrayList(dimensionItems)).withOrganisationUnits(orgUnits);
if (hasAttributeOptions) {
paramsBuilder.withAttributeOptionCombos(Collections.emptyList());
}
Grid grid = analyticsService.getAggregatedDataValues(paramsBuilder.build());
int peInx = grid.getIndexOfHeader(DimensionalObject.PERIOD_DIM_ID);
int dxInx = grid.getIndexOfHeader(DimensionalObject.DATA_X_DIM_ID);
int ouInx = grid.getIndexOfHeader(DimensionalObject.ORGUNIT_DIM_ID);
int aoInx = hasAttributeOptions ? grid.getIndexOfHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID) : 0;
int vlInx = grid.getWidth() - 1;
for (List<Object> row : grid.getRows()) {
String pe = (String) row.get(peInx);
String dx = (String) row.get(dxInx);
String ou = (String) row.get(ouInx);
String ao = hasAttributeOptions ? (String) row.get(aoInx) : null;
Object vl = row.get(vlInx);
Period period = periodLookup.get(pe);
DimensionalItemObject item = analyticsItemsLookup.get(dx);
OrganisationUnit orgUnit = orgUnitLookup.get(ou);
CategoryOptionCombo attributeOptionCombo = hasAttributeOptions ? cocLookup.get(ao, () -> categoryService.getCategoryOptionCombo(ao)) : null;
values.add(new FoundDimensionItemValue(orgUnit, period, attributeOptionCombo, item, vl));
}
return values;
}
use of org.hisp.dhis.common.FoundDimensionItemValue in project dhis2-core by dhis2.
the class PredictionAnalyticsDataFetcherTest method testGetValues.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testGetValues() {
// ---------------------------------------------------------------------
// Items with Attribute Option Combos
// ---------------------------------------------------------------------
CategoryOptionCombo aocC = createCategoryOptionCombo('C');
CategoryOptionCombo aocD = createCategoryOptionCombo('D');
when(categoryService.getCategoryOptionCombo(aocC.getUid())).thenReturn(aocC);
when(categoryService.getCategoryOptionCombo(aocD.getUid())).thenReturn(aocD);
ProgramIndicator programIndicatorA = createProgramIndicator('A', programA, "expressionA", "filterA");
ProgramIndicator programIndicatorB = createProgramIndicator('B', programB, "expressionB", "filterB");
trackedEntityAttributeA = createTrackedEntityAttribute('A');
Set<DimensionalItemObject> aocItems = Sets.newHashSet(programIndicatorA, programIndicatorB, trackedEntityAttributeA);
DataQueryParams aocParams = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(periods)).withDataDimensionItems(Lists.newArrayList(aocItems)).withOrganisationUnits(orgUnits).withAttributeOptionCombos(Collections.emptyList()).build();
Grid aocGrid = new ListGrid();
aocGrid.addHeader(new GridHeader(PERIOD_DIM_ID, "Period", ValueType.TEXT, false, true));
aocGrid.addHeader(new GridHeader(DATA_X_DIM_ID, "DimensionItem", ValueType.TEXT, false, true));
aocGrid.addHeader(new GridHeader(ORGUNIT_DIM_ID, "OrganisationUnit", ValueType.TEXT, false, true));
aocGrid.addHeader(new GridHeader(ATTRIBUTEOPTIONCOMBO_DIM_ID, "AOC", ValueType.TEXT, false, true));
aocGrid.addHeader(new GridHeader("value", "Value", ValueType.NUMBER, false, true));
aocGrid.addRow().addValue(periodA.getIsoDate()).addValue(programIndicatorA.getUid()).addValue(orgUnitA.getUid()).addValue(aocC.getUid()).addValue(10.0);
aocGrid.addRow().addValue(periodB.getIsoDate()).addValue(programIndicatorB.getUid()).addValue(orgUnitA.getUid()).addValue(aocC.getUid()).addValue(20.0);
aocGrid.addRow().addValue(periodB.getIsoDate()).addValue(trackedEntityAttributeA.getUid()).addValue(orgUnitA.getUid()).addValue(aocD.getUid()).addValue(30.0);
aocGrid.addRow().addValue(periodA.getIsoDate()).addValue(programIndicatorA.getUid()).addValue(orgUnitB.getUid()).addValue(aocC.getUid()).addValue(40.0);
when(analyticsService.getAggregatedDataValues(aocParams)).thenReturn(aocGrid);
FoundDimensionItemValue expected1;
FoundDimensionItemValue expected2;
FoundDimensionItemValue expected3;
FoundDimensionItemValue expected4;
expected1 = new FoundDimensionItemValue(orgUnitA, periodA, aocC, programIndicatorA, 10.0);
expected2 = new FoundDimensionItemValue(orgUnitA, periodB, aocC, programIndicatorB, 20.0);
expected3 = new FoundDimensionItemValue(orgUnitA, periodB, aocD, trackedEntityAttributeA, 30.0);
expected4 = new FoundDimensionItemValue(orgUnitB, periodA, aocC, programIndicatorA, 40.0);
// ---------------------------------------------------------------------
// Items without Attribute Option Combos
// ---------------------------------------------------------------------
ProgramIndicator programIndicatorC = createProgramIndicator('C', programA, "expressionC", "filterC");
ProgramIndicator programIndicatorD = createProgramIndicator('D', programB, "expressionD", "filterD");
programIndicatorC.setAnalyticsType(ENROLLMENT);
programIndicatorD.setAnalyticsType(ENROLLMENT);
Set<DimensionalItemObject> nonAocItems = Sets.newHashSet(programIndicatorC, programIndicatorD);
DataQueryParams nonAocParams = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(periods)).withDataDimensionItems(Lists.newArrayList(nonAocItems)).withOrganisationUnits(orgUnits).build();
Grid nonAocGrid = new ListGrid();
nonAocGrid.addHeader(new GridHeader(PERIOD_DIM_ID, "Period", ValueType.TEXT, false, true));
nonAocGrid.addHeader(new GridHeader(DATA_X_DIM_ID, "DimensionItem", ValueType.TEXT, false, true));
nonAocGrid.addHeader(new GridHeader(ORGUNIT_DIM_ID, "OrganisationUnit", ValueType.TEXT, false, true));
nonAocGrid.addHeader(new GridHeader("value", "Value", ValueType.NUMBER, false, true));
nonAocGrid.addRow().addValue(periodA.getIsoDate()).addValue(programIndicatorC.getUid()).addValue(orgUnitA.getUid()).addValue(100.0);
nonAocGrid.addRow().addValue(periodA.getIsoDate()).addValue(programIndicatorD.getUid()).addValue(orgUnitB.getUid()).addValue(200.0);
nonAocGrid.addRow().addValue(periodB.getIsoDate()).addValue(programIndicatorC.getUid()).addValue(orgUnitA.getUid()).addValue(300.0);
when(analyticsService.getAggregatedDataValues(nonAocParams)).thenReturn(nonAocGrid);
FoundDimensionItemValue expected5;
FoundDimensionItemValue expected6;
FoundDimensionItemValue expected7;
CategoryOptionCombo noAoc = null;
expected5 = new FoundDimensionItemValue(orgUnitA, periodA, noAoc, programIndicatorC, 100.0);
expected6 = new FoundDimensionItemValue(orgUnitB, periodA, noAoc, programIndicatorD, 200.0);
expected7 = new FoundDimensionItemValue(orgUnitA, periodB, noAoc, programIndicatorC, 300.0);
// ---------------------------------------------------------------------
// Do the test
// ---------------------------------------------------------------------
Set<DimensionalItemObject> items = Sets.union(aocItems, nonAocItems);
fetcher.init(periods, items);
List<FoundDimensionItemValue> actual = fetcher.getValues(orgUnits);
assertContainsOnly(actual, expected1, expected2, expected3, expected4, expected5, expected6, expected7);
}
use of org.hisp.dhis.common.FoundDimensionItemValue in project dhis2-core by dhis2.
the class PredictionDataConsolidatorTest method initTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@BeforeEach
void initTest() {
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementX = createDataElement('X');
dataElementA.setId(1);
dataElementB.setId(2);
dataElementX.setId(3);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setId(4);
cocB.setId(5);
cocA.setUid("CatOptCombA");
cocB.setUid("CatOptCombB");
aocC = createCategoryOptionCombo('C');
aocD = createCategoryOptionCombo('D');
aocC.setId(6);
aocD.setId(7);
aocC.setUid("AttOptionCC");
aocD.setUid("AttOptionCD");
dataElementOperandA = new DataElementOperand(dataElementA, cocA);
dataElementOperandB = new DataElementOperand(dataElementB, cocB);
dataElementOperandX = new DataElementOperand(dataElementX, cocA);
periodA = createPeriod("202201");
periodB = createPeriod("202202");
periodC = createPeriod("202203");
periodA.setUid("Perio202201");
periodB.setUid("Perio202202");
periodC.setUid("Perio202203");
periodA.setId(10);
periodB.setId(11);
periodC.setId(12);
// OrgUnit hierarchy:
//
// Level 1 - Level 2
// -- A
// -- B ------ E
// -- C ------ F
// -- D ------ G
orgUnitA = createOrganisationUnit("A");
orgUnitB = createOrganisationUnit("B");
orgUnitC = createOrganisationUnit("C");
orgUnitD = createOrganisationUnit("D");
orgUnitE = createOrganisationUnit("E", orgUnitB);
orgUnitF = createOrganisationUnit("F", orgUnitC);
orgUnitG = createOrganisationUnit("G", orgUnitD);
orgUnitA.setId(20);
orgUnitB.setId(21);
orgUnitC.setId(22);
orgUnitD.setId(23);
orgUnitE.setId(24);
orgUnitF.setId(25);
orgUnitG.setId(26);
orgUnitA.setUid("orgUnitAAAA");
orgUnitB.setUid("orgUnitBBBB");
orgUnitC.setUid("orgUnitCCCC");
orgUnitD.setUid("orgUnitDDDD");
orgUnitE.setUid("orgUnitEEEE");
orgUnitF.setUid("orgUnitFFFF");
orgUnitG.setUid("orgUnitGGGG");
orgUnitA.setPath("/orgUnitAAAA");
orgUnitB.setPath("/orgUnitBBBB");
orgUnitC.setPath("/orgUnitCCCC");
orgUnitD.setPath("/orgUnitDDDD");
orgUnitE.setPath("/orgUnitBBBB/orgUnitEEEE");
orgUnitF.setPath("/orgUnitCCCC/orgUnitFFFF");
orgUnitG.setPath("/orgUnitDDDD/orgUnitGGGG");
currentUserOrgUnits = Sets.newHashSet(orgUnitA, orgUnitB, orgUnitC, orgUnitD);
levelOneOrgUnits = Lists.newArrayList(orgUnitA, orgUnitB, orgUnitC, orgUnitD);
// DataValue values:
foundValueA = new FoundDimensionItemValue(orgUnitB, periodA, aocC, dataElementA, 25.0);
foundValueB = new FoundDimensionItemValue(orgUnitC, periodA, aocC, dataElementB, 18.0);
foundValueC = new FoundDimensionItemValue(orgUnitB, periodB, aocC, dataElementOperandA, 10.0);
foundValueD = new FoundDimensionItemValue(orgUnitB, periodB, aocD, dataElementOperandX, 30.0);
foundValueE = new FoundDimensionItemValue(orgUnitB, periodC, aocC, dataElementOperandX, 50.0);
// Analytics values with attribute option combo:
foundValueF = new FoundDimensionItemValue(orgUnitB, periodA, aocC, programIndicatorA, 10.0);
foundValueG = new FoundDimensionItemValue(orgUnitB, periodB, aocC, programIndicatorB, 10.0);
foundValueH = new FoundDimensionItemValue(orgUnitB, periodA, aocD, trackedEntityAttributeA, 10.0);
foundValueI = new FoundDimensionItemValue(orgUnitD, periodA, aocC, programIndicatorA, 10.0);
// Analytics values without attribute option combo:
CategoryOptionCombo noAoc = null;
foundValueJ = new FoundDimensionItemValue(orgUnitD, periodA, noAoc, programAttributeA, 100.0);
foundValueK = new FoundDimensionItemValue(orgUnitD, periodA, noAoc, programAttributeB, 200.0);
foundValueL = new FoundDimensionItemValue(orgUnitD, periodB, noAoc, programAttributeA, 300.0);
// old predictor data values:
dataValueX = new DataValue(dataElementX, periodA, orgUnitB, cocA, aocD, "30.0", "Z", null, null, null, false);
dataValueY = new DataValue(dataElementX, periodC, orgUnitB, cocA, aocC, "40.0", "Z", null, null, null, true);
programA = createProgram('A');
programB = createProgram('B');
programA.setUid("ProgramAAAA");
programB.setUid("ProgramBBBB");
programIndicatorA = createProgramIndicator('A', programA, "expressionA", "filterA");
programIndicatorB = createProgramIndicator('B', programB, "expressionB", "filterB");
programIndicatorA.setUid("ProgramIndA");
programIndicatorB.setUid("ProgramIndB");
trackedEntityAttributeA = createTrackedEntityAttribute('A');
trackedEntityAttributeA.setUid("trackEntAtA");
programAttributeA = new ProgramTrackedEntityAttributeDimensionItem(programA, trackedEntityAttributeA);
programAttributeB = new ProgramTrackedEntityAttributeDimensionItem(programB, trackedEntityAttributeA);
programAttributeA.setUid(programA.getUid() + "." + trackedEntityAttributeA.getUid());
programAttributeA.setUid(programB.getUid() + "." + trackedEntityAttributeA.getUid());
items = Sets.newHashSet(// DataValues (always with AOC):
dataElementA, dataElementOperandA, dataElementOperandB, dataElementOperandX, // Analytics with AOC:
programIndicatorA, programIndicatorB, trackedEntityAttributeA, // Analytics without AOC:
programAttributeA, programAttributeB);
dataValueQueryPeriods = Sets.newHashSet(periodA, periodB, periodC);
analyticsQueryPeriods = Sets.newHashSet(periodA, periodB);
existingOutputPeriods = Sets.newHashSet(periodC);
outputDataElementOperand = dataElementOperandX;
when(dataValueFetcher.setIncludeDeleted(true)).thenReturn(dataValueFetcher);
when(dataValueFetcher.setIncludeDescendants(INCLUDE_DESCENDANTS)).thenReturn(dataValueFetcher);
consolidator = new PredictionDataConsolidator(items, INCLUDE_DESCENDANTS, dataValueFetcher, analyticsFetcher);
consolidator.setAnalyticsBatchFetchSize(3);
}
use of org.hisp.dhis.common.FoundDimensionItemValue in project dhis2-core by dhis2.
the class PredictionDataValueFetcherTest method initTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@BeforeEach
void initTest() {
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementX = createDataElement('X');
dataElementA.setId(1);
dataElementB.setId(2);
dataElementX.setId(3);
dataElements = Sets.newHashSet(dataElementA, dataElementB);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setId(4);
cocB.setId(5);
cocA.setUid("CatOptCombA");
cocB.setUid("CatOptCombB");
aocC = createCategoryOptionCombo('C');
aocD = createCategoryOptionCombo('D');
aocC.setId(6);
aocD.setId(7);
aocC.setUid("AttOptionCC");
aocD.setUid("AttOptionCD");
dataElementOperandA = new DataElementOperand(dataElementA, cocA);
dataElementOperandB = new DataElementOperand(dataElementB, cocB);
dataElementOperandX = new DataElementOperand(dataElementX, cocA);
dataElementOperands = Sets.newHashSet(dataElementOperandA, dataElementOperandB, dataElementOperandX);
periodA = createPeriod("202201");
periodB = createPeriod("202202");
periodC = createPeriod("202203");
periodA.setUid("Perio202201");
periodB.setUid("Perio202202");
periodC.setUid("Perio202203");
periodA.setId(10);
periodB.setId(11);
periodC.setId(12);
queryPeriods = Sets.newHashSet(periodA, periodB, periodC);
outputPeriods = Sets.newHashSet(periodC);
// OrgUnit hierarchy:
//
// Level 1 - Level 2
// -- A
// -- B ------ E
// -- C ------ F
// -- D ------ G
orgUnitA = createOrganisationUnit("A");
orgUnitB = createOrganisationUnit("B");
orgUnitC = createOrganisationUnit("C");
orgUnitD = createOrganisationUnit("D");
orgUnitE = createOrganisationUnit("E", orgUnitB);
orgUnitF = createOrganisationUnit("F", orgUnitC);
orgUnitG = createOrganisationUnit("G", orgUnitD);
orgUnitA.setId(20);
orgUnitB.setId(21);
orgUnitC.setId(22);
orgUnitD.setId(23);
orgUnitE.setId(24);
orgUnitF.setId(25);
orgUnitG.setId(26);
orgUnitA.setUid("orgUnitAAAA");
orgUnitB.setUid("orgUnitBBBB");
orgUnitC.setUid("orgUnitCCCC");
orgUnitD.setUid("orgUnitDDDD");
orgUnitE.setUid("orgUnitEEEE");
orgUnitF.setUid("orgUnitFFFF");
orgUnitG.setUid("orgUnitGGGG");
orgUnitA.setPath("/orgUnitAAAA");
orgUnitB.setPath("/orgUnitBBBB");
orgUnitC.setPath("/orgUnitCCCC");
orgUnitD.setPath("/orgUnitDDDD");
orgUnitE.setPath("/orgUnitBBBB/orgUnitEEEE");
orgUnitF.setPath("/orgUnitCCCC/orgUnitFFFF");
orgUnitG.setPath("/orgUnitDDDD/orgUnitGGGG");
currentUserOrgUnits = Sets.newHashSet(orgUnitA, orgUnitB, orgUnitC, orgUnitD);
levelOneOrgUnits = Lists.newArrayList(orgUnitA, orgUnitB, orgUnitC, orgUnitD);
dataValueA = new DataValue(dataElementA, periodA, orgUnitB, cocA, aocC, "10.0", "Y", null, null, null, false);
dataValueB = new DataValue(dataElementA, periodA, orgUnitB, cocB, aocC, "15.0", "Y", null, null, null, false);
dataValueX = new DataValue(dataElementX, periodA, orgUnitB, cocA, aocD, "30.0", "Z", null, null, null, false);
dataValueY = new DataValue(dataElementX, periodC, orgUnitB, cocA, aocC, "40.0", "Z", null, null, null, true);
dataValueZ = new DataValue(dataElementX, periodC, orgUnitE, cocA, aocC, "50.0", "Z", null, null, null, false);
dataValueC = new DataValue(dataElementB, periodB, orgUnitC, cocA, aocC, "18.0", "Y", null, null, null, false);
dataValueD = new DataValue(dataElementB, periodB, orgUnitC, cocB, aocC, "20.0", "Y", null, null, null, true);
deflatedDataValueA = new DeflatedDataValue(dataValueA);
deflatedDataValueB = new DeflatedDataValue(dataValueB);
deflatedDataValueX = new DeflatedDataValue(dataValueX);
deflatedDataValueY = new DeflatedDataValue(dataValueY);
deflatedDataValueZ = new DeflatedDataValue(dataValueZ);
deflatedDataValueC = new DeflatedDataValue(dataValueC);
deflatedDataValueD = new DeflatedDataValue(dataValueD);
foundValueA = new FoundDimensionItemValue(orgUnitB, periodA, aocC, dataElementA, 25.0);
foundValueB = new FoundDimensionItemValue(orgUnitC, periodB, aocC, dataElementB, 18.0);
foundValueC = new FoundDimensionItemValue(orgUnitB, periodA, aocC, dataElementOperandA, 10.0);
foundValueD = new FoundDimensionItemValue(orgUnitB, periodA, aocD, dataElementOperandX, 30.0);
foundValueE = new FoundDimensionItemValue(orgUnitB, periodC, aocC, dataElementOperandX, 50.0);
fetcher = new PredictionDataValueFetcher(dataValueService, categoryService);
}
Aggregations