Search in sources :

Example 6 with DataElementOperand

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

the class HibernateDataValueStore method getDisaggRestriction.

/**
     * Examines a set of DataElementOperands, and returns a SQL condition
     * restricting the CategoryOptionCombo to a list of specific combos
     * if only specific combos are required, or returns no restriction
     * if all CategoryOptionCombos are to be fetched.
     *
     * @param deos the collection of DataElementOperands.
     * @return the SQL restriction.
     */
private String getDisaggRestriction(Set<DataElementOperand> deos) {
    String restiction = " and coc.uid in ( ";
    String snippit = "";
    for (DataElementOperand deo : deos) {
        if (deo.getCategoryOptionCombo() == null) {
            return "";
        }
        restiction += snippit + "'" + deo.getCategoryOptionCombo().getUid() + "'";
        snippit = ", ";
    }
    return restiction + " )";
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand)

Example 7 with DataElementOperand

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

the class DimensionServiceTest method testGetDimensionalItemObject.

@Test
public void testGetDimensionalItemObject() {
    String idA = deA.getUid();
    String idB = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + deA.getUid();
    String idC = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + atA.getUid();
    String idD = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + ReportingRateMetric.REPORTING_RATE.name();
    String idE = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_METRIC";
    String idF = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
    String idG = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
    String idH = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_SYMBOL";
    String idI = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
    String idJ = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
    String idK = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramTrackedEntityAttributeDimensionItem ptaA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
    ReportingRate rrA = new ReportingRate(dsA, ReportingRateMetric.REPORTING_RATE);
    DataElementOperand deoA = new DataElementOperand(deA, cocA);
    DataElementOperand deoB = new DataElementOperand(deA, null);
    DataElementOperand deoC = new DataElementOperand(deA, cocA, cocA);
    DataElementOperand deoD = new DataElementOperand(deA, cocA, null);
    DataElementOperand deoE = new DataElementOperand(deA, null, cocA);
    assertNotNull(dimensionService.getDataDimensionalItemObject(idA));
    assertEquals(deA, dimensionService.getDataDimensionalItemObject(idA));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idB));
    assertEquals(pdeA, dimensionService.getDataDimensionalItemObject(idB));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idC));
    assertEquals(ptaA, dimensionService.getDataDimensionalItemObject(idC));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idD));
    assertEquals(rrA, dimensionService.getDataDimensionalItemObject(idD));
    assertNull(dimensionService.getDataDimensionalItemObject(idE));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idF));
    assertEquals(deoA, dimensionService.getDataDimensionalItemObject(idF));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idG));
    assertEquals(deoB, dimensionService.getDataDimensionalItemObject(idG));
    assertNull(dimensionService.getDataDimensionalItemObject(idH));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idI));
    assertEquals(deoC, dimensionService.getDataDimensionalItemObject(idI));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idJ));
    assertEquals(deoD, dimensionService.getDataDimensionalItemObject(idJ));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idK));
    assertEquals(deoE, dimensionService.getDataDimensionalItemObject(idK));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with DataElementOperand

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

the class AbstractWebApiTest method createTestObject.

@SuppressWarnings("unchecked")
protected T createTestObject(Class<?> clazz, char uniqueName, Object... params) {
    if (DataElementGroup.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroup(uniqueName);
    } else if (DataElementCategoryCombo.class.isAssignableFrom(clazz)) {
        return (T) createCategoryCombo(uniqueName, Arrays.copyOf(params, params.length, DataElementCategory[].class));
    } else if (DataElementCategoryOption.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOption(uniqueName);
    } else if (DataElement.class.isAssignableFrom(clazz)) {
        return (T) createDataElement(uniqueName);
    } else if (DataElementCategory.class.isAssignableFrom(clazz)) {
        return (T) createDataElementCategory(uniqueName, Arrays.copyOf(params, params.length, DataElementCategoryOption[].class));
    } else if (Program.class.isAssignableFrom(clazz)) {
        OrganisationUnit organisationUnitA = createOrganisationUnit(uniqueName);
        manager.save(organisationUnitA);
        return (T) createProgram(uniqueName, new HashSet<>(), organisationUnitA);
    } else if (DataElementOperand.class.isAssignableFrom(clazz)) {
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        DataElementCategoryOptionCombo coc = createCategoryOptionCombo(cc, co);
        manager.save(coc);
        return (T) new DataElementOperand(deA, coc);
    } else if (DataElementGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroupSet(uniqueName);
    } else if (DataElementCategoryOptionCombo.class.isAssignableFrom(clazz)) {
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        return (T) createCategoryOptionCombo(cc, co);
    } else if (CategoryOptionGroup.class.isAssignableFrom(clazz)) {
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(co);
        return (T) createCategoryOptionGroup(uniqueName, co);
    } else if (CategoryOptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOptionGroupSet(uniqueName);
    } else if (EventChart.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventChart ecA = new EventChart("evc" + uniqueName);
        ecA.setProgram(prA);
        ecA.setType(ChartType.COLUMN);
        return (T) ecA;
    } else if (EventReport.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventReport erA = new EventReport("er" + uniqueName);
        erA.setProgram(prA);
        return (T) erA;
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        return (T) new ProgramDataElementDimensionItem(prA, deA);
    } else if (ProgramIndicator.class.isAssignableFrom(clazz)) {
        Program program = (Program) createTestObject(Program.class, uniqueName);
        manager.save(program);
        Constant constantA = createConstant(uniqueName, 7.0);
        manager.save(constantA);
        String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
        return (T) createProgramIndicator(uniqueName, program, expressionA, null);
    } else if (Indicator.class.isAssignableFrom(clazz)) {
        IndicatorType indicatorType = createIndicatorType(uniqueName);
        manager.save(indicatorType);
        return (T) createIndicator(uniqueName, indicatorType);
    } else if (IndicatorGroup.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroup(uniqueName);
    } else if (IndicatorGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroupSet(uniqueName);
    } else if (IndicatorType.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorType(uniqueName);
    } else if (Legend.class.isAssignableFrom(clazz)) {
        return (T) createLegend(uniqueName, 0d, 10d);
    } else if (LegendSet.class.isAssignableFrom(clazz)) {
        return (T) createLegendSet(uniqueName);
    } else if (OrganisationUnit.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnit(uniqueName);
    } else if (OrganisationUnitGroup.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroup(uniqueName);
    } else if (OrganisationUnitGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroupSet(uniqueName);
    } else if (OrganisationUnitLevel.class.isAssignableFrom(clazz)) {
        return (T) new OrganisationUnitLevel(uniqueName, "OrgLevel" + uniqueName);
    } else if (Color.class.isAssignableFrom(clazz)) {
        Color color = new Color("#ff3200");
        color.setName("Color" + uniqueName);
        return (T) color;
    } else if (ColorSet.class.isAssignableFrom(clazz)) {
        ColorSet colorSet = new ColorSet();
        colorSet.setName("ColorSet" + uniqueName);
        return (T) colorSet;
    } else if (org.hisp.dhis.mapping.Map.class.isAssignableFrom(clazz)) {
        org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
        map.setName("Map" + uniqueName);
        map.setDisplayName("DisplayName" + uniqueName);
        map.setLatitude(952175.62553525);
        map.setLongitude(-1378543.6774686);
        return (T) map;
    } else if (ExternalMapLayer.class.isAssignableFrom(clazz)) {
        ExternalMapLayer externalMapLayer = new ExternalMapLayer("ExternalMapLayer" + uniqueName);
        externalMapLayer.setMapService(MapService.WMS);
        externalMapLayer.setUrl("testUrl");
        externalMapLayer.setImageFormat(ImageFormat.JPG);
        externalMapLayer.setMapLayerPosition(MapLayerPosition.BASEMAP);
        return (T) externalMapLayer;
    } else if (OptionGroup.class.isAssignableFrom(clazz)) {
        OptionGroup optionGroup = new OptionGroup("OptionGroup" + uniqueName);
        optionGroup.setShortName("Group" + uniqueName);
        return (T) optionGroup;
    } else if (OptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionGroupSet("OptionGroupSet" + uniqueName);
    } else if (Option.class.isAssignableFrom(clazz)) {
        return (T) new Option("Option" + uniqueName, "code" + uniqueName);
    } else if (OptionSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionSet("OptionSet" + uniqueName, ValueType.TEXT);
    } else if (ProgramTrackedEntityAttributeGroup.class.isAssignableFrom(clazz)) {
        ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup(uniqueName);
        ProgramTrackedEntityAttribute attr = createProgramTrackedEntityAttribute(uniqueName);
        group.addAttribute(attr);
        return (T) group;
    } else if (ProgramTrackedEntityAttribute.class.isAssignableFrom(clazz)) {
        return (T) createProgramTrackedEntityAttribute(uniqueName);
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        return (T) createProgramDataElement(uniqueName);
    }
    return null;
}
Also used : ColorSet(org.hisp.dhis.color.ColorSet) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ExternalMapLayer(org.hisp.dhis.mapping.ExternalMapLayer) Legend(org.hisp.dhis.legend.Legend) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Constant(org.hisp.dhis.constant.Constant) EventReport(org.hisp.dhis.eventreport.EventReport) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) IndicatorType(org.hisp.dhis.indicator.IndicatorType) OptionGroup(org.hisp.dhis.option.OptionGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) Color(org.hisp.dhis.color.Color) EventChart(org.hisp.dhis.eventchart.EventChart) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.option.Option) ProgramTrackedEntityAttributeGroup(org.hisp.dhis.program.ProgramTrackedEntityAttributeGroup) OptionSet(org.hisp.dhis.option.OptionSet) Map(java.util.Map) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 9 with DataElementOperand

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

the class DimensionalObjectUtilsTest method testReplaceOperandTotalsWithDataElements.

@Test
public void testReplaceOperandTotalsWithDataElements() {
    DataElement deA = new DataElement("NameA");
    DataElement deB = new DataElement("NameB");
    deA.setAutoFields();
    deB.setAutoFields();
    DataElementCategoryOptionCombo cocA = new DataElementCategoryOptionCombo();
    cocA.setAutoFields();
    DataElementOperand opA = new DataElementOperand(deA);
    DataElementOperand opB = new DataElementOperand(deA, cocA);
    DataElementOperand opC = new DataElementOperand(deB, cocA);
    List<DimensionalItemObject> items = Lists.newArrayList(deB, opA, opB, opC);
    assertEquals(4, items.size());
    assertTrue(items.contains(deB));
    assertTrue(items.contains(opA));
    assertTrue(items.contains(opB));
    assertTrue(items.contains(opC));
    assertFalse(items.contains(deA));
    items = DimensionalObjectUtils.replaceOperandTotalsWithDataElements(items);
    assertEquals(4, items.size());
    assertTrue(items.contains(deB));
    assertFalse(items.contains(opA));
    assertTrue(items.contains(opB));
    assertTrue(items.contains(opC));
    assertTrue(items.contains(deA));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Test(org.junit.Test)

Example 10 with DataElementOperand

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

the class DataValidationTask method runInternal.

private void runInternal() {
    Set<ValidationResult> validationResults = new HashSet<>();
    if (!context.isAnalysisComplete()) {
        for (PeriodTypeExtended periodTypeX : context.getPeriodTypeExtendedMap().values()) {
            log.trace("Validation PeriodType " + periodTypeX.getPeriodType().getName());
            Set<ValidationRuleExtended> ruleXs = getRulesBySourceAndPeriodType(orgUnit, periodTypeX);
            SetMap<String, DataElementOperand> dataElementOperandsToGet = getDataElementOperands(ruleXs);
            if (!ruleXs.isEmpty()) {
                for (Period period : periodTypeX.getPeriods()) {
                    MapMap<String, DataElementOperand, Date> lastUpdatedMap = new MapMap<>();
                    MapMap<String, DimensionalItemObject, Double> dataValueMap = getDataValueMap(dataElementOperandsToGet, periodTypeX.getAllowedPeriodTypes(), period, orgUnit, lastUpdatedMap);
                    MapMap<String, DimensionalItemObject, Double> slidingWindowEventMap = getEventMapForSlidingWindow(context.getEventItems(), period, orgUnit);
                    slidingWindowEventMap.putMap(dataValueMap);
                    MapMap<String, DimensionalItemObject, Double> eventMap = getEventMap(context.getEventItems(), period, orgUnit);
                    dataValueMap.putMap(eventMap);
                    log.trace("OrgUnit " + orgUnit.getName() + " [" + period.getStartDate() + " - " + period.getEndDate() + "]" + " currentValueMap[" + dataValueMap.size() + "]");
                    for (ValidationRuleExtended ruleX : ruleXs) {
                        ValidationRule rule = ruleX.getRule();
                        log.trace("Validation rule " + rule.getUid() + " " + rule.getName());
                        Map<String, Double> leftSideValues;
                        if (rule.getLeftSide() != null && rule.getLeftSide().getSlidingWindow()) {
                            leftSideValues = getExpressionValueMap(rule.getLeftSide(), slidingWindowEventMap, period);
                        } else {
                            leftSideValues = getExpressionValueMap(rule.getLeftSide(), dataValueMap, period);
                        }
                        Map<String, Double> rightSideValues;
                        if (rule.getRightSide() != null && rule.getRightSide().getSlidingWindow()) {
                            rightSideValues = getExpressionValueMap(rule.getRightSide(), slidingWindowEventMap, period);
                        } else {
                            rightSideValues = getExpressionValueMap(rule.getRightSide(), dataValueMap, period);
                        }
                        Set<String> attributeOptionCombos = Sets.newHashSet(leftSideValues.keySet());
                        attributeOptionCombos.addAll(rightSideValues.keySet());
                        for (String optionCombo : attributeOptionCombos) {
                            log.trace("Validation attributeOptionCombo " + optionCombo);
                            Double leftSide = leftSideValues.get(optionCombo);
                            Double rightSide = rightSideValues.get(optionCombo);
                            boolean violation = false;
                            if (Operator.compulsory_pair.equals(rule.getOperator())) {
                                violation = (leftSide != null && rightSide == null) || (leftSide == null && rightSide != null);
                            } else if (Operator.exclusive_pair.equals(rule.getOperator())) {
                                violation = (leftSide != null && rightSide != null);
                            } else {
                                if (leftSide == null && rule.getLeftSide().getMissingValueStrategy() == NEVER_SKIP) {
                                    leftSide = 0d;
                                }
                                if (rightSide == null && rule.getRightSide().getMissingValueStrategy() == NEVER_SKIP) {
                                    rightSide = 0d;
                                }
                                if (leftSide != null && rightSide != null) {
                                    violation = !expressionIsTrue(leftSide, rule.getOperator(), rightSide);
                                }
                            }
                            if (violation) {
                                validationResults.add(new ValidationResult(rule, period, orgUnit, categoryService.getDataElementCategoryOptionCombo(optionCombo), roundSignificant(zeroIfNull(leftSide)), roundSignificant(zeroIfNull(rightSide)), periodService.getDayInPeriod(period, new Date())));
                            }
                            log.debug("Evaluated " + rule.getName() + ", combo id " + optionCombo + ": " + (violation ? "violation" : "OK") + " " + (leftSide == null ? "(null)" : leftSide.toString()) + " " + rule.getOperator() + " " + (rightSide == null ? "(null)" : rightSide.toString()) + " (" + context.getValidationResults().size() + " results)");
                        }
                    }
                }
            }
        }
    }
    if (validationResults.size() > 0) {
        context.getValidationResults().addAll(validationResults);
        if (context.isPersistResults()) {
            validationResultService.saveValidationResults(validationResults);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Period(org.hisp.dhis.period.Period)

Aggregations

DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)28 DataElement (org.hisp.dhis.dataelement.DataElement)12 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 Period (org.hisp.dhis.period.Period)6 Test (org.junit.Test)6 DataSet (org.hisp.dhis.dataset.DataSet)5 List (java.util.List)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)3 Section (org.hisp.dhis.dataset.Section)3 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)3 User (org.hisp.dhis.user.User)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2