← Back to team overview

dhis-mobile-devs team mailing list archive

[Branch ~dhis-mobile-devs/dhis-mobile/lwuit-tracking] Rev 179: re-organize validation steps

 

------------------------------------------------------------
revno: 179
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: lwuit-tracking
timestamp: Fri 2013-11-01 13:18:37 +0700
message:
  re-organize validation steps
modified:
  build.xml
  src/org/hisp/dhis/mobile/view/PersonRegistrationView.java


--
lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking
https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking

Your team DHIS mobile developers is subscribed to branch lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking/+edit-subscription
=== modified file 'build.xml'
--- build.xml	2013-10-30 09:20:56 +0000
+++ build.xml	2013-11-01 06:18:37 +0000
@@ -34,7 +34,7 @@
 	<!-- Which logo to use -->
 	<property name="logo" value="dhis2_logo.png" />
 	<!-- Server URL -->
-	<property name="server.url" value="http://localhost:9999"; />
+	<property name="server.url" value="http://localhost:8080/dhis"; />
 	<!-- User Name -->
 	<property name="username" value="mobile" />
 	<!-- Password -->

=== modified file 'src/org/hisp/dhis/mobile/view/PersonRegistrationView.java'
--- src/org/hisp/dhis/mobile/view/PersonRegistrationView.java	2013-10-31 08:42:12 +0000
+++ src/org/hisp/dhis/mobile/view/PersonRegistrationView.java	2013-11-01 06:18:37 +0000
@@ -318,48 +318,16 @@
     {
         if ( ae.getCommand().getCommandName().equals( Text.SEND() ) )
         {
-
             String dobType = (String) getDateOfBirthComboBox().getSelectedItem();
             String dateOfBirth = getDateOfBirthTextFiled().getText();
             String incidentDate = getTxtIncidentDate().getText();
-
-            this.patient = this.collectData();
-
+            isValid = true;
             // Validate Date of Birth
-            if ( !dobType.equalsIgnoreCase( "Approximated" ) && !PeriodUtil.isDateValid( dateOfBirth ) )
-            {
-
-                getDobWrongFortmatLabel().setText( Text.DOB_WRONG_FORMAT() );
-                this.isValid = false;
-            }
-            else if ( dateOfBirth.equals( "" ) )
-            {
-                getDobWrongFortmatLabel().setText( "(*):Required Field" );
-                this.isValid = false;
-            }
-            else
-            {
-                getDobWrongFortmatLabel().setText( "" );
-            }
-
+            validateDOB( dobType, dateOfBirth );
             // Validate Incident Date
-            if ( enrollProgramId != null && incidentDate.trim().equals( "" ) )
-            {
-                getRequiredLabel().setText( "(*):Required Field" );
-                this.isValid = false;
-            }
-            else if ( enrollProgramId != null && !PeriodUtil.isDateValid( incidentDate ) )
-            {
-                getRequiredLabel().setText( "YYYY-MM-dd" );
-                this.isValid = false;
-            }
-            else
-            {
-                getRequiredLabel().setText( "" );
-            }
-
-            if ( this.isValid == false )
-
+            validateIncidentDate( incidentDate );
+
+            if ( isValid == false )
             {
                 patientAttributeValueVector.removeAllElements();
                 patientIdentifierValueVector.removeAllElements();
@@ -367,10 +335,8 @@
             }
             else
             {
-
+                nameBasedMIDlet.getWaitingView().showView();
                 patient = collectData();
-
-                nameBasedMIDlet.getWaitingView().showView();
                 ConnectionManager.setUrl( dhisMIDlet.getCurrentOrgUnit().getRegisterPersonUrl() );
                 ConnectionManager.registerPerson( patient, enrollProgramId );
                 try
@@ -388,39 +354,33 @@
                 requiredLabel = null;
                 patientIdentifierVector = null;
                 patientAttributeVector = null;
+                txtIncidentDate = null;
                 System.gc();
             }
-
         }
         else if ( ae.getCommand().getCommandName().equals( Text.SAVE() ) )
         {
-
             String dobType = (String) getDateOfBirthComboBox().getSelectedItem();
             String dateOfBirth = getDateOfBirthTextFiled().getText();
-
-            this.patient = this.collectData();
-
-            if ( !dobType.equalsIgnoreCase( "Approximated" ) && !PeriodUtil.isDateValid( dateOfBirth ) )
-            {
-                this.isValid = false;
-            }
-
-            if ( dateOfBirth.equals( "" ) || this.isValid == false )
+            String incidentDate = getTxtIncidentDate().getText();
+            
+            isValid = true;
+            // Validate Date of Birth
+            validateDOB( dobType, dateOfBirth );
+            // Validate Incident Date
+            validateIncidentDate( incidentDate );
+
+            if ( isValid == false )
             {
                 patientAttributeValueVector.removeAllElements();
                 patientIdentifierValueVector.removeAllElements();
-                getDobWrongFortmatLabel().setText( Text.DOB_WRONG_FORMAT() );
                 getMainForm().show();
             }
             else
             {
+                nameBasedMIDlet.getWaitingView().showView();
                 patient = collectData();
 
-                nameBasedMIDlet.getWaitingView().showView();
-                /*
-                 * saveUnregisteredPersonTask = new SaveUnregisteredPersonTask(
-                 * patient ); saveUnregisteredPersonTask.run();
-                 */
                 ConnectionManager.saveUnregisterdPatient( patient );
                 try
                 {
@@ -437,6 +397,7 @@
                 requiredLabel = null;
                 patientIdentifierVector = null;
                 patientAttributeVector = null;
+                txtIncidentDate = null;
                 System.gc();
             }
         }
@@ -490,7 +451,7 @@
     {
         // No fullName for Uganda case
         // String fullName = this.getFullNameTextField().getText().trim();
-        this.isValid = true;
+        isValid = true;
         String fullName = "";
         String gender = (String) getGenderComboBox().getSelectedItem();
         String dobType = (String) getDateOfBirthComboBox().getSelectedItem();
@@ -537,8 +498,6 @@
             {
                 birthYear = currentYear - Integer.parseInt( dateOfBirth );
                 dateOfBirth = birthYear + "-" + currentMonth + "-" + currentDate;
-                // dateOfBirth = currentDate + "-" + currentMonth + "-" +
-                // birthYear;
             }
             catch ( Exception e )
             {
@@ -598,8 +557,6 @@
                 patientAttribute.setValue( value );
                 patientAttribute.setType( "" );
                 patientAttribute.setPredefinedValues( new Vector() );
-                // patientAttributeValueVector.setElementAt( patientAttribute, i
-
                 attributeVector.addElement( patientAttribute );
             }
         }
@@ -649,6 +606,50 @@
         return patient;
     }
 
+    // -------------------------------------------------------------------------
+    // Support Methods
+    // -------------------------------------------------------------------------
+
+    public void validateDOB( String dobType, String dateOfBirth )
+    {
+        if ( !dobType.equalsIgnoreCase( "Approximated" ) && !PeriodUtil.isDateValid( dateOfBirth ) )
+        {
+            getDobWrongFortmatLabel().setText( Text.DOB_WRONG_FORMAT() );
+            isValid = false;
+        }
+        else if ( dateOfBirth.equals( "" ) )
+        {
+            getDobWrongFortmatLabel().setText( "(*):Required Field" );
+            isValid = false;
+        }
+        else
+        {
+            getDobWrongFortmatLabel().setText( "" );
+        }
+    }
+
+    public void validateIncidentDate( String incidentDate )
+    {
+        if ( enrollProgramId != null && incidentDate.trim().equals( "" ) )
+        {
+            getRequiredLabel().setText( "(*):Required Field" );
+            isValid = false;
+        }
+        else if ( enrollProgramId != null && !PeriodUtil.isDateValid( incidentDate ) )
+        {
+            getRequiredLabel().setText( "YYYY-MM-dd" );
+            isValid = false;
+        }
+        else
+        {
+            getRequiredLabel().setText( "" );
+        }
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters/Setters
+    // -------------------------------------------------------------------------
+
     public Label getWarningLabel()
     {
         Label label = new Label();
@@ -681,6 +682,11 @@
         return enrollProgramId;
     }
 
+    public void setEnrollProgramId( String enrollProgramId )
+    {
+        this.enrollProgramId = enrollProgramId;
+    }
+
     public TextField getTxtIncidentDate()
     {
         if ( txtIncidentDate == null )
@@ -799,4 +805,5 @@
         }
         return patientAttributeTextField;
     }
+
 }
\ No newline at end of file