use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class ExportAnalysisResultAction method generateGrid.
@SuppressWarnings("unchecked")
private Grid generateGrid() {
List<DeflatedDataValue> results = (List<DeflatedDataValue>) SessionUtils.getSessionVar(GetAnalysisAction.KEY_ANALYSIS_DATA_VALUES);
Grid grid = new ListGrid();
grid.setTitle(i18n.getString("data_analysis_report"));
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
grid.addHeader(new GridHeader(i18n.getString("min"), false, false));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("max"), false, false));
for (DeflatedDataValue dataValue : results) {
Period period = dataValue.getPeriod();
grid.addRow();
grid.addValue(dataValue.getDataElementName());
grid.addValue(dataValue.getSourceName());
grid.addValue(format.formatPeriod(period));
grid.addValue(dataValue.getMin());
grid.addValue(dataValue.getValue());
grid.addValue(dataValue.getMax());
}
return grid;
}
use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class ValidationAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
DataSet dataSet = dataSetService.getDataSet(ds);
Period selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
attributeOptionCombo = dataElementCategoryService.getDefaultCategoryOptionCombo();
}
if (selectedPeriod == null || orgUnit == null || (multiOu && !orgUnit.hasChild())) {
return SUCCESS;
}
Period period = periodService.getPeriod(selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedPeriod.getPeriodType());
if (period == null) {
return SUCCESS;
}
List<OrganisationUnit> organisationUnits = new ArrayList<>();
if (!multiOu) {
organisationUnits.add(orgUnit);
} else {
organisationUnits.addAll(orgUnit.getChildren());
}
Collections.sort(organisationUnits);
Date from = new DateTime(period.getStartDate()).minusYears(2).toDate();
for (OrganisationUnit organisationUnit : organisationUnits) {
List<DeflatedDataValue> values = new ArrayList<>(minMaxOutlierAnalysisService.analyse(Sets.newHashSet(organisationUnit), dataSet.getDataElements(), Sets.newHashSet(period), null, from));
if (!values.isEmpty()) {
dataValues.put(organisationUnit.getUid(), values);
}
ValidationAnalysisParams params = validationService.newParamsBuilder(dataSet, organisationUnit, period).withAttributeOptionCombo(attributeOptionCombo).build();
List<ValidationResult> results = new ArrayList<>(validationService.validationAnalysis(params));
if (!results.isEmpty()) {
validationResults.put(organisationUnit.getUid(), results);
}
List<DataElementOperand> violations = validationService.validateRequiredComments(dataSet, period, organisationUnit, attributeOptionCombo);
log.info("Validation done for data set: '{}', period: '{}', org unit: '{}', validation rule count: {}, violations found: {}", dataSet.getUid(), period.getIsoDate(), organisationUnit.getUid(), params.getValidationRules().size(), violations.size());
if (!violations.isEmpty()) {
commentViolations.put(organisationUnit.getUid(), violations);
}
}
return dataValues.isEmpty() && validationResults.isEmpty() && commentViolations.isEmpty() ? SUCCESS : INPUT;
}
use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class PredictionDataValueFetcher method getPredictionData.
/**
* Gets prediction data for an orgUnit from a list of deflated data values.
*/
private PredictionData getPredictionData(OrganisationUnit orgUnit, List<DeflatedDataValue> deflatedDataValues) {
MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> map = new MapMapMap<>();
List<DataValue> oldPredictions = new ArrayList<>();
for (DeflatedDataValue ddv : deflatedDataValues) {
DataValue dv = inflateDataValue(ddv);
if (!dv.isDeleted()) {
addValueToMap(dv, map);
}
if (ddv.getSourcePath().equals(dv.getSource().getPath()) && ddv.getDataElementId() == outputDataElementOperand.getDataElement().getId() && ddv.getCategoryOptionComboId() == (outputDataElementOperand.getCategoryOptionCombo().getId()) && outputPeriods.contains(dv.getPeriod())) {
oldPredictions.add(dv);
}
}
return new PredictionData(orgUnit, mapToValues(orgUnit, map), oldPredictions);
}
use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class PredictionDataValueFetcher method inflateDataValue.
/**
* "Inflates" a deflated data value, using our caches.
*/
private DataValue inflateDataValue(DeflatedDataValue ddv) {
DataElement dataElement = dataElementLookup.get(ddv.getDataElementId());
Period period = periodLookup.get(ddv.getPeriodId());
OrganisationUnit orgUnit = orgUnitLookup.get(truncatePathToLevel(ddv.getSourcePath()));
CategoryOptionCombo categoryOptionCombo = cocLookup.get(ddv.getCategoryOptionComboId(), () -> categoryService.getCategoryOptionCombo(ddv.getCategoryOptionComboId()));
CategoryOptionCombo attributeOptionCombo = cocLookup.get(ddv.getAttributeOptionComboId(), () -> categoryService.getCategoryOptionCombo(ddv.getAttributeOptionComboId()));
return new DataValue(dataElement, period, orgUnit, categoryOptionCombo, attributeOptionCombo, ddv.getValue(), ddv.getStoredBy(), ddv.getLastUpdated(), ddv.getComment(), ddv.isFollowup(), ddv.isDeleted());
}
use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationService method getMissingCompulsoryFields.
@Override
@Transactional(readOnly = true)
public List<DataElementOperand> getMissingCompulsoryFields(DataSet dataSet, Period period, OrganisationUnit organisationUnit, CategoryOptionCombo attributeOptionCombo) {
List<DataElementOperand> missingDataElementOperands = new ArrayList<>();
if (!dataSet.getCompulsoryDataElementOperands().isEmpty()) {
DataExportParams params = new DataExportParams();
params.setDataElementOperands(dataSet.getCompulsoryDataElementOperands());
params.setPeriods(Sets.newHashSet(period));
params.setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo));
params.setOrganisationUnits(Sets.newHashSet(organisationUnit));
List<DeflatedDataValue> deflatedDataValues = dataValueService.getDeflatedDataValues(params);
MapMapMap<Long, Long, Long, Boolean> dataPresent = new MapMapMap<>();
for (DeflatedDataValue dv : deflatedDataValues) {
dataPresent.putEntry(dv.getSourceId(), dv.getDataElementId(), dv.getCategoryOptionComboId(), true);
}
User currentUser = currentUserService.getCurrentUser();
for (DataElementOperand deo : dataSet.getCompulsoryDataElementOperands()) {
List<String> errors = accessManager.canWrite(currentUser, deo);
if (!errors.isEmpty()) {
continue;
}
MapMap<Long, Long, Boolean> ouDataPresent = dataPresent.get(organisationUnit.getId());
if (ouDataPresent != null) {
Map<Long, Boolean> deDataPresent = ouDataPresent.get(deo.getDataElement().getId());
if (deDataPresent != null && (deo.getCategoryOptionCombo() == null || deDataPresent.get(deo.getCategoryOptionCombo().getId()) != null)) {
continue;
}
}
missingDataElementOperands.add(deo);
}
}
return missingDataElementOperands;
}
Aggregations