Search in sources :

Example 51 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DefaultValidationService method validateRequiredComments.

@Override
public List<DataElementOperand> validateRequiredComments(DataSet dataSet, Period period, OrganisationUnit organisationUnit, CategoryOptionCombo attributeOptionCombo) {
    List<DataElementOperand> violations = new ArrayList<>();
    if (dataSet.isNoValueRequiresComment()) {
        for (DataElement de : dataSet.getDataElements()) {
            for (CategoryOptionCombo co : de.getCategoryOptionCombos()) {
                DataValue dv = dataValueService.getDataValue(de, period, organisationUnit, co, attributeOptionCombo);
                boolean missingValue = dv == null || StringUtils.trimToNull(dv.getValue()) == null;
                boolean missingComment = dv == null || StringUtils.trimToNull(dv.getComment()) == null;
                if (missingValue && missingComment) {
                    violations.add(new DataElementOperand(de, co));
                }
            }
        }
    }
    return violations;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.datavalue.DataValue) ArrayList(java.util.ArrayList) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 52 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DataValidationTask method getAttributeOptionCombo.

private CategoryOptionCombo getAttributeOptionCombo(String uid) {
    CategoryOptionCombo aoc = context.getAocUidMap().get(uid);
    if (aoc == null) {
        log.trace("DataValidationTask calling getCategoryOptionCombo( uid " + uid + " )");
        aoc = categoryService.getCategoryOptionCombo(uid);
        log.trace("DataValidationTask called getCategoryOptionCombo( uid " + uid + ")");
        addToAocCache(aoc);
    }
    return aoc;
}
Also used : CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 53 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo 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;
}
Also used : MapMapMap(org.hisp.dhis.common.MapMapMap) MapMap(org.hisp.dhis.common.MapMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) FoundDimensionItemValue(org.hisp.dhis.common.FoundDimensionItemValue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MapMapMap(org.hisp.dhis.common.MapMapMap) Map(java.util.Map) CachingMap(org.hisp.dhis.commons.collection.CachingMap) MapMap(org.hisp.dhis.common.MapMap) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 54 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class PredictionAnalyticsDataFetcher method getValuesInternal.

/**
 * Queries analytics for data.
 */
private List<FoundDimensionItemValue> getValuesInternal(List<OrganisationUnit> orgUnits, Set<DimensionalItemObject> dimensionItems, boolean hasAttributeOptions) {
    List<FoundDimensionItemValue> values = new ArrayList<>();
    if (dimensionItems.isEmpty()) {
        return values;
    }
    DataQueryParams.Builder paramsBuilder = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(periods)).withDataDimensionItems(Lists.newArrayList(dimensionItems)).withOrganisationUnits(orgUnits);
    if (hasAttributeOptions) {
        paramsBuilder.withAttributeOptionCombos(Collections.emptyList());
    }
    Grid grid = analyticsService.getAggregatedDataValues(paramsBuilder.build());
    int peInx = grid.getIndexOfHeader(DimensionalObject.PERIOD_DIM_ID);
    int dxInx = grid.getIndexOfHeader(DimensionalObject.DATA_X_DIM_ID);
    int ouInx = grid.getIndexOfHeader(DimensionalObject.ORGUNIT_DIM_ID);
    int aoInx = hasAttributeOptions ? grid.getIndexOfHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID) : 0;
    int vlInx = grid.getWidth() - 1;
    for (List<Object> row : grid.getRows()) {
        String pe = (String) row.get(peInx);
        String dx = (String) row.get(dxInx);
        String ou = (String) row.get(ouInx);
        String ao = hasAttributeOptions ? (String) row.get(aoInx) : null;
        Object vl = row.get(vlInx);
        Period period = periodLookup.get(pe);
        DimensionalItemObject item = analyticsItemsLookup.get(dx);
        OrganisationUnit orgUnit = orgUnitLookup.get(ou);
        CategoryOptionCombo attributeOptionCombo = hasAttributeOptions ? cocLookup.get(ao, () -> categoryService.getCategoryOptionCombo(ao)) : null;
        values.add(new FoundDimensionItemValue(orgUnit, period, attributeOptionCombo, item, vl));
    }
    return values;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) FoundDimensionItemValue(org.hisp.dhis.common.FoundDimensionItemValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 55 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class PredictionContextGenerator method getContexts.

/**
 * Generates prediction contexts. Each prediction context contains all the
 * values required to evaluate a predictor to (possibly) generate one
 * prediction.
 * <p>
 * All the data used to generate contexts has the same organisation unit.
 *
 * @param outputPeriods output periods (predict within each period)
 * @param values input prediction values (all with the same orgUnit)
 * @param defaultCategoryOptionCombo system default cat option combo
 * @return contexts for prediction evaluation
 */
public static List<PredictionContext> getContexts(List<Period> outputPeriods, List<FoundDimensionItemValue> values, CategoryOptionCombo defaultCategoryOptionCombo) {
    List<PredictionContext> contexts = new ArrayList<>();
    MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> aocMap = getAocMap(values, defaultCategoryOptionCombo);
    for (Map.Entry<CategoryOptionCombo, MapMap<Period, DimensionalItemObject, Object>> e : aocMap.entrySet()) {
        CategoryOptionCombo aoc = e.getKey();
        MapMap<Period, DimensionalItemObject, Object> periodValueMap = e.getValue();
        for (Period outputPeriod : outputPeriods) {
            contexts.add(new PredictionContext(aoc, outputPeriod, periodValueMap, firstNonNull(periodValueMap.get(outputPeriod), new HashMap<>())));
        }
    }
    return contexts;
}
Also used : ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) MapMapMap(org.hisp.dhis.common.MapMapMap) MapMap(org.hisp.dhis.common.MapMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MapMapMap(org.hisp.dhis.common.MapMapMap) Map(java.util.Map) HashMap(java.util.HashMap) MapMap(org.hisp.dhis.common.MapMap) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16