Search in sources :

Example 21 with DeflatedDataValue

use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.

the class PredictionServiceTest method getDataValue.

private String getDataValue(DataElement dataElement, CategoryOptionCombo combo, CategoryOptionCombo attributeOptionCombo, OrganisationUnit source, Period period) {
    DataExportParams params = new DataExportParams().setDataElementOperands(Sets.newHashSet(new DataElementOperand(dataElement, combo))).setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo)).setOrganisationUnits(Sets.newHashSet(source)).setPeriods(Sets.newHashSet(periodService.reloadPeriod(period)));
    List<DeflatedDataValue> values = dataValueService.getDeflatedDataValues(params);
    if (values != null && values.size() > 0) {
        return values.get(0).getValue();
    }
    return null;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams)

Example 22 with DeflatedDataValue

use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.

the class DataValidationTask method getDataValueMap.

/**
 * Gets data elements and data element operands from the datavalue table.
 */
private void getDataValueMap() {
    DataExportParams params = new DataExportParams();
    params.setDataElements(periodTypeX.getDataElements());
    params.setDataElementOperands(periodTypeX.getDataElementOperands());
    params.setIncludedDate(period.getStartDate());
    params.setOrganisationUnits(new HashSet<>(orgUnits));
    params.setPeriodTypes(periodTypeX.getAllowedPeriodTypes());
    params.setCoDimensionConstraints(context.getCoDimensionConstraints());
    params.setCogDimensionConstraints(context.getCogDimensionConstraints());
    if (context.getAttributeCombo() != null) {
        params.setAttributeOptionCombos(Sets.newHashSet(context.getAttributeCombo()));
    }
    List<DeflatedDataValue> dataValues = dataValueService.getDeflatedDataValues(params);
    dataMap = new MapMapMap<>();
    MapMapMap<Long, String, DimensionalItemObject, Long> duplicateCheck = new MapMapMap<>();
    for (DeflatedDataValue dv : dataValues) {
        DataElement dataElement = periodTypeX.getDataElementIdMap().get(dv.getDataElementId());
        String deoIdKey = periodTypeX.getDeoIds(dv.getDataElementId(), dv.getCategoryOptionComboId());
        DataElementOperand dataElementOperand = periodTypeX.getDataElementOperandIdMap().get(deoIdKey);
        Period p = getPeriod(dv.getPeriodId());
        long orgUnitId = dv.getSourceId();
        String attributeOptionComboUid = getAttributeOptionCombo(dv.getAttributeOptionComboId()).getUid();
        if (dataElement != null) {
            Object value = getObjectValue(dv.getValue(), dataElement.getValueType());
            addValueToDataMap(orgUnitId, attributeOptionComboUid, dataElement, value, p, duplicateCheck);
        }
        if (dataElementOperand != null) {
            Object value = getObjectValue(dv.getValue(), dataElementOperand.getDataElement().getValueType());
            addValueToDataMap(orgUnitId, attributeOptionComboUid, dataElementOperand, value, p, duplicateCheck);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Period(org.hisp.dhis.period.Period) DataElement(org.hisp.dhis.dataelement.DataElement) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams)

Example 23 with DeflatedDataValue

use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.

the class DefaultFollowupAnalysisService method getFollowupDataValues.

@Override
@Transactional(readOnly = true)
public List<DeflatedDataValue> getFollowupDataValues(Collection<OrganisationUnit> parents, Collection<DataElement> dataElements, Collection<Period> periods, int limit) {
    if (parents == null || parents.isEmpty() || limit < 1) {
        return emptyList();
    }
    Set<DataElement> elements = dataElements.stream().filter(de -> de.getValueType().isNumeric()).collect(Collectors.toSet());
    Set<CategoryOptionCombo> categoryOptionCombos = new HashSet<>();
    for (DataElement dataElement : elements) {
        categoryOptionCombos.addAll(dataElement.getCategoryOptionCombos());
    }
    log.debug("Starting min-max analysis, no of data elements: " + elements.size() + ", no of parent org units: " + parents.size());
    return dataAnalysisStore.getFollowupDataValues(elements, categoryOptionCombos, periods, parents, limit);
}
Also used : CollectionUtils.isEmpty(org.hisp.dhis.commons.collection.CollectionUtils.isEmpty) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Collectors(java.util.stream.Collectors) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) I18nFormat(org.hisp.dhis.i18n.I18nFormat) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Service(org.springframework.stereotype.Service) ErrorCode(org.hisp.dhis.feedback.ErrorCode) AllArgsConstructor(lombok.AllArgsConstructor) I18nManager(org.hisp.dhis.i18n.I18nManager) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with DeflatedDataValue

use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.

the class StdDevOutlierAnalysisServiceTest method testGetFindOutliers.

// ----------------------------------------------------------------------
// Business logic tests
// ----------------------------------------------------------------------
@Test
void testGetFindOutliers() {
    dataValueA = createDataValue(dataElementSingleQuoteName, periodI, organisationUnitA, "71", categoryOptionCombo);
    dataValueB = createDataValue(dataElementSingleQuoteName, periodJ, organisationUnitA, "-71", categoryOptionCombo);
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodA, organisationUnitA, "5", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodB, organisationUnitA, "-5", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodC, organisationUnitA, "5", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodD, organisationUnitA, "-5", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodE, organisationUnitA, "10", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodF, organisationUnitA, "-10", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodG, organisationUnitA, "13", categoryOptionCombo));
    dataValueService.addDataValue(createDataValue(dataElementSingleQuoteName, periodH, organisationUnitA, "-13", categoryOptionCombo));
    dataValueService.addDataValue(dataValueA);
    dataValueService.addDataValue(dataValueB);
    double stdDevFactor = 2.0;
    List<Period> periods = new ArrayList<>();
    periods.add(periodI);
    periods.add(periodJ);
    periods.add(periodA);
    periods.add(periodE);
    List<DeflatedDataValue> values = stdDevOutlierAnalysisService.analyse(Lists.newArrayList(organisationUnitA), dataElementsA, periods, stdDevFactor, from);
    double lowerBound = -34.51 * stdDevFactor;
    double upperBound = 34.51 * stdDevFactor;
    DeflatedDataValue valueA = new DeflatedDataValue(dataValueA);
    DeflatedDataValue valueB = new DeflatedDataValue(dataValueB);
    assertEquals(1, values.size());
    assertTrue(values.contains(valueA));
    assertFalse(values.contains(valueB));
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 25 with DeflatedDataValue

use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.

the class DeflatedDataValueRowMapper method mapRow.

@Override
public DeflatedDataValue mapRow(ResultSet resultSet) throws SQLException {
    final DeflatedDataValue value = new DeflatedDataValue();
    value.setDataElementId(resultSet.getLong("dataelementid"));
    value.setPeriodId(resultSet.getLong("periodid"));
    value.setSourceId(resultSet.getLong("sourceid"));
    value.setCategoryOptionComboId(resultSet.getLong("categoryoptioncomboid"));
    value.setValue(resultSet.getString("value"));
    value.setStoredBy(resultSet.getString("storedby"));
    value.setCreated(resultSet.getTimestamp("created"));
    value.setLastUpdated(resultSet.getTimestamp("lastupdated"));
    value.setComment(resultSet.getString("comment"));
    return value;
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue)

Aggregations

DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)28 ArrayList (java.util.ArrayList)16 Period (org.hisp.dhis.period.Period)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)9 DataElement (org.hisp.dhis.dataelement.DataElement)9 List (java.util.List)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)6 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)6 Grid (org.hisp.dhis.common.Grid)5 DataValue (org.hisp.dhis.datavalue.DataValue)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 DateTime (org.joda.time.DateTime)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Collectors (java.util.stream.Collectors)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 MinMaxDataElement (org.hisp.dhis.minmax.MinMaxDataElement)3