← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2965: Fix bug: Cannot add Representative person and Relationship person.

 

------------------------------------------------------------
revno: 2965
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-03-02 15:47:32 +0700
message:
  Fix bug: Cannot add Representative person and Relationship person.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddRepresentativeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/AddRelationshipPatientAction.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-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddRepresentativeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddRepresentativeAction.java	2011-01-12 02:35:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/AddRepresentativeAction.java	2011-03-02 08:47:32 +0000
@@ -114,30 +114,37 @@
         // Get FirstName, MiddleName, LastName by FullName
         // ---------------------------------------------------------------------
 
+     // ---------------------------------------------------------------------
+        // Set FirstName, MiddleName, LastName by FullName
+        // ---------------------------------------------------------------------
+        
+        fullName = fullName.trim();
+        
         int startIndex = fullName.indexOf( ' ' );
         int endIndex = fullName.lastIndexOf( ' ' );
 
-        String name = fullName.substring( 0, startIndex );
-        patient.setFirstName( name );
-
-        if ( startIndex == endIndex )
-        {
-            patient.setMiddleName( "" );
-            
-            name = fullName.substring( startIndex, fullName.length() );
-            patient.setLastName( name );
-        }
-        else
-        {
-            name = fullName.substring( startIndex + 1, endIndex );
-            patient.setMiddleName( name );
-            
-            name = fullName.substring( endIndex, fullName.length() );
-            patient.setLastName( name );
-        }
-        
-        patient.setLastName( fullName.substring( endIndex, fullName.length() ) );
-
+        String firstName = fullName.toString();
+        String middleName = "";
+        String lastName = "";
+
+        if( fullName.indexOf( ' ' ) != -1 )
+        {
+            firstName = fullName.substring( 0, startIndex );
+            if ( startIndex == endIndex )
+            {
+                middleName = "";
+                lastName = fullName.substring( startIndex + 1, fullName.length() );
+            }
+            else
+            {
+                middleName = fullName.substring( startIndex + 1, endIndex );
+                lastName = fullName.substring( endIndex + 1, fullName.length() );
+            }
+        }
+
+        patient.setFirstName( firstName );
+        patient.setMiddleName( middleName );
+        patient.setLastName( lastName );
         // ---------------------------------------------------------------------
         // Get Other information for patient
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/AddRelationshipPatientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/AddRelationshipPatientAction.java	2011-01-12 02:35:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/AddRelationshipPatientAction.java	2011-03-02 08:47:32 +0000
@@ -122,34 +122,43 @@
         OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
 
         patient = new Patient();
+        
         // ---------------------------------------------------------------------
         // Set FirstName, MiddleName, LastName by FullName
         // ---------------------------------------------------------------------
 
+     // ---------------------------------------------------------------------
+        // Set FirstName, MiddleName, LastName by FullName
+        // ---------------------------------------------------------------------
+        
+        fullName = fullName.trim();
+        
         int startIndex = fullName.indexOf( ' ' );
         int endIndex = fullName.lastIndexOf( ' ' );
 
-        String name = fullName.substring( 0, startIndex );
-        patient.setFirstName( name );
-
-        if ( startIndex == endIndex )
-        {
-            patient.setMiddleName( "" );
-            
-            name = fullName.substring( startIndex, fullName.length() );
-            patient.setLastName( name );
-        }
-        else
-        {
-            name = fullName.substring( startIndex + 1, endIndex );
-            patient.setMiddleName( name );
-            
-            name = fullName.substring( endIndex, fullName.length() );
-            patient.setLastName( name );
-        }
+        String firstName = fullName.toString();
+        String middleName = "";
+        String lastName = "";
+
+        if( fullName.indexOf( ' ' ) != -1 )
+        {
+            firstName = fullName.substring( 0, startIndex );
+            if ( startIndex == endIndex )
+            {
+                middleName = "";
+                lastName = fullName.substring( startIndex + 1, fullName.length() );
+            }
+            else
+            {
+                middleName = fullName.substring( startIndex + 1, endIndex );
+                lastName = fullName.substring( endIndex + 1, fullName.length() );
+            }
+        }
+
+        patient.setFirstName( firstName );
+        patient.setMiddleName( middleName );
+        patient.setLastName( lastName );
         
-        patient.setLastName( fullName.substring( endIndex, fullName.length() ) );
-
         // ---------------------------------------------------------------------
         // Set Other information for patient
         // ---------------------------------------------------------------------