use of org.hisp.dhis.category.CategoryCombo 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.category.CategoryCombo in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getDefaultDataSetReport.
private List<Grid> getDefaultDataSetReport(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters, boolean selectedUnitOnly) {
ListMap<CategoryCombo, DataElement> map = new ListMap<>();
for (DataSetElement element : dataSet.getDataSetElements()) {
map.putValue(element.getResolvedCategoryCombo(), element.getDataElement());
}
DataSet tmpDataSet = new DataSet(dataSet.getName(), dataSet.getShortName(), dataSet.getPeriodType());
tmpDataSet.setDataSetElements(dataSet.getDataSetElements());
for (CategoryCombo categoryCombo : map.keySet()) {
List<DataElement> dataElements = map.get(categoryCombo);
String name = categoryCombo.isDefault() ? dataSet.getName() : categoryCombo.getName();
Section section = new Section(name, dataSet, dataElements, null);
tmpDataSet.getSections().add(section);
}
return getSectionDataSetReport(tmpDataSet, periods, unit, filters, selectedUnitOnly);
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategoryCombo.
/**
* @param categoryComboUniqueIdentifier A unique character to identify the
* category option combo.
* @param categories the categories category options.
* @return CategoryOptionCombo
*/
public static CategoryCombo createCategoryCombo(char categoryComboUniqueIdentifier, Category... categories) {
CategoryCombo categoryCombo = new CategoryCombo("CategoryCombo" + categoryComboUniqueIdentifier, DataDimensionType.DISAGGREGATION);
categoryCombo.setAutoFields();
for (Category category : categories) {
categoryCombo.getCategories().add(category);
}
return categoryCombo;
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidationsWithCatCombo.
@Test
void testPreheatValidationsWithCatCombo() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
CategoryCombo categoryCombo = manager.getByName(CategoryCombo.class, "default");
categoryCombo.setUid("p0KPaWEg3cf");
manager.update(categoryCombo);
OptionSet optionSet = new OptionSet("OptionSet: pQYCiuosBnZ", ValueType.TEXT);
optionSet.setAutoFields();
optionSet.setUid("pQYCiuosBnZ");
manager.save(optionSet);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.hasErrorReports());
validate.forEachErrorReport(errorReport -> {
assertTrue(errorReport instanceof PreheatErrorReport);
PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
if (preheatErrorReport.getValue() instanceof CategoryCombo) {
fail();
} else if (preheatErrorReport.getValue() instanceof User) {
assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
} else if (preheatErrorReport.getValue() instanceof OptionSet) {
fail();
}
});
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidations.
@Test
void testPreheatValidations() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.isEmpty());
assertTrue(validate.hasErrorReports());
validate.forEachErrorReport(errorReport -> {
assertTrue(errorReport instanceof PreheatErrorReport);
PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
if (preheatErrorReport.getValue() instanceof CategoryCombo) {
assertEquals("p0KPaWEg3cf", preheatErrorReport.getObjectReference().getUid());
} else if (preheatErrorReport.getValue() instanceof User) {
assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
} else if (preheatErrorReport.getValue() instanceof OptionSet) {
assertEquals("pQYCiuosBnZ", preheatErrorReport.getObjectReference().getUid());
}
});
}
Aggregations