Search in sources :

Example 66 with OrganisationUnit

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

the class RemoveMinMaxLimitsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    DataElement dataElement = dataElementService.getDataElement(dataElementId);
    DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptionComboId);
    MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement(organisationUnit, dataElement, optionCombo);
    if (minMaxDataElement != null) {
        minMaxDataElementService.deleteMinMaxDataElement(minMaxDataElement);
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 67 with OrganisationUnit

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

the class AnalyticsUtils method getDimensionMetadataItemMap.

/**
     * Returns a mapping between identifiers and meta data items for the given query.
     *
     * @param params the data query parameters.
     * @return a mapping between identifiers and meta data items.
     */
public static Map<String, MetadataItem> getDimensionMetadataItemMap(DataQueryParams params) {
    List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
    Map<String, MetadataItem> map = new HashMap<>();
    Calendar calendar = PeriodType.getCalendar();
    for (DimensionalObject dimension : dimensions) {
        for (DimensionalItemObject item : dimension.getItems()) {
            if (DimensionType.PERIOD == dimension.getDimensionType() && !calendar.isIso8601()) {
                Period period = (Period) item;
                DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
                map.put(period.getPeriodType().getIsoDate(dateTimeUnit), new MetadataItem(period.getDisplayName()));
            } else {
                String legendSet = item.hasLegendSet() ? item.getLegendSet().getUid() : null;
                map.put(item.getDimensionItem(), new MetadataItem(item.getDisplayProperty(params.getDisplayProperty()), legendSet));
            }
            if (DimensionType.ORGANISATION_UNIT == dimension.getDimensionType() && params.isHierarchyMeta()) {
                OrganisationUnit unit = (OrganisationUnit) item;
                for (OrganisationUnit ancestor : unit.getAncestors()) {
                    map.put(ancestor.getUid(), new MetadataItem(ancestor.getDisplayProperty(params.getDisplayProperty())));
                }
            }
            if (DimensionItemType.DATA_ELEMENT == item.getDimensionItemType()) {
                DataElement dataElement = (DataElement) item;
                for (DataElementCategoryOptionCombo coc : dataElement.getCategoryOptionCombos()) {
                    map.put(coc.getUid(), new MetadataItem(coc.getDisplayProperty(params.getDisplayProperty())));
                }
            }
        }
        map.put(dimension.getDimension(), new MetadataItem(dimension.getDisplayProperty(params.getDisplayProperty())));
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DataElement(org.hisp.dhis.dataelement.DataElement) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 68 with OrganisationUnit

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

the class AnalyticsUtils method getDebugDataSql.

/**
     * Returns an SQL statement for retrieving raw data values for
     * an aggregate query.
     * 
     * @param params the data query parameters.
     * @return an SQL statement.
     */
public static String getDebugDataSql(DataQueryParams params) {
    List<DimensionalItemObject> dataElements = new ArrayList<>(NameableObjectUtils.getCopyNullSafe(params.getDataElements()));
    dataElements.addAll(NameableObjectUtils.getCopyNullSafe(params.getFilterDataElements()));
    List<DimensionalItemObject> periods = new ArrayList<>(NameableObjectUtils.getCopyNullSafe(params.getPeriods()));
    periods.addAll(NameableObjectUtils.getCopyNullSafe(params.getFilterPeriods()));
    List<DimensionalItemObject> orgUnits = new ArrayList<>(NameableObjectUtils.getCopyNullSafe(params.getOrganisationUnits()));
    orgUnits.addAll(NameableObjectUtils.getCopyNullSafe(params.getFilterOrganisationUnits()));
    if (dataElements.isEmpty() || periods.isEmpty() || orgUnits.isEmpty()) {
        throw new IllegalQueryException("Query must contain at least one data element, one period and one organisation unit");
    }
    String sql = "select de.name as de_name, de.uid as de_uid, de.dataelementid as de_id, pe.startdate as start_date, pe.enddate as end_date, pt.name as pt_name, " + "ou.name as ou_name, ou.uid as ou_uid, ou.organisationunitid as ou_id, " + "coc.name as coc_name, coc.uid as coc_uid, coc.categoryoptioncomboid as coc_id, " + "aoc.name as aoc_name, aoc.uid as aoc_uid, aoc.categoryoptioncomboid as aoc_id, dv.value as datavalue " + "from datavalue dv " + "inner join dataelement de on dv.dataelementid = de.dataelementid " + "inner join period pe on dv.periodid = pe.periodid " + "inner join periodtype pt on pe.periodtypeid = pt.periodtypeid " + "inner join organisationunit ou on dv.sourceid = ou.organisationunitid " + "inner join categoryoptioncombo coc on dv.categoryoptioncomboid = coc.categoryoptioncomboid " + "inner join categoryoptioncombo aoc on dv.attributeoptioncomboid = aoc.categoryoptioncomboid " + "where dv.dataelementid in (" + StringUtils.join(IdentifiableObjectUtils.getIdentifiers(dataElements), ",") + ") " + "and (";
    for (DimensionalItemObject period : periods) {
        Period pe = (Period) period;
        sql += "(pe.startdate >= '" + getMediumDateString(pe.getStartDate()) + "' and pe.enddate <= '" + getMediumDateString(pe.getEndDate()) + "') or ";
    }
    sql = TextUtils.removeLastOr(sql) + ") and (";
    for (DimensionalItemObject orgUnit : orgUnits) {
        OrganisationUnit ou = (OrganisationUnit) orgUnit;
        int level = ou.getLevel();
        sql += "(dv.sourceid in (select organisationunitid from _orgunitstructure where idlevel" + level + " = " + ou.getId() + ")) or ";
    }
    sql = TextUtils.removeLastOr(sql) + ") ";
    sql += "and dv.deleted is false " + "limit 100000";
    return sql;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Example 69 with OrganisationUnit

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

the class DefaultDataQueryService method getUserOrgUnits.

@Override
public List<OrganisationUnit> getUserOrgUnits(DataQueryParams params, String userOrgUnit) {
    List<OrganisationUnit> units = new ArrayList<>();
    User currentUser = securityManager.getCurrentUser(params);
    if (userOrgUnit != null) {
        List<String> ous = DimensionalObjectUtils.getItemsFromParam(userOrgUnit);
        for (String ou : ous) {
            OrganisationUnit unit = idObjectManager.get(OrganisationUnit.class, ou);
            if (unit != null) {
                units.add(unit);
            }
        }
    } else if (currentUser != null && currentUser.hasOrganisationUnit()) {
        units = currentUser.getSortedOrganisationUnits();
    }
    return units;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User)

Example 70 with OrganisationUnit

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

the class DataSetOrganisationUnitCategoryResourceTable method getPopulateTempTableContent.

/**
     * Iterate over data sets and associated organisation units. If data set
     * has a category combination and the organisation unit has category options, 
     * find the intersection of the category option combinations linked to the 
     * organisation unit through its category options, and the category option 
     * combinations linked to the data set through its category combination. If
     * not, use the default category option combo.
     */
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (DataSet dataSet : objects) {
        DataElementCategoryCombo categoryCombo = dataSet.getCategoryCombo();
        for (OrganisationUnit orgUnit : dataSet.getSources()) {
            if (!categoryCombo.isDefault()) {
                if (orgUnit.hasCategoryOptions()) {
                    Set<DataElementCategoryOption> orgUnitOptions = orgUnit.getCategoryOptions();
                    for (DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos()) {
                        Set<DataElementCategoryOption> optionComboOptions = optionCombo.getCategoryOptions();
                        if (orgUnitOptions.containsAll(optionComboOptions)) {
                            Date startDate = DateUtils.min(optionComboOptions.stream().map(co -> co.getStartDate()).collect(Collectors.toSet()));
                            Date endDate = DateUtils.max(optionComboOptions.stream().map(co -> co.getEndDate()).collect(Collectors.toSet()));
                            List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), optionCombo.getId(), startDate, endDate);
                            batchArgs.add(values.toArray());
                        }
                    }
                }
            } else {
                List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), defaultOptionCombo.getId(), null, null);
                batchArgs.add(values.toArray());
            }
        }
    }
    return Optional.of(batchArgs);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date)

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