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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations