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