Search in sources :

Example 16 with DeflatedDataValue

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;
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) List(java.util.List) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 17 with DeflatedDataValue

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) ValidationResult(org.hisp.dhis.validation.ValidationResult) DateTime(org.joda.time.DateTime) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 18 with DeflatedDataValue

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);
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataValue(org.hisp.dhis.datavalue.DataValue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MapMapMap(org.hisp.dhis.common.MapMapMap) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 19 with DeflatedDataValue

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataValue(org.hisp.dhis.datavalue.DataValue) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 20 with DeflatedDataValue

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;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList) MapMapMap(org.hisp.dhis.common.MapMapMap) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) Transactional(org.springframework.transaction.annotation.Transactional)

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