← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11368: Add validation for default registration form; Remove validation of registration fields in design ...

 

------------------------------------------------------------
revno: 11368
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-07-09 13:32:58 +0700
message:
  Add validation for default registration form; Remove validation of registration fields in design custom entry form.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SavePatientRegistrationFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/defaultPatientRegistationForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java	2013-06-10 04:48:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java	2013-07-09 06:32:58 +0000
@@ -28,6 +28,7 @@
 package org.hisp.dhis.caseentry.action.patient;
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -53,6 +54,7 @@
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.patient.util.PatientIdentifierGenerator;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.user.UserService;
 
@@ -203,7 +205,7 @@
         {
             verified = (verified == null) ? false : verified;
 
-            Character dobType = (verified) ? 'V' : 'D';
+            Character dobType = (verified) ? Patient.DOB_TYPE_VERIFIED : Patient.DOB_TYPE_DECLARED;
 
             if ( !verified && age != null )
             {
@@ -223,6 +225,15 @@
             _birthDate = patient.getBirthDate();
             patient.setDobType( dobType );
         }
+//        else
+//        {
+//            Character dobType = Patient.DOB_TYPE_DECLARED;
+//            Calendar today = Calendar.getInstance();
+//            PeriodType.clearTimeOfDay( today );
+//            Date date = today.getTime();
+//            patient.setBirthDate( date ); 
+//            patient.setDobType( dobType );
+//        }
 
         // -----------------------------------------------------------------------------
         // Registration Date
@@ -276,6 +287,7 @@
         {
             gender = Patient.FEMALE;
         }
+        
         String identifier = PatientIdentifierGenerator.getNewIdentifier( _birthDate, gender );
 
         PatientIdentifier systemGenerateIdentifier = patientIdentifierService.get( null, identifier );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java	2013-05-21 04:18:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java	2013-07-09 06:32:58 +0000
@@ -28,6 +28,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -148,32 +149,37 @@
         // Set FirstName, MiddleName, LastName by FullName
         // ---------------------------------------------------------------------
 
-        int startIndex = fullName.indexOf( ' ' );
-        int endIndex = fullName.lastIndexOf( ' ' );
-
-        String firstName = fullName.toString();
-        String middleName = "";
-        String lastName = "";
-
-        if ( fullName.indexOf( ' ' ) != -1 )
+        if ( fullName != null )
         {
-            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() );
-            }
+            fullName = fullName.trim();
+
+            int startIndex = fullName.indexOf( ' ' );
+            int endIndex = fullName.lastIndexOf( ' ' );
+
+            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.setFirstName( firstName );
-        patient.setMiddleName( middleName );
-        patient.setLastName( lastName );
-
         // ---------------------------------------------------------------------
         // Set Other information for patient
         // ---------------------------------------------------------------------
@@ -182,39 +188,48 @@
             .getSystemSetting( SystemSettingManager.KEY_PHONE_NUMBER_AREA_CODE ) )) ? null : phoneNumber;
 
         patient.setGender( gender );
+        patient.setIsDead( false );
+        patient.setPhoneNumber( phoneNumber );
+        patient.setUnderAge( underAge );
+        patient.setOrganisationUnit( organisationUnit );
         patient.setIsDead( isDead );
-        patient.setPhoneNumber( phoneNumber );
-        if ( healthWorker != null )
-        {
-            patient.setHealthWorker( userService.getUser( healthWorker ) );
-        }
-
         if ( deathDate != null )
         {
             deathDate = deathDate.trim();
             patient.setDeathDate( format.parseDate( deathDate ) );
         }
 
-        patient.setUnderAge( underAge );
-        patient.setOrganisationUnit( organisationUnit );
-
-        if ( dobType == Patient.DOB_TYPE_VERIFIED || dobType == Patient.DOB_TYPE_DECLARED )
-        {
-            birthDate = birthDate.trim();
-            patient.setBirthDate( format.parseDate( birthDate ) );
-        }
-        else
-        {
-            patient.setBirthDateFromAge( age.intValue(), Patient.AGE_TYPE_YEAR );
-        }
-
-        patient.setDobType( dobType );
-
-        if ( registrationDate != null )
-        {
-            patient.setRegistrationDate( format.parseDate( registrationDate ) );
-        }
-
+        if ( healthWorker != null )
+        {
+            patient.setHealthWorker( userService.getUser( healthWorker ) );
+        }
+
+        Date _birthDate = new Date();
+        if ( birthDate != null || age != null )
+        {
+            verified = (verified == null) ? false : verified;
+
+            Character dobType = (verified) ? Patient.DOB_TYPE_VERIFIED : Patient.DOB_TYPE_DECLARED;
+
+            if ( !verified && age != null )
+            {
+                dobType = 'A';
+            }
+
+            if ( dobType == Patient.DOB_TYPE_VERIFIED || dobType == Patient.DOB_TYPE_DECLARED )
+            {
+                birthDate = birthDate.trim();
+                patient.setBirthDate( format.parseDate( birthDate ) );
+            }
+            else
+            {
+                patient.setBirthDateFromAge( age.intValue(), Patient.AGE_TYPE_YEAR );
+            }
+
+            _birthDate = patient.getBirthDate();
+            patient.setDobType( dobType );
+        }
+        
         // -------------------------------------------------------------------------------------
         // Save PatientIdentifier
         // -------------------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2012-12-27 05:24:12 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2013-07-09 06:32:58 +0000
@@ -122,60 +122,63 @@
 
     public String execute()
     {
-        fullName = fullName.trim();
-
-        int startIndex = fullName.indexOf( ' ' );
-        int endIndex = fullName.lastIndexOf( ' ' );
-
-        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() );
-            }
-        }
-
-        if ( !checkedDuplicate )
-        {
-            patients = patientService.getPatients( firstName, middleName, lastName, format.parseDate( birthDate ),
-                gender );
-
-            if ( patients != null && patients.size() > 0 )
-            {
-                message = i18n.getString( "patient_duplicate" );
-
-                boolean flagDuplicate = false;
-                for ( Patient p : patients )
-                {
-                    if ( id == null || (id != null && p.getId().intValue() != id.intValue()) )
+        if ( fullName != null )
+        {
+            fullName = fullName.trim();
+
+            int startIndex = fullName.indexOf( ' ' );
+            int endIndex = fullName.lastIndexOf( ' ' );
+
+            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() );
+                }
+            }
+
+            if ( !checkedDuplicate && birthDate != null && gender != null )
+            {
+                patients = patientService.getPatients( firstName, middleName, lastName, format.parseDate( birthDate ),
+                    gender );
+
+                if ( patients != null && patients.size() > 0 )
+                {
+                    message = i18n.getString( "patient_duplicate" );
+
+                    boolean flagDuplicate = false;
+                    for ( Patient p : patients )
                     {
-                        flagDuplicate = true;
-                        Collection<PatientAttributeValue> patientAttributeValues = patientAttributeValueService
-                            .getPatientAttributeValues( p );
-
-                        for ( PatientAttributeValue patientAttributeValue : patientAttributeValues )
+                        if ( id == null || (id != null && p.getId().intValue() != id.intValue()) )
                         {
-                            patientAttributeValueMap
-                                .put( p.getId() + "_" + patientAttributeValue.getPatientAttribute().getId(),
+                            flagDuplicate = true;
+                            Collection<PatientAttributeValue> patientAttributeValues = patientAttributeValueService
+                                .getPatientAttributeValues( p );
+
+                            for ( PatientAttributeValue patientAttributeValue : patientAttributeValues )
+                            {
+                                patientAttributeValueMap.put( p.getId() + "_"
+                                    + patientAttributeValue.getPatientAttribute().getId(),
                                     patientAttributeValue.getValue() );
+                            }
                         }
                     }
-                }
 
-                if ( flagDuplicate )
-                {
-                    return PATIENT_DUPLICATE;
+                    if ( flagDuplicate )
+                    {
+                        return PATIENT_DUPLICATE;
+                    }
                 }
             }
         }
@@ -198,20 +201,6 @@
             }
         }
 
-        Patient p = new Patient();
-        p.setGender( gender );
-
-        if ( birthDate != null )
-        {
-            birthDate = birthDate.trim();
-            p.setBirthDate( format.parseDate( birthDate ) );
-
-        }
-        else
-        {
-            p.setBirthDateFromAge( age.intValue(), ageType );
-        }
-
         HttpServletRequest request = ServletActionContext.getRequest();
 
         Collection<PatientIdentifierType> identifiers = identifierTypeService.getAllPatientIdentifierTypes();
@@ -252,6 +241,23 @@
         // Check Enrollment for adding patient single event with registration
         // ---------------------------------------------------------------------
 
+        Patient p = new Patient();
+        if ( gender != null )
+        {
+            p.setGender( gender );
+        }
+
+        if ( birthDate != null )
+        {
+            birthDate = birthDate.trim();
+            p.setBirthDate( format.parseDate( birthDate ) );
+
+        }
+        else if ( age != null )
+        {
+            p.setBirthDateFromAge( age.intValue(), ageType );
+        }
+
         if ( programId != null )
         {
             Program program = programService.getProgram( programId );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SavePatientRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SavePatientRegistrationFormAction.java	2013-04-24 04:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SavePatientRegistrationFormAction.java	2013-07-09 06:32:58 +0000
@@ -76,7 +76,7 @@
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
-    
+
     private String name;
 
     public void setName( String name )
@@ -144,9 +144,19 @@
         else
         {
             DataEntryForm dataEntryForm = registrationForm.getDataEntryForm();
-            dataEntryForm.setName( name );
-            dataEntryForm.setHtmlCode( designTextarea );
-            dataEntryFormService.updateDataEntryForm( dataEntryForm );
+            if ( dataEntryForm == null )
+            {
+                dataEntryForm = new DataEntryForm( name, designTextarea );
+                dataEntryFormService.addDataEntryForm( dataEntryForm );
+            }
+            else
+            {
+                dataEntryForm.setName( name );
+                dataEntryForm.setHtmlCode( designTextarea );
+                dataEntryFormService.updateDataEntryForm( dataEntryForm );
+            }
+            registrationForm.setDataEntryForm( dataEntryForm );
+            patientRegistrationFormService.updatePatientRegistrationForm( registrationForm );
         }
 
         Integer dataEntryFormId = dataEntryFormService.getDataEntryFormByName( name ).getId();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/defaultPatientRegistationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/defaultPatientRegistationForm.vm	2013-07-04 05:57:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/defaultPatientRegistationForm.vm	2013-07-09 06:32:58 +0000
@@ -1,3 +1,13 @@
+<script>
+jQuery(document).ready(	function(){
+	validation( 'defaultPatientRegistrationForm', function(form){
+		form.submit();
+	});
+	
+	byId('name').focus();
+});	
+</script>
+
 <h3>$i18n.getString( "create_default_registration_form" )</h3>
 																			
 <form id="defaultPatientRegistrationForm" name="defaultPatientRegistrationForm" action="saveDefaultPatientRegistrationForm.action" method="post" onsubmit="selectAllById('fixedAttributes');selectAllById('dynamicAttributeIds');selectAllById('identifierTypeIds');">
@@ -25,7 +35,6 @@
 		<th>$i18n.getString( "available_fixed_attributes" )</th>
 		<th>$i18n.getString( "filter" )</th>
 		<th>$i18n.getString( "selected_fixed_attributes" )
-			<input type='hidden' id='hasAttributes' name='hasAttributes' class="{validate:{required:true}}">
 		</th>
 	</tr>
 	<tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-07-02 02:25:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-07-09 06:32:58 +0000
@@ -118,7 +118,7 @@
 	showById('programAttrTab');
 }
 
-function getRequiredFields()
+function getDefaultRequiredFields()
 {
 	var requiredFields = {};
 	if( getFieldValue("disableRegistrationFields")!='true' )
@@ -187,6 +187,38 @@
 	return requiredFields;
 }
 
+function validateProgramFields()
+{
+	jQuery('#programAttrSelector option').each(function() {
+		var item = jQuery(this);
+		if( item.attr('mandatory')=='true'){
+			requiredFields['programid=' + item.val()] = item.text();
+		}
+	});
+	
+	var html = jQuery("#designTextarea").ckeditorGet().getData();
+	var input = jQuery( html ).find("input");
+	if( input.length > 0 )
+	{
+		input.each( function(i, item){	
+			var key = "";
+			var inputKey = jQuery(item).attr('fixedattributeid');
+			if( jQuery(item).attr('programid')!=undefined ){
+				inputKey = jQuery(item).attr('programid');
+				key = 'programid=' + inputKey
+			}
+			
+			for (var idx in requiredFields){
+				if( key == idx){
+					delete requiredFields[idx];
+				}
+			}
+		});
+	}
+	
+	return requiredFields;
+}
+
 function validateFormOnclick()
 {
 	var requiredFields = getRequiredFields();
@@ -400,10 +432,6 @@
 		setHeaderDelayMessage( i18n_enter_a_name );
 		return false;
 	}
-	else if ( !validateForm() )
-	{
-		return false;
-	}
 	else
 	{
 		$.postUTF8( 'validateDataEntryForm.action',

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-07-09 03:26:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-07-09 06:32:58 +0000
@@ -15,7 +15,7 @@
 			
 		jQuery('#designTextarea').ckeditor();
 		#if($!registrationForm)
-			jQuery("#designTextarea").ckeditorGet().setData('$encoder.jsEscape( $!registrationForm.dataEntryForm.htmlCode, "'" )');
+			jQuery("#designTextarea").ckeditorGet().setData('$!encoder.jsEscape( $registrationForm.dataEntryForm.htmlCode , "'" )');
 		#end
 		
 	});
@@ -48,7 +48,7 @@
 }
 </style>
 
-<form id="saveDataEntryForm" name="saveDataEntryForm" action="savePatientRegistrationForm.action" method="post">
+<form id="saveDataEntryForm" name="saveDataEntryForm" action="savePatientRegistrationForm.action" method="get">
 
 <input type="hidden" name="programId" id="programId" value="$!program.id"/>
 <input type="hidden" name="dataEntryFormId" id="dataEntryFormId" value="$!registrationForm.dataEntryForm.id"/>
@@ -96,7 +96,6 @@
         <td>
 		    <button type="button" id="saveButton" onclick="isSave='true';validateDataEntryForm();">$i18n.getString( 'save' )</button>
             <button type="submit" id="saveAndCloseButton" onclick="isSave='false';"/>$i18n.getString( 'save_and_close' )</button>
-            <button type="button" id="validateButton" onclick="validateFormOnclick();">$i18n.getString( 'validate_form' )</button>
             <button type="button" id="cancelButton" onclick="window.location='patientRegistrationForm.action'">$i18n.getString( 'cancel' )</button>
 			&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
 		    <button type="button" id="propertiesButton" onclick="openPropertiesSelector()"/>$i18n.getString( 'insert_properties' )</button>