use of org.hisp.dhis.webapi.webdomain.form.Category in project dhis2-core by dhis2.
the class FormUtils method getCategoryCombo.
private static CategoryCombo getCategoryCombo(DataSet dataset, Set<OrganisationUnit> userOrganisationUnits) {
if (dataset.hasCategoryCombo()) {
DataElementCategoryCombo categoryCombo = dataset.getCategoryCombo();
CategoryCombo catCombo = new CategoryCombo();
catCombo.setId(categoryCombo.getUid());
List<DataElementCategory> cats = categoryCombo.getCategories();
if (cats != null && cats.size() > 0) {
for (DataElementCategory cat : cats) {
if (cat.getAccess() != null && !cat.getAccess().isRead()) {
continue;
}
Category c = new Category();
c.setId(cat.getUid());
c.setLabel(cat.getName());
List<DataElementCategoryOption> options = cat.getCategoryOptions();
if (options != null && options.size() > 0) {
for (DataElementCategoryOption option : options) {
if (option.getAccess() != null && !option.getAccess().isRead()) {
continue;
}
Option o = new Option();
o.setId(option.getUid());
o.setLabel(option.getDisplayName());
o.setStartDate(option.getStartDate());
o.setEndDate(option.getEndDate());
Set<OrganisationUnit> catOptionOUs = option.getOrganisationUnits();
if (userOrganisationUnits == null || userOrganisationUnits.isEmpty() || catOptionOUs == null || catOptionOUs.isEmpty()) {
c.getOptions().add(o);
} else if (userOrganisationUnits != null && catOptionOUs != null && !Collections.disjoint(userOrganisationUnits, catOptionOUs)) {
HashSet<OrganisationUnit> organisationUnits = new HashSet<>();
catOptionOUs.stream().filter(ou -> userOrganisationUnits.contains(ou)).forEach(ou -> {
organisationUnits.add(ou);
organisationUnits.addAll(getChildren(ou, new HashSet<>()));
});
o.setOrganisationUnits(organisationUnits);
c.getOptions().add(o);
}
}
}
catCombo.getCategories().add(c);
}
}
return catCombo;
}
return null;
}
Aggregations