use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method updateAttributeValues.
private void updateAttributeValues(TrackedEntityInstance trackedEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance) {
for (Attribute attribute : trackedEntityInstance.getAttributes()) {
TrackedEntityAttribute entityAttribute = manager.get(TrackedEntityAttribute.class, attribute.getAttribute());
if (entityAttribute != null) {
TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue();
attributeValue.setEntityInstance(entityInstance);
attributeValue.setValue(attribute.getValue());
attributeValue.setAttribute(entityAttribute);
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(attributeValue);
}
}
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testSetItemsForDimensionFilters.
@Test
public void testSetItemsForDimensionFilters() {
TrackedEntityAttribute tea = new TrackedEntityAttribute();
tea.setAutoFields();
TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:2");
EventChart eventChart = new EventChart();
eventChart.setAutoFields();
eventChart.getColumnDimensions().add(tea.getUid());
eventChart.getAttributeDimensions().add(tead);
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(tea.getUid(), tea.getName()));
grid.addRow().addValue("1");
grid.addRow().addValue("2");
grid.addRow().addValue("3");
grid.addRow().addValue(null);
eventChart.populateAnalyticalProperties();
DimensionalObject dim = eventChart.getColumns().get(0);
DimensionalObjectUtils.setDimensionItemsForFilters(dim, grid, true);
assertNotNull(dim);
assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
assertEquals(tead.getFilter(), dim.getFilter());
List<DimensionalItemObject> items = dim.getItems();
assertEquals(4, items.size());
assertNotNull(items.get(0).getUid());
assertNotNull(items.get(0).getName());
assertNotNull(items.get(0).getCode());
assertNotNull(items.get(0).getShortName());
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class DhisConvenienceTest method createTrackedEntityAttribute.
/**
* @param uniqueChar A unique character to identify the object.
* @return TrackedEntityAttribute
*/
public static TrackedEntityAttribute createTrackedEntityAttribute(char uniqueChar) {
TrackedEntityAttribute attribute = new TrackedEntityAttribute();
attribute.setAutoFields();
attribute.setName("Attribute" + uniqueChar);
attribute.setCode("AttributeCode" + uniqueChar);
attribute.setDescription("Attribute" + uniqueChar);
attribute.setValueType(ValueType.TEXT);
attribute.setAggregationType(AggregationType.NONE);
return attribute;
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class DhisConvenienceTest method createTrackedEntityAttribute.
/**
* @param uniqueChar A unique character to identify the object.
* @return TrackedEntityAttribute
*/
public static TrackedEntityAttribute createTrackedEntityAttribute(char uniqueChar, ValueType valueType) {
TrackedEntityAttribute attribute = new TrackedEntityAttribute();
attribute.setAutoFields();
attribute.setName("Attribute" + uniqueChar);
attribute.setCode("AttributeCode" + uniqueChar);
attribute.setDescription("Attribute" + uniqueChar);
attribute.setValueType(valueType);
attribute.setAggregationType(AggregationType.NONE);
return attribute;
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class DefaultProgramIndicatorService method getSubstitutedExpression.
/**
* Generates an expression where all items are substituted with a sample value
* in order to maintain a valid expression syntax.
*
* @param expression the expression.
*/
private String getSubstitutedExpression(String expression) {
StringBuffer expr = new StringBuffer();
Matcher matcher = ProgramIndicator.EXPRESSION_PATTERN.matcher(expression);
while (matcher.find()) {
String key = matcher.group(1);
String uid = matcher.group(2);
if (ProgramIndicator.KEY_DATAELEMENT.equals(key)) {
String de = matcher.group(3);
ProgramStage programStage = programStageService.getProgramStage(uid);
DataElement dataElement = dataElementService.getDataElement(de);
if (programStage != null && dataElement != null) {
String sample = ValidationUtils.getSubstitutionValue(dataElement.getValueType());
matcher.appendReplacement(expr, sample);
} else {
return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
}
} else if (ProgramIndicator.KEY_ATTRIBUTE.equals(key)) {
TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute(uid);
if (attribute != null) {
String sample = ValidationUtils.getSubstitutionValue(attribute.getValueType());
matcher.appendReplacement(expr, sample);
} else {
return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
}
} else if (ProgramIndicator.KEY_CONSTANT.equals(key)) {
Constant constant = constantService.getConstant(uid);
if (constant != null) {
matcher.appendReplacement(expr, String.valueOf(constant.getValue()));
} else {
return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
}
} else if (ProgramIndicator.KEY_PROGRAM_VARIABLE.equals(key)) {
String sampleValue = VARIABLE_SAMPLE_VALUE_MAP.get(uid);
if (sampleValue != null) {
matcher.appendReplacement(expr, sampleValue);
} else {
return ProgramIndicator.UNKNOWN_VARIABLE;
}
}
}
matcher.appendTail(expr);
return expr.toString();
}
Aggregations