Search in sources :

Example 86 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyGetCoordinateColumnWithProgramStage.

@Test
void verifyGetCoordinateColumnWithProgramStage() {
    // Given
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.COORDINATE);
    item.setProgramStage(programStage);
    item.setProgram(programA);
    // When
    String columnSql = subject.getCoordinateColumn(item);
    // Then
    String colName = quote(item.getItemName());
    String eventTableName = "analytics_event_" + item.getProgram().getUid();
    assertThat(columnSql, is("(select " + "'[' || round(ST_X((" + colName + "))::numeric, 6) || ',' || round(ST_Y((" + colName + "))::numeric, 6) || ']' as " + colName + " from " + eventTableName + " where " + eventTableName + ".pi = " + ANALYTICS_TBL_ALIAS + ".pi " + "and " + colName + " is not null " + "and ps = '" + item.getProgramStage().getUid() + "' order by executiondate " + "desc limit 1 )"));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 87 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class DefaultValidationService method getValidationContext.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
 * Returns a new Builder with basic configuration based on the input
 * parameters.
 *
 * @param parameters ValidationRuleParameters for creating
 *        ValidationRuleContext
 * @return Builder with basic configuration based on input.
 */
private ValidationRunContext getValidationContext(ValidationAnalysisParams parameters) {
    User currentUser = currentUserService.getCurrentUser();
    OrganisationUnit parameterOrgUnit = parameters.getOrgUnit();
    List<OrganisationUnit> orgUnits;
    if (parameterOrgUnit == null) {
        orgUnits = organisationUnitService.getAllOrganisationUnits();
    } else if (parameters.isIncludeOrgUnitDescendants()) {
        orgUnits = organisationUnitService.getOrganisationUnitWithChildren(parameterOrgUnit.getUid());
    } else {
        orgUnits = Lists.newArrayList(parameterOrgUnit);
    }
    Map<PeriodType, PeriodTypeExtended> periodTypeXMap = new HashMap<>();
    addPeriodsToContext(periodTypeXMap, parameters.getPeriods());
    Map<DimensionalItemId, DimensionalItemObject> dimensionItemMap = addRulesToContext(periodTypeXMap, parameters.getValidationRules());
    Map<String, OrganisationUnitGroup> orgUnitGroupMap = getOrgUnitGroupMap(parameters.getValidationRules());
    removeAnyUnneededPeriodTypes(periodTypeXMap);
    ValidationRunContext.Builder builder = ValidationRunContext.newBuilder().withOrgUnits(orgUnits).withPeriodTypeXs(new ArrayList<>(periodTypeXMap.values())).withInitialResults(validationResultService.getValidationResults(parameterOrgUnit, parameters.isIncludeOrgUnitDescendants(), parameters.getValidationRules(), parameters.getPeriods())).withSendNotifications(parameters.isSendNotifications()).withPersistResults(parameters.isPersistResults()).withAttributeCombo(parameters.getAttributeOptionCombo()).withDefaultAttributeCombo(categoryService.getDefaultCategoryOptionCombo()).withItemMap(dimensionItemMap).withOrgUnitGroupMap(orgUnitGroupMap).withMaxResults(parameters.getMaxResults());
    if (currentUser != null) {
        builder.withCoDimensionConstraints(categoryService.getCoDimensionConstraints(currentUser)).withCogDimensionConstraints(categoryService.getCogDimensionConstraints(currentUser));
    }
    return builder.build();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Example 88 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class DefaultOrgUnitProfileService method getDataItems.

/**
 * Retrieves a list of data items for the given org unit profile and org
 * unit. A data item can be of type data element, indicator, data set and
 * program indicator. Data element can be of type aggregate and tracker.
 *
 * @param profile the {@link OrganisationUnitProfile}.
 * @param orgUnit the {@link OrganisationUnit}.
 * @param period the {@link Period}.
 * @return a list of {@link ProfileItem}.
 */
private List<ProfileItem> getDataItems(OrgUnitProfile profile, OrganisationUnit orgUnit, Period period) {
    if (CollectionUtils.isEmpty(profile.getDataItems())) {
        return ImmutableList.of();
    }
    List<DimensionalItemObject> dataItems = idObjectManager.getByUid(DATA_ITEM_CLASSES, profile.getDataItems());
    if (CollectionUtils.isEmpty(dataItems)) {
        return ImmutableList.of();
    }
    DataQueryParams params = DataQueryParams.newBuilder().withDataDimensionItems(dataItems).withFilterOrganisationUnit(orgUnit).withFilterPeriod(period).build();
    Map<String, Object> values = analyticsService.getAggregatedDataValueMapping(params);
    if (MapUtils.isEmpty(values)) {
        return ImmutableList.of();
    }
    List<ProfileItem> items = new ArrayList<>();
    for (DimensionalItemObject dataItem : dataItems) {
        Object value = values.get(dataItem.getUid());
        if (value != null) {
            items.add(new ProfileItem(dataItem.getUid(), dataItem.getDisplayName(), value));
        }
    }
    return items;
}
Also used : ProfileItem(org.hisp.dhis.orgunitprofile.ProfileItem) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 89 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class DefaultPredictionService method addOuputToItems.

/**
 * Adds the predictor to the list of items. Also, returns the
 * DimensionalItemObject if any to update with the predicted value.
 * <p>
 * Note that we make the simplifying assumption that if the output data
 * element is sampled in an expression without a catOptionCombo, the
 * predicted data value will be used. This is usually what the user wants,
 * but would break if the expression assumes a sum of catOptionCombos
 * including the predicted value and other catOptionCombos.
 */
private DimensionalItemObject addOuputToItems(DataElementOperand outputDataElementOperand, Set<DimensionalItemObject> sampleItems) {
    DimensionalItemObject forwardReference = null;
    for (DimensionalItemObject item : sampleItems) {
        if (item.equals(outputDataElementOperand)) {
            return item;
        }
        if (item.equals(outputDataElementOperand.getDataElement())) {
            forwardReference = item;
        }
    }
    sampleItems.add(outputDataElementOperand);
    return forwardReference;
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Example 90 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class PredictionDataValueFetcher method mapToValues.

/**
 * Convert the value map to a list of found values.
 */
private List<FoundDimensionItemValue> mapToValues(OrganisationUnit orgUnit, MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> map) {
    List<FoundDimensionItemValue> values = new ArrayList<>();
    for (Map.Entry<CategoryOptionCombo, MapMap<Period, DimensionalItemObject, Object>> e1 : map.entrySet()) {
        CategoryOptionCombo aoc = e1.getKey();
        for (Map.Entry<Period, Map<DimensionalItemObject, Object>> e2 : e1.getValue().entrySet()) {
            Period period = e2.getKey();
            for (Map.Entry<DimensionalItemObject, Object> e3 : e2.getValue().entrySet()) {
                DimensionalItemObject obj = e3.getKey();
                Object value = e3.getValue();
                values.add(new FoundDimensionItemValue(orgUnit, period, aoc, obj, value));
            }
        }
    }
    return values;
}
Also used : MapMapMap(org.hisp.dhis.common.MapMapMap) MapMap(org.hisp.dhis.common.MapMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) FoundDimensionItemValue(org.hisp.dhis.common.FoundDimensionItemValue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MapMapMap(org.hisp.dhis.common.MapMapMap) Map(java.util.Map) CachingMap(org.hisp.dhis.commons.collection.CachingMap) MapMap(org.hisp.dhis.common.MapMap) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)178 Test (org.junit.jupiter.api.Test)63 ArrayList (java.util.ArrayList)51 DimensionalObject (org.hisp.dhis.common.DimensionalObject)48 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)42 Period (org.hisp.dhis.period.Period)41 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)40 HashMap (java.util.HashMap)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)22 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)20 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)20 DataElement (org.hisp.dhis.dataelement.DataElement)20 List (java.util.List)17 Indicator (org.hisp.dhis.indicator.Indicator)17 Grid (org.hisp.dhis.common.Grid)16 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)16 ListMap (org.hisp.dhis.common.ListMap)15 QueryItem (org.hisp.dhis.common.QueryItem)15