Search in sources :

Example 51 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class GetMetaDataAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(DataElementCategoryCombo.class), identifiableObjectManager.getLastUpdated(DataElementCategory.class), identifiableObjectManager.getLastUpdated(DataElementCategoryOption.class)));
    String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
    if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
        return SUCCESS;
    }
    if (user != null && user.getOrganisationUnits().isEmpty()) {
        emptyOrganisationUnits = true;
        return SUCCESS;
    }
    significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
    dataElements = dataElementService.getDataElementsWithDataSets();
    for (DataElement dataElement : dataElements) {
        if (dataElement != null && dataElement.getOptionSet() != null) {
            dataElementsWithOptionSet.add(dataElement);
        }
    }
    indicators = indicatorService.getIndicatorsWithDataSets();
    expressionService.substituteExpressions(indicators, null);
    dataSets = dataSetService.getCurrentUserDataSets();
    Set<DataElementCategoryCombo> categoryComboSet = new HashSet<>();
    Set<DataElementCategory> categorySet = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        if (dataSet.getCategoryCombo() != null) {
            categoryComboSet.add(dataSet.getCategoryCombo());
        }
    }
    for (DataElementCategoryCombo categoryCombo : categoryComboSet) {
        if (categoryCombo.getCategories() != null) {
            categorySet.addAll(categoryCombo.getCategories());
        }
    }
    categoryCombos = new ArrayList<>(categoryComboSet);
    categories = new ArrayList<>(categorySet);
    for (DataElementCategory category : categories) {
        List<DataElementCategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataElementCategoryOptions(category));
        Collections.sort(categoryOptions);
        categoryOptionMap.put(category.getUid(), categoryOptions);
    }
    Collections.sort(dataSets);
    Collections.sort(categoryCombos);
    Collections.sort(categories);
    defaultCategoryCombo = categoryService.getDefaultDataElementCategoryCombo();
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) HashSet(java.util.HashSet)

Example 52 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class RemoveMinMaxLimitsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    DataElement dataElement = dataElementService.getDataElement(dataElementId);
    DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptionComboId);
    MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement(organisationUnit, dataElement, optionCombo);
    if (minMaxDataElement != null) {
        minMaxDataElementService.deleteMinMaxDataElement(minMaxDataElement);
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 53 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class AnalyticsUtils method getDimensionMetadataItemMap.

/**
     * Returns a mapping between identifiers and meta data items for the given query.
     *
     * @param params the data query parameters.
     * @return a mapping between identifiers and meta data items.
     */
public static Map<String, MetadataItem> getDimensionMetadataItemMap(DataQueryParams params) {
    List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
    Map<String, MetadataItem> map = new HashMap<>();
    Calendar calendar = PeriodType.getCalendar();
    for (DimensionalObject dimension : dimensions) {
        for (DimensionalItemObject item : dimension.getItems()) {
            if (DimensionType.PERIOD == dimension.getDimensionType() && !calendar.isIso8601()) {
                Period period = (Period) item;
                DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
                map.put(period.getPeriodType().getIsoDate(dateTimeUnit), new MetadataItem(period.getDisplayName()));
            } else {
                String legendSet = item.hasLegendSet() ? item.getLegendSet().getUid() : null;
                map.put(item.getDimensionItem(), new MetadataItem(item.getDisplayProperty(params.getDisplayProperty()), legendSet));
            }
            if (DimensionType.ORGANISATION_UNIT == dimension.getDimensionType() && params.isHierarchyMeta()) {
                OrganisationUnit unit = (OrganisationUnit) item;
                for (OrganisationUnit ancestor : unit.getAncestors()) {
                    map.put(ancestor.getUid(), new MetadataItem(ancestor.getDisplayProperty(params.getDisplayProperty())));
                }
            }
            if (DimensionItemType.DATA_ELEMENT == item.getDimensionItemType()) {
                DataElement dataElement = (DataElement) item;
                for (DataElementCategoryOptionCombo coc : dataElement.getCategoryOptionCombos()) {
                    map.put(coc.getUid(), new MetadataItem(coc.getDisplayProperty(params.getDisplayProperty())));
                }
            }
        }
        map.put(dimension.getDimension(), new MetadataItem(dimension.getDisplayProperty(params.getDisplayProperty())));
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DataElement(org.hisp.dhis.dataelement.DataElement) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 54 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class ResourceTableServiceTest method setUpTest.

@Override
public void setUpTest() {
    PeriodType pt = new MonthlyPeriodType();
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    DataElementGroup degA = createDataElementGroup('A');
    DataElementGroup degB = createDataElementGroup('B');
    degA.addDataElement(deA);
    degB.addDataElement(deB);
    idObjectManager.save(degA);
    idObjectManager.save(degB);
    DataElementGroupSet degsA = createDataElementGroupSet('A');
    degsA.addDataElementGroup(degA);
    degsA.addDataElementGroup(degB);
    idObjectManager.save(degsA);
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    OrganisationUnit ouC = createOrganisationUnit('C');
    ouB.setParent(ouA);
    ouC.setParent(ouA);
    ouA.getChildren().add(ouB);
    ouA.getChildren().add(ouC);
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    idObjectManager.save(ouC);
    DataSet dsA = createDataSet('A', pt);
    DataSet dsB = createDataSet('B', pt);
    dsA.addDataSetElement(deA);
    dsB.addDataSetElement(deA);
    dsA.addOrganisationUnit(ouA);
    dsB.addOrganisationUnit(ouA);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 55 with DataElement

use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.

the class DefaultPredictorService method predict.

// -------------------------------------------------------------------------
// Predictor run
// -------------------------------------------------------------------------
@Override
public int predict(Predictor predictor, Date startDate, Date endDate) {
    log.info("Predicting for " + predictor.getName() + " from " + startDate.toString() + " to " + endDate.toString());
    Expression generator = predictor.getGenerator();
    Expression skipTest = predictor.getSampleSkipTest();
    DataElement outputDataElement = predictor.getOutput();
    Set<String> aggregates = expressionService.getAggregatesInExpression(generator.getExpression());
    Map<String, Double> constantMap = constantService.getConstantMap();
    List<Period> outputPeriods = getPeriodsBetweenDates(predictor.getPeriodType(), startDate, endDate);
    ListMap<Period, Period> samplePeriodsMap = getSamplePeriodsMap(outputPeriods, predictor);
    Set<Period> allSamplePeriods = samplePeriodsMap.uniqueValues();
    Set<DataElementOperand> dataElementOperands = getDataElementOperands(aggregates, skipTest);
    User currentUser = currentUserService.getCurrentUser();
    DataElementCategoryOptionCombo outputOptionCombo = predictor.getOutputCombo() == null ? categoryService.getDefaultDataElementCategoryOptionCombo() : predictor.getOutputCombo();
    List<OrganisationUnit> orgUnits = organisationUnitService.getOrganisationUnitsAtOrgUnitLevels(predictor.getOrganisationUnitLevels(), currentUser.getOrganisationUnits());
    int predictionCount = 0;
    for (OrganisationUnit orgUnit : orgUnits) {
        MapMapMap<Period, String, DimensionalItemObject, Double> dataMap = dataElementOperands.isEmpty() ? null : dataValueService.getDataElementOperandValues(dataElementOperands, allSamplePeriods, orgUnit);
        applySkipTest(dataMap, skipTest, constantMap);
        for (Period period : outputPeriods) {
            ListMapMap<String, String, Double> aggregateSampleMap = getAggregateSamples(dataMap, aggregates, samplePeriodsMap.get(period), constantMap);
            for (String aoc : aggregateSampleMap.keySet()) {
                ListMap<String, Double> aggregateValueMap = aggregateSampleMap.get(aoc);
                Double value = expressionService.getExpressionValue(generator, new HashMap<>(), constantMap, null, period.getDaysInPeriod(), aggregateValueMap);
                if (value != null && !value.isNaN() && !value.isInfinite()) {
                    writeDataValue(outputDataElement, period, orgUnit, outputOptionCombo, categoryService.getDataElementCategoryOptionCombo(aoc), value.toString(), currentUser.getUsername());
                    predictionCount++;
                }
            }
        }
    }
    log.info("Generated " + predictionCount + " predictions for " + predictor.getName() + " from " + startDate.toString() + " to " + endDate.toString());
    return predictionCount;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Expression(org.hisp.dhis.expression.Expression) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

DataElement (org.hisp.dhis.dataelement.DataElement)254 Test (org.junit.Test)137 DhisSpringTest (org.hisp.dhis.DhisSpringTest)99 User (org.hisp.dhis.user.User)51 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)47 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)44 DataSet (org.hisp.dhis.dataset.DataSet)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 ArrayList (java.util.ArrayList)31 List (java.util.List)31 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HashSet (java.util.HashSet)23 Period (org.hisp.dhis.period.Period)20 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)19 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)18 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)16 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)15 DataValue (org.hisp.dhis.datavalue.DataValue)15 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)14 Matcher (java.util.regex.Matcher)13