Search in sources :

Example 36 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DataValueSetImportValidator method checkDataValuePeriodWithinAttrOptionComboRange.

private static void checkDataValuePeriodWithinAttrOptionComboRange(DataValueEntry dataValue, ImportContext context, DataSetContext dataSetContext, DataValueContext valueContext) {
    final CategoryOptionCombo aoc = valueContext.getAttrOptionCombo();
    DateRange aocDateRange = dataSetContext.getDataSet() != null ? context.getAttrOptionComboDateRangeMap().get(valueContext.getAttrOptionCombo().getUid() + dataSetContext.getDataSet().getUid(), () -> aoc.getDateRange(dataSetContext.getDataSet())) : context.getAttrOptionComboDateRangeMap().get(valueContext.getAttrOptionCombo().getUid() + valueContext.getDataElement().getUid(), () -> aoc.getDateRange(valueContext.getDataElement()));
    if ((aocDateRange.getStartDate() != null && aocDateRange.getStartDate().after(valueContext.getPeriod().getEndDate())) || (aocDateRange.getEndDate() != null && aocDateRange.getEndDate().before(valueContext.getPeriod().getStartDate()))) {
        context.addConflict(valueContext.getIndex(), DataValueImportConflict.PERIOD_NOT_VALID_FOR_ATTR_OPTION_COMBO, dataValue.getPeriod(), dataValue.getAttributeOptionCombo());
    }
}
Also used : DateRange(org.hisp.dhis.common.DateRange) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 37 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DefaultDataValueSetService method getDataValueTemplate.

private CollectionNode getDataValueTemplate(DataElement dataElement, String deScheme, OrganisationUnit organisationUnit, String ouScheme, Period period, boolean comment) {
    CollectionNode collectionNode = new CollectionNode("dataValues");
    collectionNode.setWrapping(false);
    for (CategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
        ComplexNode complexNode = collectionNode.addChild(new ComplexNode("dataValue"));
        String label = dataElement.getDisplayName();
        if (!categoryOptionCombo.isDefault()) {
            label += " " + categoryOptionCombo.getDisplayName();
        }
        if (comment) {
            complexNode.setComment("Data element: " + label);
        }
        if (IdentifiableProperty.CODE.toString().toLowerCase().equals(deScheme.toLowerCase())) {
            SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getCode()));
            simpleNode.setAttribute(true);
        } else {
            SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getUid()));
            simpleNode.setAttribute(true);
        }
        SimpleNode simpleNode = complexNode.addChild(new SimpleNode("categoryOptionCombo", categoryOptionCombo.getUid()));
        simpleNode.setAttribute(true);
        simpleNode = complexNode.addChild(new SimpleNode("period", period != null ? period.getIsoDate() : ""));
        simpleNode.setAttribute(true);
        if (organisationUnit != null) {
            if (IdentifiableProperty.CODE.toString().equalsIgnoreCase(ouScheme)) {
                simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getCode() == null ? "" : organisationUnit.getCode()));
                simpleNode.setAttribute(true);
            } else {
                simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getUid() == null ? "" : organisationUnit.getUid()));
                simpleNode.setAttribute(true);
            }
        }
        simpleNode = complexNode.addChild(new SimpleNode("value", ""));
        simpleNode.setAttribute(true);
    }
    return collectionNode;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 38 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class CategoryComboTest method createCategoryOptionCombo.

private static CategoryOptionCombo createCategoryOptionCombo(CategoryCombo categoryCombo, CategoryOption... categoryOptions) {
    CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
    categoryOptionCombo.setCategoryCombo(categoryCombo);
    for (CategoryOption categoryOption : categoryOptions) {
        categoryOptionCombo.getCategoryOptions().add(categoryOption);
    }
    return categoryOptionCombo;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 39 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputIdSchemeIsSetToCode.

@Test
void testGetSchemeIdResponseMapWhenOutputIdSchemeIsSetToCode() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub);
    theDataQueryParams.setOutputIdScheme(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(emptyOrNullString()));
    assertThat(responseMap.get(dataElementA.getUid()), is(equalTo(dataElementA.getCode())));
    assertThat(responseMap.get(dataElementB.getUid()), is(equalTo(dataElementB.getCode())));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
}
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 40 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToUuidForDataValueSet.

@Test
void testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToUuidForDataValueSet() {
    // 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(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(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)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16