dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37177
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19021: Program indicator, added new variable V{zero_pos_value_count}
------------------------------------------------------------
revno: 19021
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-24 19:41:07 +0200
message:
Program indicator, added new variable V{zero_pos_value_count}
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-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm
--
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-04-24 13:39:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-04-24 17:41:07 +0000
@@ -59,7 +59,8 @@
public static final String INCIDENT_DATE = "incident_date";
public static final String ENROLLMENT_DATE = "enrollment_date";
public static final String CURRENT_DATE = "current_date";
- public static final String VALUE_COUNT = "value_count";
+ public static final String VAR_VALUE_COUNT = "value_count";
+ public static final String VAR_ZERO_POS_VALUE_COUNT = "zero_pos_value_count";
public static final String VALUE_TYPE_DATE = "date";
public static final String VALUE_TYPE_INT = "int";
@@ -71,7 +72,7 @@
public static final Pattern EXPRESSION_PATTERN = Pattern.compile( EXPRESSION_REGEXP );
public static final Pattern DATAELEMENT_PATTERN = Pattern.compile( KEY_DATAELEMENT + "\\{(\\w{11})" + SEPARATOR_ID + "(\\w{11})\\}" );
public static final Pattern ATTRIBUTE_PATTERN = Pattern.compile( KEY_ATTRIBUTE + "\\{(\\w{11})\\}" );
- public static final Pattern VALUECOUNT_PATTERN = Pattern.compile( "V\\{value_count\\}" );
+ public static final Pattern VALUECOUNT_PATTERN = Pattern.compile( "V\\{(" + VAR_VALUE_COUNT + "|" + VAR_ZERO_POS_VALUE_COUNT + ")\\}" );
public static final String VALID = "valid";
=== 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-04-24 13:39:16 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-04-24 17:41:07 +0000
@@ -292,10 +292,14 @@
{
matcher.appendReplacement( description, "Incident date" );
}
- else if ( uid.equals( ProgramIndicator.VALUE_COUNT ) )
+ else if ( uid.equals( ProgramIndicator.VAR_VALUE_COUNT ) )
{
matcher.appendReplacement( description, "Value count" );
}
+ else if ( uid.equals( ProgramIndicator.VAR_ZERO_POS_VALUE_COUNT ) )
+ {
+ matcher.appendReplacement( description, "Zero or positive value count" );
+ }
}
}
@@ -437,6 +441,7 @@
Matcher matcher = ProgramIndicator.EXPRESSION_PATTERN.matcher( expression );
int valueCount = 0;
+ int zeroPosValueCount = 0;
while ( matcher.find() )
{
@@ -471,7 +476,8 @@
matcher.appendReplacement( buffer, value );
- valueCount++;
+ valueCount++;
+ zeroPosValueCount = isZeroOrPositive( value ) ? ( zeroPosValueCount + 1 ) : zeroPosValueCount;
}
else
{
@@ -499,6 +505,7 @@
matcher.appendReplacement( buffer, value );
valueCount++;
+ zeroPosValueCount = isZeroOrPositive( value ) ? ( zeroPosValueCount + 1 ) : zeroPosValueCount;
}
else
{
@@ -559,11 +566,25 @@
while ( matcher.find() )
{
- matcher.appendReplacement( buffer, String.valueOf( valueCount ) );
+ String var = matcher.group( 1 );
+
+ if ( ProgramIndicator.VAR_VALUE_COUNT.equals( var ) )
+ {
+ matcher.appendReplacement( buffer, String.valueOf( valueCount ) );
+ }
+ else if ( ProgramIndicator.VAR_ZERO_POS_VALUE_COUNT.equals( var ) )
+ {
+ matcher.appendReplacement( buffer, String.valueOf( zeroPosValueCount ) );
+ }
}
expression = TextUtils.appendTail( matcher, buffer );
return MathUtils.calculateExpression( expression );
}
+
+ private boolean isZeroOrPositive( String value )
+ {
+ return MathUtils.isNumeric( value ) && Double.valueOf( value ) >= 0d;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties 2015-04-24 13:39:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties 2015-04-24 17:41:07 +0000
@@ -79,6 +79,7 @@
add_more_option=Add Option
mandatory=Mandatory
value_count=Value count
+zero_pos_value_count=Zero or positive value count
tracked_entity_attribute_group_management=Tracked entity attribute group management
move_selected=Move selected items
remove_selected=Remove selected items
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm 2015-04-24 13:39:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm 2015-04-24 17:41:07 +0000
@@ -40,6 +40,7 @@
<option value="V{enrollment_date}">$i18n.getString( "date_of_enrollment" )</option>
<option value="V{current_date}">$i18n.getString( "current_date" )</option>
<option value="V{value_count}">$i18n.getString( "value_count" )</option>
+ <option value="V{zero_pos_value_count}">$i18n.getString( "zero_pos_value_count" )</option>
</select>
</td>
</tr>