=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2014-05-27 02:41:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2014-06-23 08:05:34 +0000
@@ -29,6 +29,7 @@
*/
import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid;
+import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsZeroAndInsignificant;
import java.util.Calendar;
import java.util.Collection;
@@ -82,6 +83,10 @@
public boolean addDataValue( DataValue dataValue )
{
+ // ---------------------------------------------------------------------
+ // Validation
+ // ---------------------------------------------------------------------
+
if ( dataValue == null || dataValue.isNullValue() )
{
log.info( "Data value is null" );
@@ -96,6 +101,18 @@
return false;
}
+ boolean zeroInsignificant = dataValueIsZeroAndInsignificant( dataValue.getValue(), dataValue.getDataElement() );
+
+ if ( zeroInsignificant )
+ {
+ log.info( "Data value is zero and insignificant" );
+ return false;
+ }
+
+ // ---------------------------------------------------------------------
+ // Save
+ // ---------------------------------------------------------------------
+
if ( dataValue.getCategoryOptionCombo() == null )
{
dataValue.setCategoryOptionCombo( categoryService.getDefaultDataElementCategoryOptionCombo() );
@@ -105,7 +122,7 @@
{
dataValue.setAttributeOptionCombo( categoryService.getDefaultDataElementCategoryOptionCombo() );
}
-
+
dataValueStore.addDataValue( dataValue );
return true;
@@ -113,7 +130,7 @@
public void updateDataValue( DataValue dataValue )
{
- if ( dataValue.isNullValue() )
+ if ( dataValue.isNullValue() || dataValueIsZeroAndInsignificant( dataValue.getValue(), dataValue.getDataElement() ) )
{
deleteDataValue( dataValue );
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2014-06-23 08:05:34 +0000
@@ -241,7 +241,7 @@
* given data element. Considers the value to be valid if null or empty.
* Returns a string if the valid is invalid, possible
* values are:
- *
+ *
*
* - data_element_or_type_null_or_empty
* - value_length_greater_than_max_length
@@ -250,13 +250,12 @@
* - value_not_integer
* - value_not_positive_integer
* - value_not_negative_integer
- * - value_is_zero_and_not_zero_significant
* - value_not_bool
* - value_not_true_only
* - value_not_valid_date
*
*
- * @param value the data value.
+ * @param value the data value.
* @param dataElement the data element.
* @return null if the value is valid, a string if not.
*/
@@ -325,18 +324,25 @@
if ( VALUE_TYPE_DATE.equals( type ) && !DateUtils.dateIsValid( value ) )
{
return "value_not_valid_date";
- }
-
- if ( VALUE_TYPE_INT.equals( dataElement.getType() ) && MathUtils.isZero( value ) &&
- !dataElement.isZeroIsSignificant() && !AGGREGATION_OPERATOR_AVERAGE.equals( dataElement.getAggregationOperator() ) )
- {
- return "value_is_zero_and_not_zero_significant";
- }
+ }
return null;
}
/**
+ * Indicates whether the given value is zero and not zero significant according
+ * to its data element.
+ *
+ * @param value the data value.
+ * @param dataElement the data element.
+ */
+ public static boolean dataValueIsZeroAndInsignificant( String value, DataElement dataElement )
+ {
+ return VALUE_TYPE_INT.equals( dataElement.getType() ) && MathUtils.isZero( value ) &&
+ !dataElement.isZeroIsSignificant() && !AGGREGATION_OPERATOR_AVERAGE.equals( dataElement.getAggregationOperator() );
+ }
+
+ /**
* Checks if the given comment is valid. Returns null if valid and a string
* if invalid, possible values are:
*
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java 2014-06-23 08:05:34 +0000
@@ -34,6 +34,7 @@
import static org.hisp.dhis.system.util.ValidationUtils.getLatitude;
import static org.hisp.dhis.system.util.ValidationUtils.getLongitude;
import static org.hisp.dhis.system.util.ValidationUtils.passwordIsValid;
+import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsZeroAndInsignificant;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -110,6 +111,20 @@
}
@Test
+ public void testDataValueIsZeroAndInsignificant()
+ {
+ DataElement de = new DataElement( "DEA" );
+ de.setType( DataElement.VALUE_TYPE_INT );
+ de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
+
+ assertTrue( dataValueIsZeroAndInsignificant( "0", de ) );
+
+ de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE );
+
+ assertFalse( dataValueIsZeroAndInsignificant( "0", de ) );
+ }
+
+ @Test
public void testDataValueIsValid()
{
DataElement de = new DataElement( "DEA" );
@@ -141,15 +156,6 @@
assertNull( dataValueIsValid( "-3", de ) );
assertNotNull( dataValueIsValid( "4", de ) );
- de.setNumberType( DataElement.VALUE_TYPE_INT );
- assertNotNull( dataValueIsValid( "0", de ) );
-
- de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE );
-
- assertNull( dataValueIsValid( "0", de ) );
-
- de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
-
de.setType( DataElement.VALUE_TYPE_TEXT );
assertNull( dataValueIsValid( "0", de ) );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2014-04-14 07:47:26 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2014-06-23 08:05:34 +0000
@@ -137,6 +137,8 @@
}
var warning = undefined;
+
+ var existing = !!( dhis2.de.currentExistingValue && dhis2.de.currentExistingValue != '' );
if ( value != '' )
{
@@ -170,9 +172,10 @@
{
return alertField( fieldId, i18n_value_must_zero_or_positive_integer + '\n\n' + dataElementName );
}
- if ( dhis2.validation.isValidZeroNumber( value ) )
+ if ( !existing && dhis2.validation.isValidZeroNumber( value ) )
{
// If value = 0 and zero not significant for data element, skip
+ // If existing value, let through and delete on server
if ( dhis2.de.significantZeros.indexOf( dataElementId ) == -1 )
{
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2014-06-10 20:46:05 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2014-06-23 08:05:34 +0000
@@ -58,6 +58,9 @@
// Current offset, next or previous corresponding to increasing or decreasing value
dhis2.de.currentPeriodOffset = 0;
+// Current existing data value, prior to entry or modification
+dhis2.de.currentExistingValue = null;
+
// Associative array with currently-displayed period choices, keyed by iso
dhis2.de.periodChoices = [];
@@ -1510,11 +1513,13 @@
function valueFocus( e )
{
var id = e.target.id;
+ var value = e.target.value;
var split = splitFieldId( id );
var dataElementId = split.dataElementId;
var optionComboId = split.optionComboId;
dhis2.de.currentOrganisationUnitId = split.organisationUnitId;
+ dhis2.de.currentExistingValue = value;
var dataElementName = getDataElementName( dataElementId );
var optionComboName = getOptionComboName( optionComboId );
=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm 2011-07-22 09:17:04 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm 1970-01-01 00:00:00 +0000
@@ -1,10 +0,0 @@
-#set( $size = $dataSets.size() )
-{ "dataSets": [
-#foreach( $dataSet in $dataSets )
- {
- "id": $!{dataSet.id},
- "name": "$!encoder.jsonEncode( ${dataSet.name} )"
- }#if( $velocityCount < $size ),#end
-#end ],
- "dataSetValid": ${dataSetValid}
-}
\ No newline at end of file
=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseLockStatus.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseLockStatus.vm 2012-02-16 12:07:10 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseLockStatus.vm 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-{"locked":$locked}
\ No newline at end of file
=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm 2011-07-18 10:22:08 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-#set( $size1 = $periods.size() )
-{ "periods": [
-#foreach( $period in $periods )
- {
- "name": "$!format.formatPeriod( ${period} )"
- }#if( $velocityCount < $size1 ),#end
-#end ],
- "periodValid": ${periodValid}
-}