← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3783: Fix bug: Error display dateentry form into Edit DataEntry Form ( Patient module ).

 

------------------------------------------------------------
revno: 3783
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-05-30 11:34:47 +0700
message:
  Fix bug: Error display dateentry form into Edit DataEntry Form ( Patient module ).
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml


--
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/ProgramDataEntryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java	2011-05-27 04:02:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java	2011-05-30 04:34:47 +0000
@@ -30,7 +30,6 @@
 import java.util.Collection;
 import java.util.regex.Pattern;
 
-import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
@@ -45,7 +44,9 @@
     final Pattern INPUT_PATTERN = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
     final Pattern SELECT_PATTERN = Pattern.compile( "(<select.*?)[/]?</select>", Pattern.DOTALL );
     final Pattern IDENTIFIER_PATTERN_TEXTBOX = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].value:value\\[([\\p{Digit}.]*)\\].value:value\\[([\\p{Digit}.]*)\\].value\"" );
-    final Pattern IDENTIFIER_PATTERN_OTHERS = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].\\S+:value\\[([\\p{Digit}.]*)\\].\\S+\"" );
+    final Pattern IDENTIFIER_PATTERN_BOOLEAN = Pattern.compile( "value\\[(.*)\\].boolean:value\\[(.*)\\].boolean" );
+    final Pattern IDENTIFIER_PATTERN_COMBO = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].combo:value\\[([\\p{Digit}.]*)\\].combo\"" );
+    final Pattern IDENTIFIER_PATTERN_DATE = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].date:value\\[([\\p{Digit}.]*)\\].date\"" );
 
     //--------------------------------------------------------------------------
     // ProgramDataEntryService
@@ -55,5 +56,5 @@
         I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance,
         OrganisationUnit organisationUnit );
     
-    String prepareDataEntryFormForEdit( String htmlCode, Collection<DataElement> dataElements );
+    String prepareDataEntryFormForEdit( String htmlCode );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2011-05-27 04:02:40 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2011-05-30 04:34:47 +0000
@@ -27,6 +27,7 @@
 
 package org.hisp.dhis.program;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -135,13 +136,15 @@
         return result;
     }
 
-    public String prepareDataEntryFormForEdit( String htmlCode , Collection<DataElement> dataElements )
+    public String prepareDataEntryFormForEdit( String htmlCode )
     {        
-        String result = populateCustomDataEntryForTextBox( htmlCode, dataElements );
-        
-        result = populateCustomDataEntryForCombo( htmlCode, dataElements );
-        
-        result = populateCustomDataEntryForDate( htmlCode, dataElements );
+        String result = populateCustomDataEntryForTextBox( htmlCode );
+        
+        result = populateCustomDataEntryForCombo( result );
+        
+        result = populateCustomDataEntryForBoolean( result );
+        
+        result = populateCustomDataEntryForDate( result );
         
         return result;
     }
@@ -150,7 +153,7 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private String populateCustomDataEntryForTextBox( String htmlCode , Collection<DataElement> dataElements )
+    private String populateCustomDataEntryForTextBox( String htmlCode )
     {
         // ---------------------------------------------------------------------
         // Metadata code to add to HTML before outputting
@@ -187,12 +190,14 @@
                 // Get data element ID of data element
                 // -------------------------------------------------------------
 
+                int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                ProgramStage programStage = programStageService.getProgramStage( programStageId );
+                Collection<DataElement> dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( programStage ) );
+
                 int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
+                DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
                 int optionComboId = Integer.parseInt( identifierMatcher.group( 3 ) );
-
-                DataElement dataElement = dataElementService.getDataElement( dataElementId );
-                
                 DataElementCategoryOptionCombo optionCombo = categoryService
                     .getDataElementCategoryOptionCombo( optionComboId );
 
@@ -208,64 +213,122 @@
             }
         }
 
-        return sb.toString();
-    }
-
-    private String populateCustomDataEntryForCombo( String htmlCode, Collection<DataElement> dataElements)
-    {
-        // ---------------------------------------------------------------------
-        // Metadata code to add to HTML before outputting
-        // ---------------------------------------------------------------------
-
-        StringBuffer sb = new StringBuffer();
-
-        // ---------------------------------------------------------------------
-        // Pattern to match data elements in the HTML code
-        // ---------------------------------------------------------------------
-
-        Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode );
-
-        // ---------------------------------------------------------------------
-        // Iterate through all matching data element fields
-        // ---------------------------------------------------------------------
-
-        while ( inputMatcher.find() )
-        {
-            String inputHTML = inputMatcher.group();
-            
-            // -----------------------------------------------------------------
-            // Get HTML input field code
-            // -----------------------------------------------------------------
-
-            String dataElementCode = inputMatcher.group( 1 );
-
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
-
-            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
-            {
-                // -------------------------------------------------------------
-                // Get data element ID of data element
-                // -------------------------------------------------------------
-
-                int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
-                
-                DataElement dataElement = dataElementService.getDataElement( dataElementId );
-                
-                if ( !dataElements.contains( dataElement ) )
-                {
-                    inputMatcher.appendReplacement( sb, DATA_ELEMENT_DOES_NOT_EXIST );
-                } 
-                else
-                {
-                    inputMatcher.appendReplacement( sb, inputHTML );
-                }
-            }
-        }
-        
-        return sb.toString();
-    }
-
-    private String populateCustomDataEntryForDate( String htmlCode, Collection<DataElement> dataElements )
+        return ( sb.toString().isEmpty() ) ? htmlCode : sb.toString();
+    }
+    
+    private String populateCustomDataEntryForBoolean( String htmlCode )
+    {
+        // ---------------------------------------------------------------------
+        // Metadata code to add to HTML before outputting
+        // ---------------------------------------------------------------------
+
+        StringBuffer sb = new StringBuffer();
+
+        // ---------------------------------------------------------------------
+        // Pattern to match data elements in the HTML code
+        // ---------------------------------------------------------------------
+
+        Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode );
+
+        // ---------------------------------------------------------------------
+        // Iterate through all matching data element fields
+        // ---------------------------------------------------------------------
+
+        while ( inputMatcher.find() )
+        {
+            String inputHTML = inputMatcher.group();
+            
+            // -----------------------------------------------------------------
+            // Get HTML input field code
+            // -----------------------------------------------------------------
+
+            String dataElementCode = inputMatcher.group( 1 );
+
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_BOOLEAN.matcher( dataElementCode );
+
+            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+            {
+                // -------------------------------------------------------------
+                // Get data element ID of data element
+                // -------------------------------------------------------------
+                int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                ProgramStage programStage = programStageService.getProgramStage( programStageId );
+                Collection<DataElement> dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( programStage ) );
+
+                int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
+                DataElement dataElement = dataElementService.getDataElement( dataElementId );
+                
+                if ( !dataElements.contains( dataElement ) )
+                {
+                    inputMatcher.appendReplacement( sb, DATA_ELEMENT_DOES_NOT_EXIST );
+                } 
+                else
+                {
+                    inputMatcher.appendReplacement( sb, inputHTML );
+                }
+            }
+        }
+        
+        return ( sb.toString().isEmpty() ) ? htmlCode : sb.toString();
+    }
+
+    private String populateCustomDataEntryForCombo( String htmlCode )
+    {
+        // ---------------------------------------------------------------------
+        // Metadata code to add to HTML before outputting
+        // ---------------------------------------------------------------------
+
+        StringBuffer sb = new StringBuffer();
+
+        // ---------------------------------------------------------------------
+        // Pattern to match data elements in the HTML code
+        // ---------------------------------------------------------------------
+
+        Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode );
+
+        // ---------------------------------------------------------------------
+        // Iterate through all matching data element fields
+        // ---------------------------------------------------------------------
+
+        while ( inputMatcher.find() )
+        {
+            String inputHTML = inputMatcher.group();
+            
+            // -----------------------------------------------------------------
+            // Get HTML input field code
+            // -----------------------------------------------------------------
+
+            String dataElementCode = inputMatcher.group( 1 );
+
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_COMBO.matcher( dataElementCode );
+
+            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+            {
+                // -------------------------------------------------------------
+                // Get data element ID of data element
+                // -------------------------------------------------------------
+                int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                ProgramStage programStage = programStageService.getProgramStage( programStageId );
+                Collection<DataElement> dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( programStage ) );
+
+                int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
+                DataElement dataElement = dataElementService.getDataElement( dataElementId );
+                
+                if ( !dataElements.contains( dataElement ) )
+                {
+                    inputMatcher.appendReplacement( sb, DATA_ELEMENT_DOES_NOT_EXIST );
+                } 
+                else
+                {
+                    inputMatcher.appendReplacement( sb, inputHTML );
+                }
+            }
+        }
+        
+        return ( sb.toString().isEmpty() ) ? htmlCode : sb.toString();
+    }
+
+    private String populateCustomDataEntryForDate( String htmlCode )
     {
         // ---------------------------------------------------------------------
         // Metadata code to add to HTML before outputting
@@ -293,18 +356,21 @@
 
             String dataElementCode = inputMatcher.group( 1 );
 
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_DATE.matcher( dataElementCode );
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
                 // -------------------------------------------------------------
                 // Get data element ID of data element
                 // -------------------------------------------------------------
+               
+                int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                ProgramStage programStage = programStageService.getProgramStage( programStageId );
+                Collection<DataElement> dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( programStage ) );
 
                 int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
-                
                 DataElement dataElement = dataElementService.getDataElement( dataElementId );
-                
+
                 if ( !dataElements.contains( dataElement ) )
                 {
                     inputMatcher.appendReplacement( sb, DATA_ELEMENT_DOES_NOT_EXIST );
@@ -315,7 +381,7 @@
             }
         }
         
-        return sb.toString();
+        return ( sb.toString().isEmpty() ) ? htmlCode : sb.toString();
     }
 
     private String populateCustomDataEntryForTextBox( String dataEntryFormCode,
@@ -572,7 +638,7 @@
 
             String compulsory = "null";
             String dataElementCode = dataElementMatcher.group( 1 );
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_BOOLEAN.matcher( dataElementCode );
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
                 // -------------------------------------------------------------
@@ -815,7 +881,7 @@
 
             String dataElementCode = dataElementMatcher.group( 1 );
 
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_COMBO.matcher( dataElementCode );
 
             String compulsory = "null";
 
@@ -1050,7 +1116,7 @@
             String compulsory = "null";
             String dataElementCode = dataElementMatcher.group( 1 );
 
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_DATE.matcher( dataElementCode );
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java	2011-05-27 04:02:40 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewDataEntryFormAction.java	2011-05-30 04:34:47 +0000
@@ -31,13 +31,10 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.comparator.DataElementNameComparator;
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.dataentryform.DataEntryFormService;
 import org.hisp.dhis.program.ProgramDataEntryService;
 import org.hisp.dhis.program.ProgramStage;
-import org.hisp.dhis.program.ProgramStageDataElementService;
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.program.comparator.ProgramStageNameComparator;
 
@@ -77,13 +74,6 @@
         this.programStageService = programStageService;
     }
 
-    private ProgramStageDataElementService programStageDataElementService;
-
-    public void setProgramStageDataElementService( ProgramStageDataElementService programStageDataElementService )
-    {
-        this.programStageDataElementService = programStageDataElementService;
-    }
-
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
@@ -116,13 +106,6 @@
         return existingDataEntryForms;
     }
 
-    public List<DataElement> dataElements;
-
-    public List<DataElement> getDataElements()
-    {
-        return dataElements;
-    }
-
     private List<ProgramStage> programStages;
 
     public List<ProgramStage> getProgramStages()
@@ -147,14 +130,6 @@
         programStage = programStageService.getProgramStage( programStageId );
 
         // ---------------------------------------------------------------------
-        // Get data-elements into selected program-stage
-        // ---------------------------------------------------------------------
-
-        dataElements = new ArrayList<DataElement>( programStageDataElementService.getListDataElement( programStage ) );
-
-        Collections.sort( dataElements, new DataElementNameComparator() );
-
-        // ---------------------------------------------------------------------
         // Get dataEntryForm of selected program-stage
         // ---------------------------------------------------------------------
 
@@ -162,7 +137,7 @@
 
         if ( dataEntryForm != null )
         {
-            dataEntryValue = programDataEntryService.prepareDataEntryFormForEdit( dataEntryForm.getHtmlCode(), dataElements );
+            dataEntryValue = programDataEntryService.prepareDataEntryFormForEdit( dataEntryForm.getHtmlCode() );
         }
         else
         {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2011-05-27 04:02:40 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2011-05-30 04:34:47 +0000
@@ -809,8 +809,6 @@
 		<property name="programStageService">
 			<ref bean="org.hisp.dhis.program.ProgramStageService" />
 		</property>
-		<property name="programStageDataElementService"
-			ref="org.hisp.dhis.program.ProgramStageDataElementService" />
 		<property name="programDataEntryService"
 			ref="org.hisp.dhis.program.ProgramDataEntryService" />
 	</bean>