Search in sources :

Example 1 with CategoryCombo

use of org.hisp.dhis.webapi.webdomain.form.CategoryCombo 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;
}
Also used : SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) Category(org.hisp.dhis.webapi.webdomain.form.Category) ValueType(org.hisp.dhis.common.ValueType) DataSet(org.hisp.dhis.dataset.DataSet) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) HashMap(java.util.HashMap) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) HashSet(java.util.HashSet) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) Map(java.util.Map) Field(org.hisp.dhis.webapi.webdomain.form.Field) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Option(org.hisp.dhis.webapi.webdomain.form.Option) Collection(java.util.Collection) Set(java.util.Set) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) NameableObjectUtils(org.hisp.dhis.common.NameableObjectUtils) ProgramStage(org.hisp.dhis.program.ProgramStage) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) DataValue(org.hisp.dhis.datavalue.DataValue) Group(org.hisp.dhis.webapi.webdomain.form.Group) Form(org.hisp.dhis.webapi.webdomain.form.Form) Collections(java.util.Collections) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Category(org.hisp.dhis.webapi.webdomain.form.Category) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.webapi.webdomain.form.Option) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 NameableObjectUtils (org.hisp.dhis.common.NameableObjectUtils)1 ValueType (org.hisp.dhis.common.ValueType)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)1 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)1 DataSet (org.hisp.dhis.dataset.DataSet)1 Section (org.hisp.dhis.dataset.Section)1 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)1 DataValue (org.hisp.dhis.datavalue.DataValue)1