use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DataApprovalServiceTest method setUpCategories.
// -------------------------------------------------------------------------
// Categories supportive methods
// -------------------------------------------------------------------------
private void setUpCategories() {
optionA = new DataElementCategoryOption("CategoryOptionA");
optionB = new DataElementCategoryOption("CategoryOptionB");
optionC = new DataElementCategoryOption("CategoryOptionC");
optionD = new DataElementCategoryOption("CategoryOptionD");
optionE = new DataElementCategoryOption("CategoryOptionE");
optionF = new DataElementCategoryOption("CategoryOptionF");
optionG = new DataElementCategoryOption("CategoryOptionG");
optionH = new DataElementCategoryOption("CategoryOptionH");
categoryService.addDataElementCategoryOption(optionA);
categoryService.addDataElementCategoryOption(optionB);
categoryService.addDataElementCategoryOption(optionC);
categoryService.addDataElementCategoryOption(optionD);
categoryService.addDataElementCategoryOption(optionE);
categoryService.addDataElementCategoryOption(optionF);
categoryService.addDataElementCategoryOption(optionG);
categoryService.addDataElementCategoryOption(optionH);
categoryA = createDataElementCategory('A', optionA, optionB, optionC, optionD);
categoryB = createDataElementCategory('B', optionE, optionF, optionG, optionH);
categoryService.addDataElementCategory(categoryA);
categoryService.addDataElementCategory(categoryB);
categoryComboA = createCategoryCombo('A', categoryA, categoryB);
categoryService.addDataElementCategoryCombo(categoryComboA);
optionComboAE = createCategoryOptionCombo('A', categoryComboA, optionA, optionE);
optionComboAF = createCategoryOptionCombo('B', categoryComboA, optionA, optionF);
optionComboAG = createCategoryOptionCombo('C', categoryComboA, optionA, optionG);
optionComboAH = createCategoryOptionCombo('D', categoryComboA, optionA, optionH);
optionComboBE = createCategoryOptionCombo('E', categoryComboA, optionB, optionE);
optionComboBF = createCategoryOptionCombo('F', categoryComboA, optionB, optionF);
optionComboBG = createCategoryOptionCombo('G', categoryComboA, optionB, optionG);
optionComboBH = createCategoryOptionCombo('H', categoryComboA, optionB, optionH);
optionComboCE = createCategoryOptionCombo('I', categoryComboA, optionC, optionE);
optionComboCF = createCategoryOptionCombo('J', categoryComboA, optionC, optionF);
optionComboCG = createCategoryOptionCombo('K', categoryComboA, optionC, optionG);
optionComboCH = createCategoryOptionCombo('L', categoryComboA, optionC, optionH);
optionComboDE = createCategoryOptionCombo('M', categoryComboA, optionD, optionE);
optionComboDF = createCategoryOptionCombo('N', categoryComboA, optionD, optionF);
optionComboDG = createCategoryOptionCombo('O', categoryComboA, optionD, optionG);
optionComboDH = createCategoryOptionCombo('P', categoryComboA, optionD, optionH);
categoryService.addDataElementCategoryOptionCombo(optionComboAE);
categoryService.addDataElementCategoryOptionCombo(optionComboAF);
categoryService.addDataElementCategoryOptionCombo(optionComboAG);
categoryService.addDataElementCategoryOptionCombo(optionComboAH);
categoryService.addDataElementCategoryOptionCombo(optionComboBE);
categoryService.addDataElementCategoryOptionCombo(optionComboBF);
categoryService.addDataElementCategoryOptionCombo(optionComboBG);
categoryService.addDataElementCategoryOptionCombo(optionComboBH);
categoryService.addDataElementCategoryOptionCombo(optionComboCE);
categoryService.addDataElementCategoryOptionCombo(optionComboCF);
categoryService.addDataElementCategoryOptionCombo(optionComboCG);
categoryService.addDataElementCategoryOptionCombo(optionComboCH);
categoryService.addDataElementCategoryOptionCombo(optionComboDE);
categoryService.addDataElementCategoryOptionCombo(optionComboDF);
categoryService.addDataElementCategoryOptionCombo(optionComboDG);
categoryService.addDataElementCategoryOptionCombo(optionComboDH);
groupAB = createCategoryOptionGroup('A', optionA, optionB);
groupCD = createCategoryOptionGroup('C', optionC, optionD);
groupEF = createCategoryOptionGroup('E', optionE, optionF);
groupGH = createCategoryOptionGroup('G', optionG, optionH);
categoryService.saveCategoryOptionGroup(groupAB);
categoryService.saveCategoryOptionGroup(groupCD);
categoryService.saveCategoryOptionGroup(groupEF);
categoryService.saveCategoryOptionGroup(groupGH);
groupSetABCD = new CategoryOptionGroupSet("GroupSetABCD");
groupSetEFGH = new CategoryOptionGroupSet("GroupSetEFGH");
categoryService.saveCategoryOptionGroupSet(groupSetABCD);
categoryService.saveCategoryOptionGroupSet(groupSetEFGH);
groupSetABCD.addCategoryOptionGroup(groupAB);
groupSetABCD.addCategoryOptionGroup(groupCD);
groupSetEFGH.addCategoryOptionGroup(groupAB);
groupSetEFGH.addCategoryOptionGroup(groupEF);
groupAB.getGroupSets().add(groupSetABCD);
groupCD.getGroupSets().add(groupSetABCD);
groupEF.getGroupSets().add(groupSetEFGH);
groupGH.getGroupSets().add(groupSetEFGH);
level2ABCD = new DataApprovalLevel("level2ABCD", 2, groupSetABCD);
level2EFGH = new DataApprovalLevel("level2EFGH", 2, groupSetEFGH);
dataApprovalLevelService.addDataApprovalLevel(level2EFGH);
dataApprovalLevelService.addDataApprovalLevel(level2ABCD);
workflow12A_H = new DataApprovalWorkflow("workflow12A_H", periodType, newHashSet(level1, level2, level2ABCD, level2EFGH));
dataApprovalService.addWorkflow(workflow12A_H);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption 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