use of org.hisp.dhis.dataset.comparator.SectionOrderComparator in project dhis2-core by dhis2.
the class LoadFormAction method getSectionForm.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getSectionForm(Collection<DataElement> dataElements, DataSet dataSet) {
sections = new ArrayList<>(dataSet.getSections());
Collections.sort(sections, new SectionOrderComparator());
for (Section section : sections) {
Set<Integer> categoryComboIds = new HashSet<>();
for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
categoryComboIds.add(categoryCombo.getId());
sectionCategoryComboDataElements.put(section.getId() + "-" + categoryCombo.getId(), section.getDataElementsByCategoryCombo(categoryCombo));
}
if (!categoryComboIds.isEmpty()) {
sectionCombos.put(section.getId(), categoryComboIds);
}
for (DataElementOperand operand : section.getGreyedFields()) {
if (operand != null && operand.getDataElement() != null && operand.getCategoryOptionCombo() != null) {
greyedFields.put(operand.getDataElement().getUid() + ":" + operand.getCategoryOptionCombo().getUid(), true);
}
}
}
}
use of org.hisp.dhis.dataset.comparator.SectionOrderComparator 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