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