use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getSectionDataSetReport.
private List<Grid> getSectionDataSetReport(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters, boolean selectedUnitOnly) {
I18nFormat format = i18nManager.getI18nFormat();
I18n i18n = i18nManager.getI18n();
List<Section> sections = new ArrayList<>(dataSet.getSections());
sections.sort(new SectionOrderComparator());
Map<String, Object> valueMap = dataSetReportStore.getAggregatedValues(dataSet, periods, unit, filters);
Map<String, Object> subTotalMap = dataSetReportStore.getAggregatedSubTotals(dataSet, periods, unit, filters);
Map<String, Object> totalMap = dataSetReportStore.getAggregatedTotals(dataSet, periods, unit, filters);
List<Grid> grids = new ArrayList<>();
for (Section section : sections) {
for (CategoryCombo categoryCombo : section.getCategoryCombos()) {
Grid grid = new ListGrid().setTitle(section.getName() + SPACE + categoryCombo.getName()).setSubtitle(unit.getName() + SPACE + formatPeriods(periods, format));
// -----------------------------------------------------------------
// Grid headers
// -----------------------------------------------------------------
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
for (CategoryOptionCombo optionCombo : optionCombos) {
grid.addHeader(new GridHeader(optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (CategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
grid.addHeader(new GridHeader(categoryOption.getName(), false, false));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
grid.addHeader(new GridHeader(TOTAL_HEADER, false, false));
}
// -----------------------------------------------------------------
// Grid values
// -----------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(section.getDataElementsByCategoryCombo(categoryCombo));
FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
for (DataElement dataElement : dataElements) {
grid.addRow();
// Data
grid.addValue(new GridValue(dataElement.getFormNameFallback()));
for (// Values
CategoryOptionCombo optionCombo : // Values
optionCombos) {
Map<Object, Object> attributes = new HashMap<>();
attributes.put(ATTR_DE, dataElement.getUid());
attributes.put(ATTR_CO, optionCombo.getUid());
Object value;
if (selectedUnitOnly) {
value = getSelectedUnitValue(dataElement, periods, unit, optionCombo);
} else {
value = valueMap.get(dataElement.getUid() + SEPARATOR + optionCombo.getUid());
}
grid.addValue(new GridValue(value, attributes));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (CategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
Object value = subTotalMap.get(dataElement.getUid() + SEPARATOR + categoryOption.getUid());
grid.addValue(new GridValue(value));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
Object value = totalMap.get(String.valueOf(dataElement.getUid()));
grid.addValue(new GridValue(value));
}
}
grids.add(grid);
}
}
return grids;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class AnalyticsControllerTest method buildMockGrid.
private Grid buildMockGrid() {
Grid grid = new ListGrid();
grid.addHeader(new GridHeader("a"));
grid.addHeader(new GridHeader("b"));
grid.addHeader(new GridHeader("c"));
grid.addHeader(new GridHeader("d"));
grid.addRow();
grid.addValue("de1");
grid.addValue("ou2");
grid.addValue("pe1");
grid.addValue(3);
grid.addRow();
grid.addValue("de2");
grid.addValue("ou3");
grid.addValue("pe2");
grid.addValue(5);
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class AnalyticsValidationServiceTest method newGrid.
// -------------------------------------------------------------------------
// Local convenience methods
// -------------------------------------------------------------------------
/**
* Make a data grid for MockAnalyticsService to return.
*
* @param dataElementVal Program data element value
* @param teAttributeVal Tracked entity attribute value
* @param piVal Program Indicator value
* @param indicatorVal Indicator value
* @return the Grid, as would be returned by analytics
*/
private Grid newGrid(double dataElementVal, double teAttributeVal, double piVal, double indicatorVal) {
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
grid.addHeader(new GridHeader(VALUE_ID));
grid.addRow();
grid.addValue("ProgramABCD.DataElement");
grid.addValue(orgUnitA.getUid());
grid.addValue("HllvX50cXC0");
grid.addValue(new Double(dataElementVal));
grid.addRow();
grid.addValue("ProgramABCD.TEAttribute");
grid.addValue(orgUnitA.getUid());
grid.addValue("HllvX50cXC0");
grid.addValue(new Double(teAttributeVal));
grid.addRow();
grid.addValue("ProgramIndA");
grid.addValue(orgUnitA.getUid());
grid.addValue("HllvX50cXC0");
grid.addValue(new Double(piVal));
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid 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.system.grid.ListGrid in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getSectionDataSetReport.
@Override
public List<Grid> getSectionDataSetReport(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions, boolean selectedUnitOnly, I18nFormat format, I18n i18n) {
List<Section> sections = new ArrayList<>(dataSet.getSections());
Collections.sort(sections, new SectionOrderComparator());
Map<String, Object> valueMap = dataSetReportStore.getAggregatedValues(dataSet, period, unit, dimensions);
Map<String, Object> subTotalMap = dataSetReportStore.getAggregatedSubTotals(dataSet, period, unit, dimensions);
Map<String, Object> totalMap = dataSetReportStore.getAggregatedTotals(dataSet, period, unit, dimensions);
List<Grid> grids = new ArrayList<>();
for (Section section : sections) {
for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
Grid grid = new ListGrid().setTitle(section.getName() + SPACE + categoryCombo.getName()).setSubtitle(unit.getName() + SPACE + format.formatPeriod(period));
// -----------------------------------------------------------------
// Grid headers
// -----------------------------------------------------------------
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
for (DataElementCategoryOptionCombo optionCombo : optionCombos) {
grid.addHeader(new GridHeader(optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
grid.addHeader(new GridHeader(categoryOption.getName(), false, false));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
grid.addHeader(new GridHeader(TOTAL_HEADER, false, false));
}
// -----------------------------------------------------------------
// Grid values
// -----------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(section.getDataElementsByCategoryCombo(categoryCombo));
FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
for (DataElement dataElement : dataElements) {
grid.addRow();
// Data element name
grid.addValue(new GridValue(dataElement.getFormNameFallback()));
for (// Values
DataElementCategoryOptionCombo optionCombo : // Values
optionCombos) {
Map<Object, Object> attributes = new HashMap<>();
attributes.put(ATTR_DE, dataElement.getUid());
attributes.put(ATTR_CO, optionCombo.getUid());
Object value = null;
if (selectedUnitOnly) {
DataValue dataValue = dataValueService.getDataValue(dataElement, period, unit, optionCombo);
value = dataValue != null && dataValue.getValue() != null ? Double.parseDouble(dataValue.getValue()) : null;
} else {
value = valueMap.get(dataElement.getUid() + SEPARATOR + optionCombo.getUid());
}
grid.addValue(new GridValue(value, attributes));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (DataElementCategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
Object value = subTotalMap.get(dataElement.getUid() + SEPARATOR + categoryOption.getUid());
grid.addValue(new GridValue(value));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
Object value = totalMap.get(String.valueOf(dataElement.getUid()));
grid.addValue(new GridValue(value));
}
}
grids.add(grid);
}
}
return grids;
}
Aggregations