Search in sources :

Example 31 with DataElementOperand

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

the class SchemaIdResponseMapperTest method stubDataElementOperands.

private List<DataElementOperand> stubDataElementOperands() {
    final DataElement dataElementA = new DataElement("NameA");
    dataElementA.setUid("uid1234567A");
    dataElementA.setCode("CodeA");
    final DataElement dataElementB = new DataElement("NameB");
    dataElementB.setUid("uid1234567B");
    dataElementB.setCode("CodeB");
    final CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
    categoryOptionCombo.setName("NameC");
    categoryOptionCombo.setUid("uid1234567C");
    categoryOptionCombo.setCode("CodeC");
    final DataElementOperand dataElementOperandA = new DataElementOperand(dataElementA, categoryOptionCombo);
    final DataElementOperand dataElementOperandB = new DataElementOperand(dataElementB, categoryOptionCombo);
    return newArrayList(dataElementOperandA, dataElementOperandB);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 32 with DataElementOperand

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

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputIdSchemeIsSetToUid.

@Test
void testGetSchemeIdResponseMapWhenOutputIdSchemeIsSetToUid() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub);
    theDataQueryParams.setOutputIdScheme(UUID);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(emptyOrNullString()));
    assertThat(responseMap.get(periodIsoDate), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementA.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementB.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 33 with DataElementOperand

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

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToCodeForDataValueSet.

@Test
void testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToCodeForDataValueSet() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
    theDataQueryParams.setOutputOrgUnitIdScheme(CODE);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(equalTo(orUnitStub.getCode())));
    assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getUid())));
    assertThat(responseMap.get(dataElementA.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementB.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 34 with DataElementOperand

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

the class QueryValidatorTest method setUp.

@BeforeEach
public void setUp() {
    queryValidator = new DefaultQueryValidator(mock(SystemSettingManager.class));
    PeriodType pt = new MonthlyPeriodType();
    coA = createCategoryOption('A');
    coB = createCategoryOption('B');
    coC = createCategoryOption('C');
    coD = createCategoryOption('D');
    caA = createCategory('A', coA, coB);
    caB = createCategory('B', coC, coD);
    ccA = createCategoryCombo('A', caA);
    ccB = createCategoryCombo('B', caB);
    ccB.setSkipTotal(true);
    cocC = createCategoryOptionCombo(ccB, coC);
    cocD = createCategoryOptionCombo(ccB, coD);
    itA = createIndicatorType('A');
    inA = createIndicator('A', itA);
    inB = createIndicator('B', itA);
    prA = createProgram('A');
    deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
    deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM);
    deC = createDataElement('C', ValueType.INTEGER, AggregationType.SUM);
    deA.setCategoryCombo(ccA);
    deB.setCategoryCombo(ccA);
    deC.setCategoryCombo(ccB);
    pdeA = new ProgramDataElementDimensionItem(prA, deA);
    pdeB = new ProgramDataElementDimensionItem(prA, deB);
    doC = new DataElementOperand(deC, cocC);
    doD = new DataElementOperand(deC, cocD);
    DataSet dsA = createDataSet('A', pt);
    rrA = new ReportingRate(dsA);
    peA = PeriodType.getPeriodFromIsoString("201501");
    peB = PeriodType.getPeriodFromIsoString("201502");
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    degA = createDataElementGroup('A');
    degA.addDataElement(deA);
    degA.addDataElement(deB);
    dgsA = createDataElementGroupSet('A');
    dgsA.getMembers().add(degA);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with DataElementOperand

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

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