Search in sources :

Example 51 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand 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 52 with DataElementOperand

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

the class CompleteDataSetRegistrationServiceTest method testGetMissingCompulsoryFields.

@Test
void testGetMissingCompulsoryFields() {
    DataElementOperand compulsoryA = new DataElementOperand(elementA, optionCombo);
    DataElementOperand compulsoryB = new DataElementOperand(elementB, optionCombo);
    DataElementOperand compulsoryC = new DataElementOperand(elementC, optionCombo);
    dataSetA.addCompulsoryDataElementOperand(compulsoryA);
    dataSetA.addCompulsoryDataElementOperand(compulsoryB);
    dataSetA.addCompulsoryDataElementOperand(compulsoryC);
    dataValueService.addDataValue(new DataValue(elementA, periodA, sourceA, optionCombo, optionCombo, "10"));
    dataValueService.addDataValue(new DataValue(elementE, periodA, sourceA, optionCombo, optionCombo, "20"));
    List<DataElementOperand> missingFields = completeDataSetRegistrationService.getMissingCompulsoryFields(dataSetA, periodA, sourceA, optionCombo);
    Collections.sort(missingFields);
    assertEquals(2, missingFields.size());
    assertEquals("DataElementB", missingFields.get(0).getDataElement().getName());
    assertEquals("DataElementC", missingFields.get(1).getDataElement().getName());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataValue(org.hisp.dhis.datavalue.DataValue) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 53 with DataElementOperand

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

the class DimensionServiceTest method setUpTest.

@Override
public void setUpTest() {
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    deC.setDomainType(DataElementDomain.TRACKER);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    cocA = categoryService.getDefaultCategoryOptionCombo();
    dsA = createDataSet('A');
    dataSetService.addDataSet(dsA);
    prA = createProgram('A');
    idObjectManager.save(prA);
    psA = createProgramStage('A', 1);
    idObjectManager.save(psA);
    atA = createTrackedEntityAttribute('A');
    idObjectManager.save(atA);
    piA = createProgramIndicator('A', prA, null, null);
    idObjectManager.save(piA);
    peA = createPeriod("201201");
    peB = createPeriod("201202");
    peLast12Months = new BaseDimensionalItemObject(LAST_12_MONTHS.toString());
    peA.setUid("201201");
    peB.setUid("201202");
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    ouD = createOrganisationUnit('D');
    ouE = createOrganisationUnit('E');
    ouB.updateParent(ouA);
    ouC.updateParent(ouA);
    ouD.updateParent(ouB);
    ouE.updateParent(ouB);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    organisationUnitService.addOrganisationUnit(ouD);
    organisationUnitService.addOrganisationUnit(ouE);
    String level2 = KEY_LEVEL + 2;
    ouUser = new BaseDimensionalItemObject(KEY_USER_ORGUNIT);
    ouLevel2 = new BaseDimensionalItemObject(level2);
    deGroupSetA = createDataElementGroupSet('A');
    dataElementService.addDataElementGroupSet(deGroupSetA);
    deGroupA = createDataElementGroup('A');
    deGroupB = createDataElementGroup('B');
    deGroupC = createDataElementGroup('C');
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupB.getGroupSets().add(deGroupSetA);
    deGroupC.getGroupSets().add(deGroupSetA);
    dataElementService.addDataElementGroup(deGroupA);
    dataElementService.addDataElementGroup(deGroupB);
    dataElementService.addDataElementGroup(deGroupC);
    deGroupSetA.getMembers().add(deGroupA);
    deGroupSetA.getMembers().add(deGroupB);
    deGroupSetA.getMembers().add(deGroupC);
    dataElementService.updateDataElementGroupSet(deGroupSetA);
    ouGroupSetA = createOrganisationUnitGroupSet('A');
    organisationUnitGroupService.addOrganisationUnitGroupSet(ouGroupSetA);
    ouGroupA = createOrganisationUnitGroup('A');
    ouGroupB = createOrganisationUnitGroup('B');
    ouGroupC = createOrganisationUnitGroup('C');
    ouGroupA.getGroupSets().add(ouGroupSetA);
    ouGroupB.getGroupSets().add(ouGroupSetA);
    ouGroupC.getGroupSets().add(ouGroupSetA);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupC);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupA);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupB);
    ouGroupSetA.getOrganisationUnitGroups().add(ouGroupC);
    organisationUnitGroupService.updateOrganisationUnitGroupSet(ouGroupSetA);
    queryModsA = QueryModifiers.builder().periodOffset(10).build();
    queryModsB = QueryModifiers.builder().minDate(new Date()).build();
    queryModsC = QueryModifiers.builder().maxDate(new Date()).build();
    itemObjectA = deA;
    itemObjectB = new DataElementOperand(deA, cocA);
    itemObjectC = new DataElementOperand(deA, null, cocA);
    itemObjectD = new DataElementOperand(deA, cocA, cocA);
    itemObjectE = new ReportingRate(dsA);
    itemObjectF = new ProgramDataElementDimensionItem(prA, deA);
    itemObjectG = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
    itemObjectH = piA;
    itemIdA = new DimensionalItemId(DATA_ELEMENT, deA.getUid());
    itemIdB = new DimensionalItemId(DATA_ELEMENT_OPERAND, deA.getUid(), cocA.getUid());
    itemIdC = new DimensionalItemId(DATA_ELEMENT_OPERAND, deA.getUid(), null, cocA.getUid());
    itemIdD = new DimensionalItemId(DATA_ELEMENT_OPERAND, deA.getUid(), cocA.getUid(), cocA.getUid());
    itemIdE = new DimensionalItemId(REPORTING_RATE, dsA.getUid(), ReportingRateMetric.REPORTING_RATE.name());
    itemIdF = new DimensionalItemId(PROGRAM_DATA_ELEMENT, prA.getUid(), deA.getUid());
    itemIdG = new DimensionalItemId(PROGRAM_ATTRIBUTE, prA.getUid(), atA.getUid());
    itemIdH = new DimensionalItemId(PROGRAM_INDICATOR, piA.getUid());
    itemIds = new HashSet<>();
    itemIds.add(itemIdA);
    itemIds.add(itemIdB);
    itemIds.add(itemIdC);
    itemIds.add(itemIdD);
    itemIds.add(itemIdE);
    itemIds.add(itemIdF);
    itemIds.add(itemIdG);
    itemIds.add(itemIdH);
    itemMap = ImmutableMap.<DimensionalItemId, DimensionalItemObject>builder().put(itemIdA, itemObjectA).put(itemIdB, itemObjectB).put(itemIdC, itemObjectC).put(itemIdD, itemObjectD).put(itemIdE, itemObjectE).put(itemIdF, itemObjectF).put(itemIdG, itemObjectG).put(itemIdH, itemObjectH).build();
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) ReportingRate(org.hisp.dhis.common.ReportingRate) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) Date(java.util.Date) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Example 54 with DataElementOperand

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

the class ExpressionService2Test method testGetIndicatorDimensionalItemMap2.

@Test
void testGetIndicatorDimensionalItemMap2() {
    Set<DimensionalItemId> itemIds = Sets.newHashSet(getId(opA));
    Map<DimensionalItemId, DimensionalItemObject> expectedItemMap = ImmutableMap.of(getId(opA), opA);
    when(dimensionService.getDataDimensionalItemObjectMap(itemIds)).thenReturn(expectedItemMap);
    mockConstantService();
    IndicatorType indicatorType = new IndicatorType("A", 100, false);
    Indicator indicatorA = createIndicator('A', indicatorType);
    indicatorA.setNumerator(expressionE);
    indicatorA.setDenominator(expressionF);
    List<Indicator> indicators = Arrays.asList(indicatorA);
    Map<DimensionalItemId, DimensionalItemObject> itemMap = target.getIndicatorDimensionalItemMap(indicators);
    Map<DimensionalItemObject, Object> valueMap = new HashMap<>();
    valueMap.put(new DataElementOperand(deA, coc), 12d);
    IndicatorValue value = target.getIndicatorValueObject(indicatorA, Collections.singletonList(period), itemMap, valueMap, null);
    assertNotNull(value);
    assertEquals(24d, value.getNumeratorValue(), DELTA);
    assertEquals(12d, value.getDenominatorValue(), DELTA);
    assertEquals(100, value.getMultiplier());
    assertEquals(1, value.getDivisor());
    assertEquals(100d, value.getFactor(), DELTA);
    assertEquals(200d, value.getValue(), DELTA);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorType(org.hisp.dhis.indicator.IndicatorType) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 55 with DataElementOperand

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

the class ExpressionService2Test method testAnnualizedIndicatorValueWhenHavingNullPeriods.

@Test
void testAnnualizedIndicatorValueWhenHavingNullPeriods() {
    Set<DimensionalItemId> itemIds = Sets.newHashSet(getId(opA));
    Map<DimensionalItemId, DimensionalItemObject> expectedItemMap = ImmutableMap.of(getId(opA), opA);
    when(dimensionService.getDataDimensionalItemObjectMap(itemIds)).thenReturn(expectedItemMap);
    mockConstantService();
    IndicatorType indicatorType = new IndicatorType("A", 100, false);
    Indicator indicatorA = createIndicator('A', indicatorType);
    indicatorA.setAnnualized(true);
    indicatorA.setNumerator(expressionE);
    indicatorA.setDenominator(expressionF);
    Map<DimensionalItemObject, Object> valueMap = new HashMap<>();
    valueMap.put(new DataElementOperand(deA, coc), 12d);
    valueMap.put(new DataElementOperand(deB, coc), 34d);
    valueMap.put(new DataElementOperand(deA, cocA, cocB), 46d);
    valueMap.put(new DataElementOperand(deB, cocA), 10d);
    Map<DimensionalItemId, DimensionalItemObject> itemMap = target.getIndicatorDimensionalItemMap(Arrays.asList(indicatorA));
    IndicatorValue value = target.getIndicatorValueObject(indicatorA, null, itemMap, valueMap, null);
    assertNotNull(value);
    assertEquals(24d, value.getNumeratorValue(), DELTA);
    assertEquals(12d, value.getDenominatorValue(), DELTA);
    assertEquals(100, value.getMultiplier());
    assertEquals(1, value.getDivisor());
    assertEquals(100.0d, Precision.round(value.getFactor(), 2), DELTA);
    assertEquals(200.0d, Precision.round(value.getValue(), 2), DELTA);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorType(org.hisp.dhis.indicator.IndicatorType) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)75 DataElement (org.hisp.dhis.dataelement.DataElement)36 Test (org.junit.jupiter.api.Test)30 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)25 Period (org.hisp.dhis.period.Period)24 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)23 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)17 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)14 PeriodType.getPeriodFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodFromIsoString)14 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 Indicator (org.hisp.dhis.indicator.Indicator)11 HashMap (java.util.HashMap)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 IndicatorType (org.hisp.dhis.indicator.IndicatorType)10 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)9 DataSet (org.hisp.dhis.dataset.DataSet)9 ArrayList (java.util.ArrayList)8 DataValue (org.hisp.dhis.datavalue.DataValue)8 List (java.util.List)7