Search in sources :

Example 46 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class MobileClientController method getOrgUnitsForUser2_8.

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public OrgUnits getOrgUnitsForUser2_8(HttpServletRequest request) throws NotAllowedException {
    User user = currentUserService.getCurrentUser();
    if (user == null) {
        throw NotAllowedException.NO_USER;
    }
    Collection<OrganisationUnit> units = user.getOrganisationUnits();
    List<MobileOrgUnitLinks> unitList = new ArrayList<>();
    for (OrganisationUnit unit : units) {
        unitList.add(getOrgUnit(unit, request));
    }
    OrgUnits orgUnits = new OrgUnits(unitList);
    orgUnits.setClientVersion(DataStreamSerializable.TWO_POINT_EIGHT);
    return orgUnits;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MobileOrgUnitLinks(org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList) OrgUnits(org.hisp.dhis.api.mobile.model.OrgUnits) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 47 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit 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)

Example 48 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class GetOrganisationUnitChildrenAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    OrganisationUnit unit = organisationUnitService.getOrganisationUnit(id);
    organisationUnits = new ArrayList<>(unit.getChildren());
    Collections.sort(organisationUnits);
    if (usePaging) {
        this.paging = createPaging(organisationUnits.size());
        organisationUnits = organisationUnits.subList(paging.getStartPos(), paging.getEndPos());
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Example 49 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class GetOrganisationUnitTreeAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    version = getVersionString();
    username = currentUserService.getCurrentUsername();
    User user = currentUserService.getCurrentUser();
    if (user != null && user.hasOrganisationUnit()) {
        rootOrganisationUnits = new ArrayList<>(user.getOrganisationUnits());
    } else if (currentUserService.currentUserIsSuper() || user == null) {
        rootOrganisationUnits = new ArrayList<>(organisationUnitService.getRootOrganisationUnits());
    }
    if (byName != null) {
        List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName(byName);
        if (!organisationUnitByName.isEmpty()) {
            OrganisationUnit child = organisationUnitByName.get(0);
            organisationUnits.add(child);
            OrganisationUnit parent = child.getParent();
            if (parent != null) {
                do {
                    organisationUnits.add(parent);
                    organisationUnits.addAll(parent.getChildren());
                } while ((parent = parent.getParent()) != null);
            }
            return "partial";
        }
    }
    if (leafId != null) {
        OrganisationUnit leaf = organisationUnitService.getOrganisationUnit(leafId);
        if (leaf != null) {
            organisationUnits.add(leaf);
            organisationUnits.addAll(leaf.getChildren());
            for (OrganisationUnit organisationUnit : leaf.getAncestors()) {
                organisationUnits.add(organisationUnit);
                organisationUnits.addAll(organisationUnit.getChildren());
            }
        }
        return "partial";
    }
    if (parentId != null) {
        OrganisationUnit parent = organisationUnitService.getOrganisationUnit(parentId);
        if (parent != null) {
            organisationUnits.addAll(parent.getChildren());
        }
        return "partial";
    }
    if (!versionOnly && !rootOrganisationUnits.isEmpty()) {
        Integer offlineLevels = getOfflineOrganisationUnitLevels();
        for (OrganisationUnit unit : rootOrganisationUnits) {
            organisationUnits.addAll(organisationUnitService.getOrganisationUnitWithChildren(unit.getId(), offlineLevels));
        }
    }
    Collection<?> intersection = org.apache.commons.collections.CollectionUtils.intersection(organisationUnitService.getRootOrganisationUnits(), rootOrganisationUnits);
    if (intersection.size() > 0) {
        realRoot = true;
    }
    Collections.sort(rootOrganisationUnits);
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList)

Example 50 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DataApproval method getLowestApproval.

// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
/**
     * Finds the lowest level (if any) at which data would be approved.
     */
public static DataApproval getLowestApproval(DataApproval dataApproval) {
    OrganisationUnit orgUnit = dataApproval.getOrganisationUnit();
    List<DataApprovalLevel> approvalLevels = dataApproval.getWorkflow().getSortedLevels();
    Collections.reverse(approvalLevels);
    DataApproval da = null;
    for (DataApprovalLevel approvalLevel : approvalLevels) {
        int orgUnitLevel = orgUnit.getLevel();
        if (approvalLevel.getOrgUnitLevel() <= orgUnitLevel) {
            if (approvalLevel.getOrgUnitLevel() < orgUnitLevel) {
                orgUnit = orgUnit.getAncestors().get(approvalLevel.getOrgUnitLevel() - 1);
            }
            da = new DataApproval(approvalLevel, dataApproval.getWorkflow(), dataApproval.getPeriod(), orgUnit, dataApproval.getAttributeOptionCombo());
            break;
        }
    }
    return da;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)321 Period (org.hisp.dhis.period.Period)74 Test (org.junit.Test)63 ArrayList (java.util.ArrayList)62 User (org.hisp.dhis.user.User)57 Date (java.util.Date)53 HashSet (java.util.HashSet)53 DataSet (org.hisp.dhis.dataset.DataSet)53 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 DataElement (org.hisp.dhis.dataelement.DataElement)50 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)37 List (java.util.List)36 CurrentUserService (org.hisp.dhis.user.CurrentUserService)29 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)23 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)23 Program (org.hisp.dhis.program.Program)22 ClassPathResource (org.springframework.core.io.ClassPathResource)20