use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testGetDataElementOperandIdSchemeCodeMap.
@Test
void testGetDataElementOperandIdSchemeCodeMap() {
DataElement deA = new DataElement("NameA");
DataElement deB = new DataElement("NameB");
deA.setUid("D123456789A");
deB.setUid("D123456789B");
deA.setCode("DCodeA");
deB.setCode("DCodeB");
CategoryOptionCombo ocA = new CategoryOptionCombo();
ocA.setUid("C123456789A");
ocA.setCode("CCodeA");
DataElementOperand opA = new DataElementOperand(deA, ocA);
DataElementOperand opB = new DataElementOperand(deB, ocA);
List<DataElementOperand> operands = Lists.newArrayList(opA, opB);
Map<String, String> map = DimensionalObjectUtils.getDataElementOperandIdSchemeMap(operands, IdScheme.CODE);
assertEquals(3, map.size());
assertEquals("DCodeA", map.get("D123456789A"));
assertEquals("DCodeB", map.get("D123456789B"));
assertEquals("CCodeA", map.get("C123456789A"));
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataHandler method addDataElementOperandValues.
/**
* Adds data element operand values to the given grid.
*
* @param params the {@link DataQueryParams}.
* @param grid the grid.
* @param totalType the operand {@link TotalType}.
*/
private void addDataElementOperandValues(DataQueryParams params, Grid grid, TotalType totalType) {
List<DataElementOperand> operands = asTypedList(params.getDataElementOperands());
operands = operands.stream().filter(o -> totalType.equals(o.getTotalType())).collect(Collectors.toList());
if (operands.isEmpty()) {
return;
}
List<DimensionalItemObject> dataElements = newArrayList(getDataElements(operands));
List<DimensionalItemObject> categoryOptionCombos = newArrayList(getCategoryOptionCombos(operands));
List<DimensionalItemObject> attributeOptionCombos = newArrayList(getAttributeOptionCombos(operands));
// TODO Check if data was dim or filter
DataQueryParams.Builder builder = newBuilder(params).removeDimension(DATA_X_DIM_ID).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DATA_X, dataElements));
if (totalType.isCategoryOptionCombo()) {
builder.addDimension(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID, CATEGORY_OPTION_COMBO, categoryOptionCombos));
}
if (totalType.isAttributeOptionCombo()) {
builder.addDimension(new BaseDimensionalObject(ATTRIBUTEOPTIONCOMBO_DIM_ID, ATTRIBUTE_OPTION_COMBO, attributeOptionCombos));
}
DataQueryParams operandParams = builder.build();
Map<String, Object> aggregatedDataMap = getAggregatedDataValueMapObjectTyped(operandParams);
aggregatedDataMap = convertDxToOperand(aggregatedDataMap, totalType);
for (Map.Entry<String, Object> entry : aggregatedDataMap.entrySet()) {
Object value = getRoundedValueObject(operandParams, entry.getValue());
grid.addRow().addValues(entry.getKey().split(DIMENSION_SEP)).addValue(value);
if (params.isIncludeNumDen()) {
grid.addNullValues(NUMERATOR_DENOMINATOR_PROPERTIES_COUNT);
}
}
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataQueryServiceTest method testGetDimensionOperand.
@Test
void testGetDimensionOperand() {
DataElementOperand opA = new DataElementOperand(deA, cocA);
DataElementOperand opB = new DataElementOperand(deB, cocA);
DataElementOperand opC = new DataElementOperand(deC, cocA);
List<DimensionalItemObject> items = Lists.newArrayList(opA, opB, opC);
List<String> itemUids = DimensionalObjectUtils.getDimensionalItemIds(items);
DimensionalObject actual = dataQueryService.getDimension(DimensionalObject.DATA_X_DIM_ID, itemUids, null, null, null, false, false, IdScheme.UID);
assertEquals(DimensionalObject.DATA_X_DIM_ID, actual.getDimension());
assertEquals(DimensionType.DATA_X, actual.getDimensionType());
assertEquals(DataQueryParams.DISPLAY_NAME_DATA_X, actual.getDimensionDisplayName());
assertEquals(items, actual.getItems());
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToNameForDataValueSet.
@Test
void testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToNameForDataValueSet() {
// 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(NAME);
// 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.getName())));
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()));
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeOverridesOutputOrgUnitIdSchemeForDataValueSet.
@Test
void testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeOverridesOutputOrgUnitIdSchemeForDataValueSet() {
// 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.setOutputIdScheme(NAME);
// Overriding output id schema and setting CODE for Data
// Element/Operands
theDataQueryParams.setOutputDataElementIdScheme(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.getName())));
assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getName())));
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())));
}
Aggregations