Search in sources :

Example 1 with Option

use of org.hisp.dhis.webapi.webdomain.form.Option in project dhis2-core by dhis2.

the class FormUtils method getCategoryCombo.

private static CategoryCombo getCategoryCombo(DataSet dataset, Set<OrganisationUnit> userOrganisationUnits) {
    if (dataset.hasCategoryCombo()) {
        org.hisp.dhis.category.CategoryCombo categoryCombo = dataset.getCategoryCombo();
        CategoryCombo catCombo = new CategoryCombo();
        catCombo.setId(categoryCombo.getUid());
        List<org.hisp.dhis.category.Category> cats = categoryCombo.getCategories();
        if (cats != null && cats.size() > 0) {
            for (org.hisp.dhis.category.Category cat : cats) {
                if (cat.getAccess() != null && !cat.getAccess().isRead()) {
                    continue;
                }
                Category c = new Category();
                c.setId(cat.getUid());
                c.setLabel(cat.getName());
                List<CategoryOption> options = cat.getCategoryOptions();
                if (options != null && options.size() > 0) {
                    for (CategoryOption 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) CategoryOption(org.hisp.dhis.category.CategoryOption) ValueType(org.hisp.dhis.common.ValueType) DataSet(org.hisp.dhis.dataset.DataSet) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) Map(java.util.Map) Field(org.hisp.dhis.webapi.webdomain.form.Field) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Option(org.hisp.dhis.webapi.webdomain.form.Option) Collection(java.util.Collection) Set(java.util.Set) NameableObjectUtils(org.hisp.dhis.common.NameableObjectUtils) ProgramStage(org.hisp.dhis.program.ProgramStage) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValue(org.hisp.dhis.datavalue.DataValue) Group(org.hisp.dhis.webapi.webdomain.form.Group) Collections(java.util.Collections) Form(org.hisp.dhis.webapi.webdomain.form.Form) Assert(org.springframework.util.Assert) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Category(org.hisp.dhis.webapi.webdomain.form.Category) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOption(org.hisp.dhis.category.CategoryOption) Option(org.hisp.dhis.webapi.webdomain.form.Option) 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 StringUtils (org.apache.commons.lang3.StringUtils)1 CategoryOption (org.hisp.dhis.category.CategoryOption)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 NameableObjectUtils (org.hisp.dhis.common.NameableObjectUtils)1 ValueType (org.hisp.dhis.common.ValueType)1 DataElement (org.hisp.dhis.dataelement.DataElement)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 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1