use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class GetValidationResultDetailsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
validationRule = validationRuleService.getValidationRule(validationRuleId);
Period period = periodService.getPeriod(periodId);
OrganisationUnit source = organisationUnitService.getOrganisationUnit(sourceId);
for (DataElementOperand operand : expressionService.getOperandsInExpression(validationRule.getLeftSide().getExpression())) {
DataValue dataValue = dataValueService.getDataValue(operand.getDataElement(), period, source, operand.getCategoryOptionCombo());
String value = dataValue != null ? dataValue.getValue() : NULL_REPLACEMENT;
leftSideMap.put(operand.getName(), value);
}
for (DataElementOperand operand : expressionService.getOperandsInExpression(validationRule.getRightSide().getExpression())) {
DataValue dataValue = dataValueService.getDataValue(operand.getDataElement(), period, source, operand.getCategoryOptionCombo());
String value = dataValue != null ? dataValue.getValue() : NULL_REPLACEMENT;
rightSideMap.put(operand.getName(), value);
}
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DefaultValidationService method getDimensionalItemObjects.
/**
* Gets all required DimensionalItemObjects from their UIDs.
*
* @param expressionIdMap UIDs of DimensionalItemObjects to get.
* @return map of the DimensionalItemObjects.
*/
private Map<String, DimensionalItemObject> getDimensionalItemObjects(SetMap<Class<? extends DimensionalItemObject>, String> expressionIdMap) {
// 1. Get ids for all the individual IdentifiableObjects within the DimensionalItemObjects:
SetMap<Class<? extends IdentifiableObject>, String> idsToGet = new SetMap<>();
getIdentifiableObjectIds(idsToGet, expressionIdMap, DataElementOperand.class, DataElement.class, DataElementCategoryOptionCombo.class);
getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramDataElementDimensionItem.class, Program.class, DataElement.class);
getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramTrackedEntityAttributeDimensionItem.class, Program.class, TrackedEntityAttribute.class);
getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramIndicator.class, ProgramIndicator.class);
// 2. Look up all the IdentifiableObjects (each class all together, for best performance):
MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> idMap = new MapMap<>();
for (Map.Entry<Class<? extends IdentifiableObject>, Set<String>> e : idsToGet.entrySet()) {
idMap.putEntries(e.getKey(), idObjectManager.get(e.getKey(), e.getValue()).stream().collect(Collectors.toMap(o -> o.getUid(), o -> o)));
}
// 3. Build the map of DimensionalItemObjects:
Map<String, DimensionalItemObject> dimObjects = new HashMap<>();
for (Map.Entry<Class<? extends DimensionalItemObject>, Set<String>> e : expressionIdMap.entrySet()) {
for (String id : e.getValue()) {
if (e.getKey() == DataElementOperand.class) {
DataElementOperand deo = new DataElementOperand((DataElement) idMap.getValue(DataElement.class, getIdPart(id, 0)), (DataElementCategoryOptionCombo) idMap.getValue(DataElementCategoryOptionCombo.class, getIdPart(id, 1)));
if (deo.getDataElement() != null && (deo.getCategoryOptionCombo() != null || getIdPart(id, 1) == null)) {
dimObjects.put(id, deo);
}
} else if (e.getKey() == ProgramDataElementDimensionItem.class) {
ProgramDataElementDimensionItem pde = new ProgramDataElementDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (DataElement) idMap.getValue(DataElement.class, getIdPart(id, 1)));
if (pde.getProgram() != null && pde.getDataElement() != null) {
dimObjects.put(id, pde);
}
} else if (e.getKey() == ProgramTrackedEntityAttributeDimensionItem.class) {
ProgramTrackedEntityAttributeDimensionItem pa = new ProgramTrackedEntityAttributeDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (TrackedEntityAttribute) idMap.getValue(TrackedEntityAttribute.class, getIdPart(id, 1)));
if (pa.getProgram() != null && pa.getAttribute() != null) {
dimObjects.put(id, pa);
}
} else if (e.getKey() == ProgramIndicator.class) {
ProgramIndicator pi = (ProgramIndicator) idMap.getValue(ProgramIndicator.class, id);
if (pi != null) {
dimObjects.put(id, pi);
}
}
}
}
return dimObjects;
}
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, DataElementCategoryOptionCombo attributeOptionCombo) {
List<DataElementOperand> violations = new ArrayList<>();
if (dataSet.isNoValueRequiresComment()) {
for (DataElement de : dataSet.getDataElements()) {
for (DataElementCategoryOptionCombo 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;
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataSetCompletenessServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
setExternalTestDir(locationManager);
categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
periodType = new MonthlyPeriodType();
periodA = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 1, 31));
periodB = createPeriod(periodType, getDate(2000, 2, 1), getDate(2000, 2, 28));
periodC = createPeriod(new QuarterlyPeriodType(), getDate(2000, 1, 1), getDate(2000, 3, 31));
periodIdA = periodService.addPeriod(periodA);
periodService.addPeriod(periodB);
periodIdC = periodService.addPeriod(periodC);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
unitC = createOrganisationUnit('C');
unitD = createOrganisationUnit('D');
unitE = createOrganisationUnit('E');
unitF = createOrganisationUnit('F');
unitG = createOrganisationUnit('G');
unitH = createOrganisationUnit('H');
unitB.setParent(unitA);
unitC.setParent(unitA);
unitE.setParent(unitB);
unitF.setParent(unitB);
unitG.setParent(unitC);
unitH.setParent(unitC);
unitA.getChildren().add(unitB);
unitA.getChildren().add(unitC);
unitB.getChildren().add(unitE);
unitB.getChildren().add(unitF);
unitC.getChildren().add(unitG);
unitC.getChildren().add(unitH);
unitIdA = organisationUnitService.addOrganisationUnit(unitA);
unitIdB = organisationUnitService.addOrganisationUnit(unitB);
unitIdC = organisationUnitService.addOrganisationUnit(unitC);
organisationUnitService.addOrganisationUnit(unitD);
organisationUnitService.addOrganisationUnit(unitE);
organisationUnitService.addOrganisationUnit(unitF);
organisationUnitService.addOrganisationUnit(unitG);
organisationUnitService.addOrganisationUnit(unitH);
unitIdsA = new HashSet<>();
unitIdsA.add(unitIdA);
unitIdsA.add(unitIdB);
unitIdsA.add(unitIdC);
groupA = createOrganisationUnitGroup('A');
groupB = createOrganisationUnitGroup('B');
groupC = createOrganisationUnitGroup('C');
groupA.addOrganisationUnit(unitA);
groupB.addOrganisationUnit(unitA);
groupB.addOrganisationUnit(unitB);
groupC.addOrganisationUnit(unitE);
groupC.addOrganisationUnit(unitF);
organisationUnitGroupService.addOrganisationUnitGroup(groupA);
organisationUnitGroupService.addOrganisationUnitGroup(groupB);
organisationUnitGroupService.addOrganisationUnitGroup(groupC);
dataSetA = createDataSet('A', periodType);
dataSetB = createDataSet('B', periodType);
dataSetC = createDataSet('C', periodType);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataSetA.getCompulsoryDataElementOperands().add(new DataElementOperand(dataElementA, categoryOptionCombo));
dataSetA.getCompulsoryDataElementOperands().add(new DataElementOperand(dataElementB, categoryOptionCombo));
dataSetB.getCompulsoryDataElementOperands().add(new DataElementOperand(dataElementA, categoryOptionCombo));
onTimeA = getDate(2000, 2, 10);
tooLateA = getDate(2000, 2, 25);
onTimeB = getDate(2000, 3, 10);
tooLateB = getDate(2000, 3, 25);
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testHandleGridForDataValueSet.
@Test
public void testHandleGridForDataValueSet() {
IndicatorType itA = new IndicatorType();
DataElementCategoryOptionCombo ocA = createCategoryOptionCombo('A');
ocA.setUid("ceabcdefghA");
DataElement dxA = createDataElement('A');
dxA.setUid("deabcdefghA");
dxA.setValueType(ValueType.INTEGER);
DataElement dxB = createDataElement('B');
dxB.setUid("deabcdefghB");
dxB.setValueType(ValueType.NUMBER);
Indicator dxC = createIndicator('C', itA);
dxC.setUid("deabcdefghC");
dxC.setDecimals(0);
dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
Indicator dxD = createIndicator('D', itA);
dxD.setUid("deabcdefghD");
dxD.setDecimals(2);
dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
DataElementOperand dxE = new DataElementOperand(dxA, ocA);
DataElementOperand dxF = new DataElementOperand(dxB, ocA);
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
assertEquals(4, grid.getWidth());
assertEquals(6, grid.getHeight());
AnalyticsUtils.handleGridForDataValueSet(params, grid);
assertEquals(6, grid.getWidth());
assertEquals(6, grid.getHeight());
assertEquals("deabcdefghA", grid.getRow(0).get(0));
assertNull(grid.getRow(0).get(3));
assertNull(grid.getRow(0).get(4));
assertEquals(1, grid.getRow(0).get(5));
assertEquals("deabcdefghB", grid.getRow(1).get(0));
assertNull(grid.getRow(1).get(3));
assertNull(grid.getRow(1).get(4));
assertEquals(2d, (Double) grid.getRow(1).get(5), 0.01);
assertEquals("deabcdefghC", grid.getRow(2).get(0));
assertNull(grid.getRow(2).get(3));
assertEquals("ceabcdefghA", grid.getRow(2).get(4));
assertEquals(3, grid.getRow(2).get(5));
assertEquals("deabcdefghD", grid.getRow(3).get(0));
assertEquals("ceabcdefghB", grid.getRow(3).get(3));
assertNull(grid.getRow(3).get(4));
assertEquals(4d, (Double) grid.getRow(3).get(5), 0.01);
assertEquals("deabcdefghA", grid.getRow(4).get(0));
assertEquals("ceabcdefghA", grid.getRow(4).get(3));
assertNull(grid.getRow(4).get(4));
assertEquals(5, grid.getRow(4).get(5));
assertEquals("deabcdefghB", grid.getRow(5).get(0));
assertEquals("ceabcdefghA", grid.getRow(5).get(3));
assertNull(grid.getRow(5).get(4));
assertEquals(6d, (Double) grid.getRow(5).get(5), 0.01);
}
Aggregations