← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5818: Impl integrity check for data elements which are members of a data set but not in the form or any...

 

------------------------------------------------------------
revno: 5818
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-01-28 18:42:13 +0100
message:
  Impl integrity check for data elements which are members of a data set but not in the form or any sections
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataIntegrityForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.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/dataentryform/DataEntryFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2012-01-18 06:11:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2012-01-28 17:42:13 +0000
@@ -29,8 +29,10 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 import java.util.regex.Pattern;
 
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.i18n.I18n;
 
@@ -139,6 +141,8 @@
      */
     String prepareDataEntryFormForEntry( String htmlCode, I18n i18n, DataSet dataSet );
     
+    Set<DataElement> getDataElementsInDataEntryForm( DataEntryForm form );
+    
     Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds );
     
     Collection<DataEntryForm> listDisctinctDataEntryFormByDataSetIds( List<Integer> dataSetIds );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java	2012-01-28 17:42:13 +0000
@@ -78,6 +78,12 @@
      */
     SortedMap<DataElement, Collection<DataSet>> getDataElementsAssignedToDataSetsWithDifferentPeriodTypes();
 
+    /**
+     * Returns all data elements which are member of a data set but not part of
+     * either the custom form or sections of the data set.
+     */
+    SortedMap<DataSet, Collection<DataElement>> getDataElementsInDataSetNotInForm();
+    
     // -------------------------------------------------------------------------
     // Section
     // -------------------------------------------------------------------------

=== 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	2011-12-09 20:53:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-01-28 17:42:13 +0000
@@ -236,6 +236,18 @@
 
         return TYPE_DEFAULT;
     }
+    
+    public Set<DataElement> getDataElementsInSections()
+    {
+        Set<DataElement> dataElements = new HashSet<DataElement>();
+        
+        for ( Section section : sections )
+        {
+            dataElements.addAll( section.getDataElements() );
+        }
+        
+        return dataElements;
+    }
 
     public DataSet increaseVersion()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java	2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java	2012-01-28 17:42:13 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.dataset.Section;
@@ -136,6 +137,13 @@
     {
         this.expressionService = expressionService;
     }
+    
+    private DataEntryFormService dataEntryFormService;
+
+    public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
+    {
+        this.dataEntryFormService = dataEntryFormService;
+    }
 
     // -------------------------------------------------------------------------
     // DataIntegrityService implementation
@@ -186,7 +194,6 @@
         return targets;
     }
 
-    @Override
     public SortedMap<DataElement, Collection<DataElementGroup>> getDataElementsViolatingExclusiveGroupSets()
     {
         Collection<DataElementGroupSet> groupSets = dataElementService.getAllDataElementGroupSets();
@@ -212,6 +219,41 @@
 
         return targets;
     }
+    
+    public SortedMap<DataSet, Collection<DataElement>> getDataElementsInDataSetNotInForm()
+    {
+        SortedMap<DataSet, Collection<DataElement>> map = new TreeMap<DataSet, Collection<DataElement>>( IdentifiableObjectNameComparator.INSTANCE );
+        
+        Collection<DataSet> dataSets = dataSetService.getAllDataSets();
+        
+        for ( DataSet dataSet : dataSets )
+        {
+            if ( !DataSet.TYPE_DEFAULT.equals( dataSet.getDataSetType() ) )
+            {
+                Set<DataElement> formElements = new HashSet<DataElement>();
+                
+                if ( dataSet.hasDataEntryForm() )
+                {
+                    formElements.addAll( dataEntryFormService.getDataElementsInDataEntryForm( dataSet.getDataEntryForm() ) );
+                }
+                else if ( dataSet.hasSections() )
+                {
+                    formElements.addAll( dataSet.getDataElementsInSections() );
+                }
+                
+                Set<DataElement> dataSetElements = new HashSet<DataElement>( dataSet.getDataElements() );
+                
+                dataSetElements.removeAll( formElements );
+                
+                if ( dataSetElements.size() > 0 )
+                {
+                    map.put( dataSet, dataSetElements );
+                }
+            }
+        }
+        
+        return map;
+    }
 
     // -------------------------------------------------------------------------
     // DataSet

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2012-01-05 20:39:23 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2012-01-28 17:42:13 +0000
@@ -43,6 +43,7 @@
     <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
     <property name="validationRuleService" ref="org.hisp.dhis.validation.ValidationRuleService" />
     <property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
+	<property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
   </bean>
   
   <!-- Maintenance -->

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-01-18 06:11:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-01-28 17:42:13 +0000
@@ -31,8 +31,10 @@
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Matcher;
 
 import org.hisp.dhis.dataelement.DataElement;
@@ -317,6 +319,41 @@
         return sb.toString();
     }
 
+    public Set<DataElement> getDataElementsInDataEntryForm( DataEntryForm form )
+    {
+        Set<DataElement> dataElements = new HashSet<DataElement>();
+        
+        Matcher inputMatcher = INPUT_PATTERN.matcher( form.getHtmlCode() );
+        
+        while ( inputMatcher.find() )
+        {
+            String inputHtml = inputMatcher.group();
+            
+            Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
+            Matcher dataElementTotalMatcher = DATAELEMENT_TOTAL_PATTERN.matcher( inputHtml );
+            
+            DataElement dataElement = null;
+            
+            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+            {
+                int dataElementId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                dataElement = dataElementService.getDataElement( dataElementId );
+            }
+            else if ( dataElementTotalMatcher.find() && dataElementTotalMatcher.groupCount() > 0 )
+            {
+                int dataElementId = Integer.parseInt( dataElementTotalMatcher.group( 1 ) );
+                dataElement = dataElementService.getDataElement( dataElementId );
+            }
+            
+            if ( dataElement != null )
+            {
+                dataElements.add( dataElement );
+            }
+        }
+        
+        return dataElements;
+    }
+    
     public Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds )
     {
         if ( programStageIds == null || programStageIds.isEmpty() )

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java	2012-01-28 17:42:13 +0000
@@ -60,17 +60,15 @@
     }
 
     @Override
-    public String allowDeleteIndicator( Indicator indicator )
+    public void deleteIndicator( Indicator indicator )
     {
         for ( Chart chart : chartService.getAllCharts() )
         {
-            if ( chart.getIndicators().contains( indicator ) )
+            if ( chart.getIndicators().remove( indicator ) )
             {
-                return chart.getName();
+                chartService.saveChart( chart );
             }
         }
-
-        return null;
     }
 
     @Override

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java	2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java	2012-01-28 17:42:13 +0000
@@ -88,12 +88,26 @@
         return dataElementsWithoutGroups;
     }
 
+    private Map<DataElement, Collection<DataSet>> dataElementsAssignedToDataSetsWithDifferentPeriodTypes;
+
+    public Map<DataElement, Collection<DataSet>> getDataElementsAssignedToDataSetsWithDifferentPeriodTypes()
+    {
+        return dataElementsAssignedToDataSetsWithDifferentPeriodTypes;
+    }
+
     private SortedMap<DataElement, Collection<DataElementGroup>> dataElementsViolatingExclusiveGroupSets;
 
     public SortedMap<DataElement, Collection<DataElementGroup>> getDataElementsViolatingExclusiveGroupSets()
     {
         return dataElementsViolatingExclusiveGroupSets;
     }
+    
+    private SortedMap<DataSet, Collection<DataElement>> dataElementsInDataSetNotInForm;
+
+    public SortedMap<DataSet, Collection<DataElement>> getDataElementsInDataSetNotInForm()
+    {
+        return dataElementsInDataSetNotInForm;
+    }
 
     private List<DataSet> dataSetsNotAssignedToOrganisationUnits;
 
@@ -109,13 +123,6 @@
         return sectionsWithInvalidCategoryCombinations;
     }
 
-    private Map<DataElement, Collection<DataSet>> dataElementsAssignedToDataSetsWithDifferentPeriodTypes;
-
-    public Map<DataElement, Collection<DataSet>> getDataElementsAssignedToDataSetsWithDifferentPeriodTypes()
-    {
-        return dataElementsAssignedToDataSetsWithDifferentPeriodTypes;
-    }
-
     private Collection<Collection<Indicator>> indicatorsWithIdenticalFormulas;
 
     public Collection<Collection<Indicator>> getIndicatorsWithIdenticalFormulas()
@@ -224,6 +231,7 @@
         dataElementsWithoutGroups = new ArrayList<DataElement>( dataIntegrityService.getDataElementsWithoutGroups() );
         dataElementsAssignedToDataSetsWithDifferentPeriodTypes = dataIntegrityService.getDataElementsAssignedToDataSetsWithDifferentPeriodTypes();
         dataElementsViolatingExclusiveGroupSets = dataIntegrityService.getDataElementsViolatingExclusiveGroupSets();
+        dataElementsInDataSetNotInForm = dataIntegrityService.getDataElementsInDataSetNotInForm();
 
         log.info( "Checked data elements" );
         

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2012-01-06 12:18:29 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2012-01-28 17:42:13 +0000
@@ -380,3 +380,4 @@
 execute_now=Execute now
 execute_tasks_confirmation=Are you sure you want to execute all tasks now? Task processing might fully utilize your system resources and slow down other operations.
 no_aggregation=No aggregation
+data_elements_in_data_set_not_in_form = Data elements in data set but not in form or sections
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataIntegrityForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataIntegrityForm.vm	2011-03-13 05:02:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataIntegrityForm.vm	2012-01-28 17:42:13 +0000
@@ -15,6 +15,7 @@
 #integrityItem( $i18n.getString( "data_elements_without_data_set" ) "dataElementsWithoutDataSet" )
 #integrityItem( $i18n.getString( "data_elements_without_groups" ) "dataElementsWithoutGroups" )
 #integrityItem( $i18n.getString( "data_elements_violating_exclusive_group_sets" ) "dataElementsViolatingExclusiveGroupSets" )
+#integrityItem( $i18n.getString( "data_elements_in_data_set_not_in_form" ) "dataElementsInDataSetNotInForm" )
 #integrityItem( $i18n.getString( "data_elements_assigned_to_period_types_with_different_period_types" ) "dataElementsAssignedToDataSetsWithDifferentPeriodTypes" )
 #integrityItem( $i18n.getString( "data_sets_not_assigned_to_organisation_units" ) "dataSetsNotAssignedToOrganisationUnits" )
 #integrityItem( $i18n.getString( "sections_with_invalid_category_combinations" ) "sectionsWithInvalidCategoryCombinations" )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js	2011-08-19 21:33:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js	2012-01-28 17:42:13 +0000
@@ -14,6 +14,7 @@
     displayViolationList( json.dataElementsWithoutGroups, "dataElementsWithoutGroups" );
 	displayViolationList( json.dataElementsViolatingCompulsoryGroupSets, "dataElementsViolatingCompulsoryGroupSets" );
 	displayViolationList( json.dataElementsViolatingExclusiveGroupSets, "dataElementsViolatingExclusiveGroupSets" );
+	displayViolationList( json.dataElementsInDataSetNotInForm, "dataElementsInDataSetNotInForm" );
     displayViolationList( json.dataElementsAssignedToDataSetsWithDifferentPeriodTypes, "dataElementsAssignedToDataSetsWithDifferentPeriodTypes" );
     displayViolationList( json.dataSetsNotAssignedToOrganisationUnits, "dataSetsNotAssignedToOrganisationUnits" );
     displayViolationList( json.sectionsWithInvalidCategoryCombinations, "sectionsWithInvalidCategoryCombinations" );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm	2011-03-13 15:59:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm	2012-01-28 17:42:13 +0000
@@ -2,7 +2,7 @@
 #set( $size = $list.size() )
 "$!encoder.jsEncode( ${name} )": [
 #foreach( $o in $list )
-"$!encoder.jsonEncode( ${o.name} )"#if( $velocityCount < $size ),#end
+"$!encoder.jsonEncode( ${o.displayName} )"#if( $velocityCount < $size ),#end
 #end
 ]
 #end
@@ -12,7 +12,7 @@
 "$!encoder.jsonEncode( ${name} )": [
 #foreach( $o in $list )
 #set( $oSize = $o.size() )
-"#foreach( $p in $o ) $!encoder.jsonEncode( ${p.name} ) #if( $velocityCount < $oSize ), #end
+"#foreach( $p in $o ) $!encoder.jsonEncode( ${p.displayName} ) #if( $velocityCount < $oSize ), #end
 #end "#if( $velocityCount < $listSize ),#end
 #end
 ]
@@ -22,7 +22,7 @@
 #set( $size = $map.keySet().size() )
 "$!encoder.jsonEncode( ${name} )": [
 #foreach( $o in $map.keySet() )
-"$!encoder.jsonEncode( ${o.name} ): $map.get( $o )"#if( $velocityCount < $size ),#end
+"$!encoder.jsonEncode( ${o.displayName} ): $map.get( $o )"#if( $velocityCount < $size ),#end
 #end
 ]
 #end
@@ -32,17 +32,18 @@
 "$!encoder.jsonEncode( ${name} )": [
 #foreach( $o in $map.keySet() )
 #set( $listSize = $map.get( $o ).size() )
-"$!encoder.jsonEncode( ${o.name} ):#foreach( $p in $map.get( $o ) ) $!encoder.jsonEncode( ${p.name} )#if( $velocityCount < $listSize ), #end
+"$!encoder.jsonEncode( ${o.displayName} ):#foreach( $p in $map.get( $o ) ) $!encoder.jsonEncode( ${p.displayName} )#if( $velocityCount < $listSize ), #end
 #end "#if( $velocityCount < $mapSize ),#end
 #end
 ]
 #end
 {
     #violation( "dataElementsWithoutDataSet" $dataElementsWithoutDataSet ),
-    #violation( "dataElementsWithoutGroups" $dataElementsWithoutGroups ),    
-    #violation( "dataElementsViolatingCompulsoryGroupSets" $dataElementsViolatingCompulsoryGroupSets ),    
-    #violationWithMapList( "dataElementsViolatingExclusiveGroupSets" $dataElementsViolatingExclusiveGroupSets ),    
-    #violationWithMapList( "dataElementsAssignedToDataSetsWithDifferentPeriodTypes" $dataElementsAssignedToDataSetsWithDifferentPeriodTypes ),    
+    #violation( "dataElementsWithoutGroups" $dataElementsWithoutGroups ),
+    #violation( "dataElementsViolatingCompulsoryGroupSets" $dataElementsViolatingCompulsoryGroupSets ),
+    #violationWithMapList( "dataElementsViolatingExclusiveGroupSets" $dataElementsViolatingExclusiveGroupSets ),
+    #violationWithMapList( "dataElementsInDataSetNotInForm" $dataElementsInDataSetNotInForm ),
+    #violationWithMapList( "dataElementsAssignedToDataSetsWithDifferentPeriodTypes" $dataElementsAssignedToDataSetsWithDifferentPeriodTypes ),
     #violation( "dataSetsNotAssignedToOrganisationUnits" $dataSetsNotAssignedToOrganisationUnits ),
     #violation( "sectionsWithInvalidCategoryCombinations" $sectionsWithInvalidCategoryCombinations ),
     #violationWithCollection( "indicatorsWithIdenticalFormulas" $indicatorsWithIdenticalFormulas ),