← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12270: Add script to modify database schema for Default registration form function.

 

------------------------------------------------------------
revno: 12270
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-27 14:43:07 +0700
message:
  Add script to modify database schema for Default registration form function.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationFormService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientProperty.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java


--
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/patient/PatientRegistrationFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationFormService.java	2013-09-03 06:39:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationFormService.java	2013-09-27 07:43:07 +0000
@@ -59,10 +59,6 @@
 
     final Pattern TITLE_TAG_PATTERN = Pattern.compile( "title=\"(.*?)\"", Pattern.DOTALL );
 
-    final Pattern SUGGESTED_VALUE_PATTERN = Pattern.compile( "suggested=('|\")(\\w*)('|\")" );
-    
-    final Pattern CLASS_PATTERN = Pattern.compile( "class='(\\w*)'" );
-
     // --------------------------------------------------------------------------
     // ProgramDataEntryService
     // --------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientProperty.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientProperty.java	2013-09-27 04:43:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramPatientProperty.java	2013-09-27 07:43:07 +0000
@@ -54,7 +54,7 @@
 
     private String defaultValue;
 
-    private boolean hidden;
+    private boolean hidden = false;
 
     private int sortOrder;
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java	2013-09-06 09:34:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java	2013-09-27 07:43:07 +0000
@@ -39,6 +39,8 @@
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramPatientProperty;
+import org.hisp.dhis.program.ProgramPatientPropertyService;
 import org.hisp.dhis.user.User;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -98,6 +100,13 @@
         this.attributeValueService = attributeValueService;
     }
 
+    private ProgramPatientPropertyService programPatientPropertyService;
+
+    public void setProgramPatientPropertyService( ProgramPatientPropertyService programPatientPropertyService )
+    {
+        this.programPatientPropertyService = programPatientPropertyService;
+    }
+
     // -------------------------------------------------------------------------
     // PatientRegistrationForm implementation
     // -------------------------------------------------------------------------
@@ -165,8 +174,6 @@
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
             Matcher dynamicAttrMatcher = DYNAMIC_ATTRIBUTE_PATTERN.matcher( inputHtml );
             Matcher programMatcher = PROGRAM_PATTERN.matcher( inputHtml );
-            Matcher suggestedMarcher = SUGGESTED_VALUE_PATTERN.matcher( inputHtml );
-            Matcher classMarcher = CLASS_PATTERN.matcher( inputHtml );
 
             index++;
 
@@ -177,6 +184,14 @@
                 // Get value
                 String value = "";
                 String hidden = "";
+               
+                ProgramPatientProperty programPatientProperty = programPatientPropertyService.getProgramPatientProperty( program, fixedAttr );
+                if (programPatientProperty != null)
+                {
+                    hidden = programPatientProperty.isHidden() ? "hidden" : "";
+                    value = programPatientProperty.getDefaultValue();
+                }
+                
                 if ( patient != null )
                 {
                     Object object = getValueFromPatient( fixedAttr, patient );
@@ -196,15 +211,6 @@
                         }
                     }
                 }
-                else if ( suggestedMarcher.find() )
-                {
-                    value = suggestedMarcher.group( 2 );
-                }
-
-                if ( classMarcher.find() )
-                {
-                    hidden = classMarcher.group( 1 );
-                }
 
                 inputHtml = getFixedAttributeField( inputHtml, fixedAttr, value.toString(), hidden, healthWorkers,
                     i18n, index );
@@ -223,6 +229,15 @@
                     int id = identifierType.getId();
                     // Get value
                     String value = "";
+                    String hidden = "";
+                   
+                    ProgramPatientProperty programPatientProperty = programPatientPropertyService.getProgramPatientProperty( program, identifierType );
+                    if (programPatientProperty != null)
+                    {
+                        hidden = programPatientProperty.isHidden() ? "hidden" : "";
+                        value = programPatientProperty.getDefaultValue();
+                    }
+                    
                     if ( patient != null )
                     {
                         PatientIdentifier patientIdentifier = identifierService.getPatientIdentifier( identifierType,
@@ -237,7 +252,7 @@
                     inputHtml = "<input id=\"iden" + id + "\" name=\"iden" + id + "\" tabindex=\"" + index
                         + "\" value=\"" + value + "\" ";
 
-                    inputHtml += "class=\"{validate:{required:" + identifierType.isMandatory() + ",";
+                    inputHtml += "class=\" " + hidden + " {validate:{required:" + identifierType.isMandatory() + ",";
                     if ( identifierType.getNoChars() != null )
                     {
                         inputHtml += "maxlength:" + identifierType.getNoChars() + ",";
@@ -258,7 +273,16 @@
             {
                 String uid = dynamicAttrMatcher.group( 1 );
                 PatientAttribute attribute = attributeService.getPatientAttribute( uid );
-
+                String value = "";
+                String hidden = "";
+               
+                ProgramPatientProperty programPatientProperty = programPatientPropertyService.getProgramPatientProperty( program, attribute );
+                if (programPatientProperty != null)
+                {
+                    hidden = programPatientProperty.isHidden() ? "hidden" : "";
+                    value = programPatientProperty.getDefaultValue();
+                }
+                
                 if ( attribute == null )
                 {
                     inputHtml = "<input value='[" + i18n.getString( "missing_patient_attribute" ) + " " + uid
@@ -266,8 +290,6 @@
                 }
                 else
                 {
-                    // Get value
-                    String value = "";
                     if ( patient != null )
                     {
                         PatientAttributeValue attributeValue = attributeValueService.getPatientAttributeValue( patient,
@@ -278,7 +300,7 @@
                         }
                     }
 
-                    inputHtml = getAttributeField( inputHtml, attribute, value, i18n, index );
+                    inputHtml = getAttributeField( inputHtml, attribute, value, i18n, index, hidden );
                 }
 
             }
@@ -332,12 +354,12 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private String getAttributeField( String inputHtml, PatientAttribute attribute, String value, I18n i18n, int index )
+    private String getAttributeField( String inputHtml, PatientAttribute attribute, String value, I18n i18n, int index, String hidden )
     {
         inputHtml = TAG_OPEN + "input id=\"attr" + attribute.getId() + "\" name=\"attr" + attribute.getId()
             + "\" tabindex=\"" + index + "\" ";
 
-        inputHtml += "\" class=\"{validate:{required:" + attribute.isMandatory();
+        inputHtml += "\" class=\" " + hidden + " {validate:{required:" + attribute.isMandatory();
         if ( PatientAttribute.TYPE_INT.equals( attribute.getValueType() ) )
         {
             inputHtml += ",number:true";

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-09-27 05:05:59 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-09-27 07:43:07 +0000
@@ -248,6 +248,11 @@
 
         executeSql( "update patientidentifiertype set orgunitScope=false where orgunitScope is null" );
         executeSql( "update patientidentifiertype set programScope=false where programScope is null" );
+
+        int index = updateProgramPatientAttribue();
+        updateProgramPatientIdentifierType( index );
+        executeSql( "DROP TABLE program_patientattributes" );
+        executeSql( "DROP TABLE program_patientidentifiertypes" );
     }
 
     // -------------------------------------------------------------------------
@@ -382,6 +387,73 @@
         executeSql( "ALTER TABLE programinstance DROP COLUMN completed" );
     }
 
+    private int updateProgramPatientAttribue()
+    {
+        StatementHolder holder = statementManager.getHolder();
+
+        try
+        {
+            Statement statement = holder.getStatement();
+
+            ResultSet resultSet = statement
+                .executeQuery( "select programid, patientattributeid, sort_order from program_patientattributes" );
+            int i = 1;
+            while ( resultSet.next() )
+            {
+                executeSql( "insert into programpatientproperty( programpatientpropertyid, programid, patientattributeid, hidden, sortOrder) "
+                    + "values ("
+                    + i
+                    + ", "
+                    + resultSet.getInt( "programid" )
+                    + ","
+                    + resultSet.getInt( "patientattributeid" ) + ", false, " + resultSet.getInt( "sort_order" ) + ") " );
+                i++;
+            }
+            return i;
+        }
+        catch ( Exception ex )
+        {
+            log.debug( ex );
+        }
+        finally
+        {
+            holder.close();
+        }
+        return 0;
+    }
+
+    private void updateProgramPatientIdentifierType( int index )
+    {
+        StatementHolder holder = statementManager.getHolder();
+
+        try
+        {
+            Statement statement = holder.getStatement();
+
+            ResultSet resultSet = statement
+                .executeQuery( "select programid, patientidentifiertypeid, sort_order from program_patientidentifiertypes" );
+            while ( resultSet.next() )
+            {
+                executeSql( "insert into programpatientproperty( programpatientpropertyid, programid, patientidentifiertypeid, hidden, sortOrder) "
+                    + "values ("
+                    + index
+                    + ", "
+                    + resultSet.getInt( "programid" )
+                    + ","
+                    + resultSet.getInt( "patientidentifiertypeid" ) + ", false, " + resultSet.getInt( "sort_order" ) + ") " );
+                index++;
+            }
+        }
+        catch ( Exception ex )
+        {
+            log.debug( ex );
+        }
+        finally
+        {
+            holder.close();
+        }
+    }
+
     private int executeSql( String sql )
     {
         try

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-27 04:43:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-27 07:43:07 +0000
@@ -465,6 +465,8 @@
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="attributeValueService"
 			ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
+		<property name="programPatientPropertyService"
+			ref="org.hisp.dhis.program.ProgramPatientPropertyService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientRegistrationFormStore"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java	2013-09-27 04:43:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java	2013-09-27 07:43:07 +0000
@@ -133,6 +133,13 @@
         return identifierTypes;
     }
 
+    private Collection<String> fixedProperties;
+
+    public Collection<String> getFixedProperties()
+    {
+        return fixedProperties;
+    }
+
     private PatientRegistrationForm registrationForm;
 
     public PatientRegistrationForm getRegistrationForm()
@@ -187,10 +194,15 @@
         else
         {
             program = programService.getProgram( programId );
-            
+
             identifierTypes.addAll( programPatientPropertyService.getPatientIdentifierTypes( program ) );
             attributes.addAll( programPatientPropertyService.getPatientAttributes( program ) );
-            
+            fixedProperties = programPatientPropertyService.getPatientProperties( program );
+            if ( fixedProperties == null )
+            {
+                fixedProperties = new HashSet<String>();
+            }
+
             registrationForm = patientRegistrationFormService.getPatientRegistrationForm( program );
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2013-09-27 04:43:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2013-09-27 07:43:07 +0000
@@ -483,7 +483,6 @@
                 }
                 else
                 {
-                    programPatientProperty.setProgram( program );
                     programPatientProperty.setHidden( hiddens.get( index ) );
                     programPatientProperty.setDefaultValue( defaultValues.get( index ) );
                     programPatientProperty.setSortOrder( index );
@@ -509,7 +508,6 @@
                 }
                 else
                 {
-                    programPatientProperty.setProgram( program );
                     programPatientProperty.setHidden( hiddens.get( index ) );
                     programPatientProperty.setDefaultValue( defaultValues.get( index ) );
                     programPatientProperty.setSortOrder( index );
@@ -531,12 +529,11 @@
                 }
                 else
                 {
-                    programPatientProperty.setProgram( program );
                     programPatientProperty.setHidden( hiddens.get( index ) );
                     programPatientProperty.setDefaultValue( defaultValues.get( index ) );
                     programPatientProperty.setSortOrder( index );
                     programPatientPropertyService.updateProgramPatientProperty( programPatientProperty );
-
+                    
                     removeProgramProperties.remove( programPatientProperty );
                 }
             }