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