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());
}
}
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;
}
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;
}
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())));
}
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()));
}
Aggregations