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