← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13822: Impl new option for data set for requiring comments for missing or false values in the form when ...

 

------------------------------------------------------------
revno: 13822
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-23 13:54:46 +0200
message:
  Impl new option for data set for requiring comments for missing or false values in the form when clicking complete. Useful e.g. when doing facility surveys where all info must be filled except when a valid reason is given.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editDataSet.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/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2014-01-19 05:14:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2014-01-23 11:54:46 +0000
@@ -205,6 +205,12 @@
      * can be completed.
      */
     private boolean validCompleteOnly;
+    
+    /**
+     * Property indicating whether a comment is required for all fields in a form
+     * which are not entered, including false for boolean values.
+     */
+    private boolean noValueRequiresComment;
 
     /**
      * Property indicating whether offline storage is enabled for this dataSet
@@ -768,6 +774,19 @@
     @JsonProperty
     @JsonView({ DetailedView.class, ExportView.class, WithoutOrganisationUnitsView.class })
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public boolean isNoValueRequiresComment()
+    {
+        return noValueRequiresComment;
+    }
+
+    public void setNoValueRequiresComment( boolean noValueRequiresComment )
+    {
+        this.noValueRequiresComment = noValueRequiresComment;
+    }
+
+    @JsonProperty
+    @JsonView({ DetailedView.class, ExportView.class, WithoutOrganisationUnitsView.class })
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isSkipOffline()
     {
         return skipOffline;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-01-21 07:07:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-01-23 11:54:46 +0000
@@ -519,6 +519,7 @@
         executeSql( "UPDATE dataset SET skipoffline = false WHERE skipoffline IS NULL" );
         executeSql( "UPDATE dataset SET renderastabs = false WHERE renderastabs IS NULL" );
         executeSql( "UPDATE dataset SET renderhorizontally = false WHERE renderhorizontally IS NULL" );
+        executeSql( "UPDATE dataset SET novaluerequirescomment = false WHERE novaluerequirescomment IS NULL" );
 
         executeSql( "UPDATE categorycombo SET skiptotal = false WHERE skiptotal IS NULL" );
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml	2014-01-19 05:14:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml	2014-01-23 11:54:46 +0000
@@ -94,6 +94,8 @@
     <property name="fieldCombinationRequired" />
 
     <property name="validCompleteOnly" />
+    
+    <property name="noValueRequiresComment" />
 
     <property name="skipOffline" />
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java	2013-12-21 19:02:27 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java	2014-01-23 11:54:46 +0000
@@ -29,7 +29,6 @@
  */
 
 import java.util.Collection;
-import java.util.List;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -190,13 +189,6 @@
         return dataValue;
     }
 
-    private List<String> standardComments;
-
-    public List<String> getStandardComments()
-    {
-        return standardComments;
-    }
-
     private Collection<DataValueAudit> dataValueAudits;
 
     public Collection<DataValueAudit> getDataValueAudits()

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java	2014-01-23 09:31:23 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java	2014-01-23 11:54:46 +0000
@@ -28,13 +28,26 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.Action;
+import static org.hisp.dhis.system.util.ListUtils.getCollection;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.dataanalysis.DataAnalysisService;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.datavalue.DeflatedDataValue;
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -46,14 +59,7 @@
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleService;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import static org.hisp.dhis.system.util.ListUtils.getCollection;
+import com.opensymphony.xwork2.Action;
 
 /**
  * @author Margrethe Store
@@ -109,6 +115,13 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    private DataValueService dataValueService;
+
+    public void setDataValueService( DataValueService dataValueService )
+    {
+        this.dataValueService = dataValueService;
+    }
 
     // -------------------------------------------------------------------------
     // Input
@@ -137,6 +150,11 @@
 
     private boolean multiOu;
 
+    public boolean isMultiOu()
+    {
+        return multiOu;
+    }
+
     public void setMultiOu( boolean multiOu )
     {
         this.multiOu = multiOu;
@@ -173,6 +191,13 @@
     {
         return dataValues;
     }
+    
+    private Map<OrganisationUnit, List<DataElementOperand>> commentViolations = new TreeMap<OrganisationUnit, List<DataElementOperand>>();
+
+    public Map<OrganisationUnit, List<DataElementOperand>> getCommentViolations()
+    {
+        return commentViolations;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -223,9 +248,16 @@
             {
                 validationResults.put( organisationUnit, results );
             }
+            
+            List<DataElementOperand> violations = noValueRequiresCommentAnalysis( organisationUnit, dataSet, period );
+            
+            if ( !violations.isEmpty() )
+            {
+                commentViolations.put( organisationUnit, violations );
+            }
         }
 
-        return dataValues.size() == 0 && validationResults.size() == 0 ? SUCCESS : INPUT;
+        return dataValues.isEmpty() && validationResults.isEmpty() & commentViolations.isEmpty() ? SUCCESS : INPUT;
     }
 
     // -------------------------------------------------------------------------
@@ -274,4 +306,35 @@
 
         return validationResults;
     }
+
+    // -------------------------------------------------------------------------
+    // No value requires comment analysis
+    // -------------------------------------------------------------------------
+    
+    private List<DataElementOperand> noValueRequiresCommentAnalysis( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        List<DataElementOperand> violations = new ArrayList<DataElementOperand>();
+     
+        if ( !dataSet.isNoValueRequiresComment() )
+        {
+            return violations;
+        }
+        
+        for ( DataElement de : dataSet.getDataElements() )
+        {
+            for ( DataElementCategoryOptionCombo co : de.getCategoryCombo().getOptionCombos() )
+            {
+                DataValue dv = dataValueService.getDataValue( de, period, organisationUnit, co );
+                
+                if ( dv == null || DataValue.FALSE.equals( dv.getValue() ) )
+                {
+                    violations.add( new DataElementOperand( de, co ) );
+                }
+            }
+        }
+        
+        log.info( "Number of missing comments: " + violations.size() );
+        
+        return violations;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2014-01-23 09:31:23 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2014-01-23 11:54:46 +0000
@@ -67,6 +67,7 @@
     <property name="minMaxOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.MinMaxOutlierAnalysisService" />
     <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+    <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
   </bean>
 
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties	2013-12-25 15:01:48 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties	2014-01-23 11:54:46 +0000
@@ -13,6 +13,7 @@
 data_set=Data Set
 select=Select
 period=Period
+form_field=Form field
 filter_on_section=Filter on section
 filter_in_section=Filter in section
 show_all_sections=Show all sections
@@ -38,9 +39,10 @@
 validation_result=Validation Result
 expression=Expression
 successful_validation=The data entry screen successfully passed validation
-data_entry_screen_has_following_errors=The data entry screen has the following validation errors, please correct these before proceeding
+data_entry_screen_has_following_errors=The data entry screen has the following validation errors, please correct
+the_following_values_are_outliers=The following values are considered as outliers (min-max or std dev), please correct
+the_following_fields_require_comment=The following input fields require a comment, please enter
 the_following_values_violate_rules=The following values violate validation rules
-the_following_values_are_outliers=The following values are considered as outliers (min-max or std dev)
 value=Value
 operator=Operator
 no_organisationunit_selected=No Organisation Unit Selected
@@ -54,7 +56,6 @@
 data_entry=Data Entry
 followup=Follow-up
 validation_rule=Validation rule
-the_following_values_are_outliers=The following values are considered as outliers (min-max or std dev).
 register_complete_dataset_success=Registered complete dataset
 register_complete_dataset_failed=Register complete dataset failed
 undo_register_complete_dataset_success=Undo register complete dataset success

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm	2013-03-15 04:53:19 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm	2014-01-23 11:54:46 +0000
@@ -1,13 +1,13 @@
 <h3>$i18n.getString( "validation_result" ) &nbsp;<img src="../images/warning_small.png"></h3>
 
-<p class="bold">$i18n.getString( "data_entry_screen_has_following_errors" )</p>
-
 #if( !$validationResults.isEmpty() )
     #foreach( $key in $validationResults.keySet() )
     #set( $results = $validationResults.get($key))
 
-    <h3>$key.displayName</h3>
+    #if( $multiOu )<h3>$key.displayName</h3>#end
 
+    <p class="bold">$i18n.getString( "data_entry_screen_has_following_errors" )</p>
+    
     <table class="listTable" width="100%">
         <tr>
             <th>$i18n.getString( "validation_rule" )</th>                
@@ -42,9 +42,10 @@
     #foreach( $key in $dataValues.keySet() )
     #set( $results = $dataValues.get( $key ))
 
-    <h3>$key.displayName</h3>
+    #if( $multiOu )<h3>$key.displayName</h3>#end
 
     <p class="bold">$encoder.htmlEncode( $i18n.getString( "the_following_values_are_outliers" ) )</p>
+    
     <table class="listTable" style="width:100%">
 	    <tr>
 	        <th>$i18n.getString( "data_element" )</th>
@@ -55,7 +56,7 @@
 	    #set( $mark = false )	    
 	    #foreach( $value in $results )
 	    <tr>	    
-	        <td style="height:32px"#alternate( $mark )>$value.dataElementName $value.categoryOptionComboNameParsed</td>	        
+	        <td style="height:32px"#alternate( $mark )>$encoder.htmlEncode( $value.dataElementName ) $encoder.htmlEncode( $value.categoryOptionComboNameParsed )</td>	        
 	        <td style="text-align:center"#alternate( $mark )>$value.min</td>	        
 	        <td style="text-align:center;width:100px"#alternate( $mark )>$value.value</td>	        
 	        <td style="text-align:center"#alternate( $mark )>$value.max</td>
@@ -69,3 +70,30 @@
 	</table>
     #end
 #end
+
+#if ( !$commentViolations.isEmpty() )
+	#foreach( $key in $commentViolations.keySet() )
+	#set( $operands = $commentViolations.get( $key ))
+			
+    #if( $multiOu )<h3>$key.displayName</h3>#end
+    
+    <p class="bold">$encoder.htmlEncode( $i18n.getString( "the_following_fields_require_comment" ) )</p>
+			
+    <table class="listTable" style="width:100%">
+        <tr>
+            <th>$i18n.getString( "form_field" )</th>        	
+        </tr>
+        #set( $mark = false )
+        #foreach( $operand in $operands )
+        <tr>
+        	<td style="height:32px"#alternate( $mark )>$encoder.htmlEncode( $operand.prettyName )</td>
+        </tr>
+        #if( $mark )
+            #set( $mark = false )
+        #else
+            #set( $mark = true )
+        #end
+        #end
+    </table>
+	#end
+#end

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java	2014-01-19 05:53:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/AddDataSetAction.java	2014-01-23 11:54:46 +0000
@@ -219,6 +219,13 @@
     {
         this.validCompleteOnly = validCompleteOnly;
     }
+    
+    private boolean noValueRequiresComment;
+    
+    public void setNoValueRequiresComment( boolean noValueRequiresComment )
+    {
+        this.noValueRequiresComment = noValueRequiresComment;
+    }
 
     private boolean skipOffline;
 
@@ -333,6 +340,7 @@
         dataSet.setAllowFuturePeriods( allowFuturePeriods );
         dataSet.setFieldCombinationRequired( fieldCombinationRequired );
         dataSet.setValidCompleteOnly( validCompleteOnly );
+        dataSet.setNoValueRequiresComment( noValueRequiresComment );
         dataSet.setNotifyCompletingUser( notifyCompletingUser );
         dataSet.setApproveData( approveData );
         dataSet.setSkipOffline( skipOffline );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java	2014-01-19 05:53:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java	2014-01-23 11:54:46 +0000
@@ -237,6 +237,13 @@
         this.validCompleteOnly = validCompleteOnly;
     }
 
+    private boolean noValueRequiresComment;
+    
+    public void setNoValueRequiresComment( boolean noValueRequiresComment )
+    {
+        this.noValueRequiresComment = noValueRequiresComment;
+    }
+
     private boolean skipOffline;
 
     public void setSkipOffline( boolean skipOffline )
@@ -358,6 +365,7 @@
         dataSet.setAllowFuturePeriods( allowFuturePeriods );
         dataSet.setFieldCombinationRequired( fieldCombinationRequired );
         dataSet.setValidCompleteOnly( validCompleteOnly );
+        dataSet.setNoValueRequiresComment( noValueRequiresComment );
         dataSet.setNotifyCompletingUser( notifyCompletingUser );
         dataSet.setApproveData( approveData );
         dataSet.setSkipOffline( skipOffline );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2013-12-22 21:08:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2014-01-23 11:54:46 +0000
@@ -100,6 +100,7 @@
 form_details=Form details
 complete_allowed_only_if_validation_passes=Complete allowed only if validation passes
 notification_recipients=Complete notification recipients
+no_value_requires_comment=Missing value requires comment on complete
 skip_offline=Skip offline
 render_as_tabs=Render sections as tabs
 render_horizontally=Render Vertically

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm	2014-01-19 05:53:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/addDataSet.vm	2014-01-23 11:54:46 +0000
@@ -196,6 +196,15 @@
           </select>
         </td>
       </tr>
+      <tr>
+        <td><label>$i18n.getString( "no_value_requires_comment" )</label></td>
+        <td>
+          <select id="noValueRequiresComment" name="noValueRequiresComment">
+            <option value="false">$i18n.getString( "no" )</option>
+            <option value="true">$i18n.getString( "yes" )</option>
+          </select>
+        </td>
+      </tr>
       </tr>
       <tr>
         <td>$i18n.getString( 'legend_set' )</td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editDataSet.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editDataSet.vm	2014-01-19 05:53:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editDataSet.vm	2014-01-23 11:54:46 +0000
@@ -201,6 +201,15 @@
         </td>
       </tr>
       <tr>
+        <td><label for="validCompleteOnly">$i18n.getString( "no_value_requires_comment" )</label></td>
+        <td>
+          <select id="noValueRequiresComment" name="noValueRequiresComment">
+            <option value="false">$i18n.getString( "no" )</option>
+            <option value="true"#if( $dataSet.noValueRequiresComment == true ) selected="selected"#end>$i18n.getString( "yes" )</option>
+          </select>
+        </td>
+      </tr>
+      <tr>
         <td>$i18n.getString( 'legend_set' )</td>
         <td>
           <select id="selectedLegendSetId" name="selectedLegendSetId">