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();
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class ProgramStageInstanceServiceTest method setUpTest.
@Override
public void setUpTest() {
mockFormat = new MockI18nFormat();
organisationUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
entityInstanceA = createTrackedEntityInstance('A', organisationUnitA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
entityInstanceB = createTrackedEntityInstance('B', organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
attribute.setValueType(ValueType.PHONE_NUMBER);
attributeService.addTrackedEntityAttribute(attribute);
TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue('A', entityInstanceA, attribute);
attributeValue.setValue("123456789");
attributeValueService.addTrackedEntityAttributeValue(attributeValue);
entityInstanceA.getTrackedEntityAttributeValues().add(attributeValue);
entityInstanceService.updateTrackedEntityInstance(entityInstanceA);
/**
* Program A
*/
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programService.addProgram(programA);
stageA = createProgramStage('A', 0);
stageA.setProgram(programA);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
stageB = new ProgramStage("B", programA);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
stageDataElementA = new ProgramStageDataElement(stageA, dataElementA, false, 1);
stageDataElementB = new ProgramStageDataElement(stageA, dataElementB, false, 2);
stageDataElementC = new ProgramStageDataElement(stageB, dataElementA, false, 1);
stageDataElementD = new ProgramStageDataElement(stageB, dataElementB, false, 2);
programStageDataElementService.addProgramStageDataElement(stageDataElementA);
programStageDataElementService.addProgramStageDataElement(stageDataElementB);
programStageDataElementService.addProgramStageDataElement(stageDataElementC);
programStageDataElementService.addProgramStageDataElement(stageDataElementD);
/**
* Program B
*/
Program programB = createProgram('B', new HashSet<>(), organisationUnitB);
programService.addProgram(programB);
stageC = new ProgramStage("C", programB);
stageC.setSortOrder(1);
programStageService.saveProgramStage(stageC);
stageD = new ProgramStage("D", programB);
stageB.setSortOrder(2);
stageC.setRepeatable(true);
programStageService.saveProgramStage(stageD);
programStages = new HashSet<>();
programStages.add(stageC);
programStages.add(stageD);
programB.setProgramStages(programStages);
programService.updateProgram(programB);
/**
* Program Instance and Program Stage Instance
*/
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
incidenDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
enrollmentDate = testDate2.toDate();
programInstanceA = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programA);
programInstanceA.setUid("UID-PIA");
programInstanceService.addProgramInstance(programInstanceA);
programInstanceB = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceB, programB);
programInstanceService.addProgramInstance(programInstanceB);
programStageInstanceA = new ProgramStageInstance(programInstanceA, stageA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setUid("UID-A");
programStageInstanceB = new ProgramStageInstance(programInstanceA, stageB);
programStageInstanceB.setDueDate(enrollmentDate);
programStageInstanceB.setUid("UID-B");
programStageInstanceC = new ProgramStageInstance(programInstanceB, stageC);
programStageInstanceC.setDueDate(enrollmentDate);
programStageInstanceC.setUid("UID-C");
programStageInstanceD1 = new ProgramStageInstance(programInstanceB, stageD);
programStageInstanceD1.setDueDate(enrollmentDate);
programStageInstanceD1.setUid("UID-D1");
programStageInstanceD2 = new ProgramStageInstance(programInstanceB, stageD);
programStageInstanceD2.setDueDate(enrollmentDate);
programStageInstanceD2.setUid("UID-D2");
}
Aggregations