dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36509
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18672: Program indicator expression, regex improvement
------------------------------------------------------------
revno: 18672
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-03-24 11:12:48 +0100
message:
Program indicator expression, regex improvement
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java
dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-03-24 09:13:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-03-24 10:12:48 +0000
@@ -64,8 +64,8 @@
public static String SEP_OBJECT = ":";
- public static final String EXPRESSION_REGEXP = "(" + KEY_DATAELEMENT + "|" + KEY_ATTRIBUTE + "|" + KEY_PROGRAM_VARIABLE + "|" + KEY_CONSTANT + ")\\{([a-zA-Z0-9]+|" +
- INCIDENT_DATE + "|" + ENROLLMENT_DATE + "|" + CURRENT_DATE + ")" + SEPARATOR_ID + "*([a-zA-Z0-9]*)\\}";
+ public static final String EXPRESSION_REGEXP = "(" + KEY_DATAELEMENT + "|" + KEY_ATTRIBUTE + "|" + KEY_PROGRAM_VARIABLE + "|" + KEY_CONSTANT + ")\\{(\\w+|" +
+ INCIDENT_DATE + "|" + ENROLLMENT_DATE + "|" + CURRENT_DATE + ")" + SEPARATOR_ID + "?(\\w*)\\}";
public static final Pattern EXPRESSION_PATTERN = Pattern.compile( EXPRESSION_REGEXP );
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-03-24 09:13:12 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-03-24 10:12:48 +0000
@@ -245,14 +245,14 @@
while ( matcher.find() )
{
String key = matcher.group( 1 );
- String uid1 = matcher.group( 2 );
+ String uid = matcher.group( 2 );
if ( ProgramIndicator.KEY_DATAELEMENT.equals( key ) )
{
- String uid2 = matcher.group( 3 );
+ String de = matcher.group( 3 );
- ProgramStage programStage = programStageService.getProgramStage( uid1 );
- DataElement dataElement = dataElementService.getDataElement( uid2 );
+ ProgramStage programStage = programStageService.getProgramStage( uid );
+ DataElement dataElement = dataElementService.getDataElement( de );
if ( programStage != null && dataElement != null )
{
@@ -266,7 +266,7 @@
else if ( ProgramIndicator.KEY_ATTRIBUTE.equals( key ) )
{
- TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid1 );
+ TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid );
if ( attribute != null )
{
@@ -275,7 +275,7 @@
}
else if ( ProgramIndicator.KEY_CONSTANT.equals( key ) )
{
- Constant constant = constantService.getConstant( uid1 );
+ Constant constant = constantService.getConstant( uid );
if ( constant != null )
{
@@ -284,15 +284,15 @@
}
else if ( ProgramIndicator.KEY_PROGRAM_VARIABLE.equals( key ) )
{
- if ( uid1.equals( ProgramIndicator.CURRENT_DATE ) )
+ if ( uid.equals( ProgramIndicator.CURRENT_DATE ) )
{
matcher.appendReplacement( description, "Current date" );
}
- else if ( uid1.equals( ProgramIndicator.ENROLLMENT_DATE ) )
+ else if ( uid.equals( ProgramIndicator.ENROLLMENT_DATE ) )
{
matcher.appendReplacement( description, "Enrollment date" );
}
- else if ( uid1.equals( ProgramIndicator.INCIDENT_DATE ) )
+ else if ( uid.equals( ProgramIndicator.INCIDENT_DATE ) )
{
matcher.appendReplacement( description, "Incident date" );
}
@@ -314,14 +314,14 @@
while ( matcher.find() )
{
String key = matcher.group( 1 );
- String uid1 = matcher.group( 2 );
+ String uid = matcher.group( 2 );
if ( ProgramIndicator.KEY_DATAELEMENT.equals( key ) )
{
- String uid2 = matcher.group( 3 );
+ String de = matcher.group( 3 );
- ProgramStage programStage = programStageService.getProgramStage( uid1 );
- DataElement dataElement = dataElementService.getDataElement( uid2 );
+ ProgramStage programStage = programStageService.getProgramStage( uid );
+ DataElement dataElement = dataElementService.getDataElement( de );
if ( programStage != null && dataElement != null )
{
@@ -335,7 +335,7 @@
else if ( ProgramIndicator.KEY_ATTRIBUTE.equals( key ) )
{
- TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid1 );
+ TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid );
if ( attribute != null )
{
@@ -348,7 +348,7 @@
}
else if ( ProgramIndicator.KEY_CONSTANT.equals( key ) )
{
- Constant constant = constantService.getConstant( uid1 );
+ Constant constant = constantService.getConstant( uid );
if ( constant != null )
{
@@ -392,13 +392,13 @@
while ( matcher.find() )
{
String key = matcher.group( 1 );
- String uid1 = matcher.group( 2 );
+ String uid = matcher.group( 2 );
if ( ProgramIndicator.KEY_DATAELEMENT.equals( key ) )
{
- String uid2 = matcher.group( 3 );
- ProgramStage programStage = programStageService.getProgramStage( uid1 );
- DataElement dataElement = dataElementService.getDataElement( uid2 );
+ String de = matcher.group( 3 );
+ ProgramStage programStage = programStageService.getProgramStage( uid );
+ DataElement dataElement = dataElementService.getDataElement( de );
if ( programStage != null && dataElement != null )
{
@@ -430,7 +430,7 @@
}
else if ( ProgramIndicator.KEY_ATTRIBUTE.equals( key ) )
{
- TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid1 );
+ TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid );
if ( attribute != null )
{
@@ -453,7 +453,7 @@
}
else if ( ProgramIndicator.KEY_CONSTANT.equals( key ) )
{
- Constant constant = constantService.getConstant( uid1 );
+ Constant constant = constantService.getConstant( uid );
if ( constant != null )
{
@@ -469,15 +469,15 @@
Date currentDate = new Date();
Date date = null;
- if ( uid1.equals( ProgramIndicator.ENROLLMENT_DATE ) )
+ if ( uid.equals( ProgramIndicator.ENROLLMENT_DATE ) )
{
date = programInstance.getEnrollmentDate();
}
- else if ( uid1.equals( ProgramIndicator.INCIDENT_DATE ) )
+ else if ( uid.equals( ProgramIndicator.INCIDENT_DATE ) )
{
date = programInstance.getDateOfIncident();
}
- else if ( uid1.equals( ProgramIndicator.CURRENT_DATE ) )
+ else if ( uid.equals( ProgramIndicator.CURRENT_DATE ) )
{
date = programInstance.getDateOfIncident();
}
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java 2015-03-24 09:07:34 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java 2015-03-24 10:12:48 +0000
@@ -153,7 +153,6 @@
indicatorC.setShortName( "C" );
indicatorC.setProgram( programB );
-
indicatorD = new ProgramIndicator( "IndicatorD", "IndicatorDesD", ProgramIndicator.VALUE_TYPE_INT, "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{"
+ ProgramIndicator.INCIDENT_DATE + "}" );
indicatorD.setUid( "UID-D" );