← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9401: Improve registering a new person in single event with registration.

 

------------------------------------------------------------
revno: 9401
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-27 12:20:24 +0700
message:
  Improve registering a new person in single event with registration.
modified:
  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/ValidatePatientProgramEnrollmentAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js


--
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/ValidatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2012-09-27 13:00:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2012-12-27 05:20:24 +0000
@@ -28,7 +28,6 @@
 package org.hisp.dhis.caseentry.action.patient;
 
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -38,7 +37,6 @@
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientIdentifier;
 import org.hisp.dhis.patient.PatientIdentifierService;
@@ -47,6 +45,9 @@
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.validation.ValidationCriteria;
 
 import com.opensymphony.xwork2.Action;
 
@@ -63,8 +64,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private OrganisationUnitSelectionManager selectionManager;
-
     private I18nFormat format;
 
     private PatientService patientService;
@@ -75,14 +74,14 @@
 
     private PatientIdentifierTypeService identifierTypeService;
 
+    private ProgramService programService;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
 
     private String fullName;
 
-    private Character dobType;
-
     private String birthDate;
 
     private char ageType;
@@ -101,6 +100,8 @@
 
     private Integer relationshipTypeId;
 
+    private Integer programId;
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -123,47 +124,8 @@
 
     public String execute()
     {
-        Date dateOfBirth;
-
-        if ( selectionManager.getSelectedOrganisationUnit() == null )
-        {
-            message = i18n.getString( "please_select_a_registering_unit" );
-
-            return INPUT;
-        }
-
-        if ( dobType != null && dobType == Patient.DOB_TYPE_APPROXIATED )
-        {
-            Patient patient = new Patient();
-            patient.setBirthDateFromAge( age.intValue(), ageType );
-
-            if ( patient.getIntegerValueOfAge() > 100 )
-            {
-                message = i18n.getString( "age_of_patient_must_be_less_or_equals_to_100" );
-                return INPUT;
-            }
-        }
-
-        if ( dobType != null && (dobType == Patient.DOB_TYPE_VERIFIED || dobType == Patient.DOB_TYPE_DECLARED) )
-        {
-            birthDate = birthDate.trim();
-
-            dateOfBirth = format.parseDate( birthDate );
-
-            if ( dateOfBirth == null || dateOfBirth.after( new Date() ) )
-            {
-                message = i18n.getString( "please_enter_a_valid_birth_date" );
-
-                return INPUT;
-            }
-        }
-
         fullName = fullName.trim();
 
-        // ---------------------------------------------------------------------
-        // Check duplicated patients
-        // ---------------------------------------------------------------------
-
         int startIndex = fullName.indexOf( ' ' );
         int endIndex = fullName.lastIndexOf( ' ' );
 
@@ -239,6 +201,7 @@
         }
 
         Patient p = new Patient();
+        p.setGender( gender );
 
         if ( birthDate != null )
         {
@@ -288,6 +251,46 @@
         }
 
         // ---------------------------------------------------------------------
+        // Check Enrollment for adding patient single event with registration
+        // ---------------------------------------------------------------------
+
+        if ( programId != null )
+        {
+            Program program = programService.getProgram( programId );
+            ValidationCriteria criteria = program.isValid( p );
+
+            if ( criteria != null )
+            {
+                message = i18n.getString( "patient_could_not_be_enrolled_due_to_following_enrollment_criteria" ) + ": "
+                    + i18n.getString( criteria.getProperty() );
+
+                switch ( criteria.getOperator() )
+                {
+                case ValidationCriteria.OPERATOR_EQUAL_TO:
+                    message += " = ";
+                    break;
+                case ValidationCriteria.OPERATOR_GREATER_THAN:
+                    message += " > ";
+                    break;
+                default:
+                    message += " < ";
+                    break;
+                }
+
+                if ( criteria.getProperty() == "birthDate" )
+                {
+                    message += " " + format.formatValue( criteria.getValue() );
+                }
+                else
+                {
+                    message += " " + criteria.getValue().toString();
+                }
+
+                return INPUT;
+            }
+        }
+
+        // ---------------------------------------------------------------------
         // Validation success
         // ---------------------------------------------------------------------
 
@@ -300,6 +303,16 @@
     // Getter/Setter
     // -------------------------------------------------------------------------
 
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    public void setProgramId( Integer programId )
+    {
+        this.programId = programId;
+    }
+
     public Collection<Patient> getPatients()
     {
         return patients;
@@ -315,11 +328,6 @@
         this.patientIdentifierService = patientIdentifierService;
     }
 
-    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
-    {
-        this.selectionManager = selectionManager;
-    }
-
     public void setFormat( I18nFormat format )
     {
         this.format = format;
@@ -409,9 +417,4 @@
     {
         this.ageType = ageType;
     }
-
-    public void setDobType( Character dobType )
-    {
-        this.dobType = dobType;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientProgramEnrollmentAction.java	2012-03-14 02:44:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientProgramEnrollmentAction.java	2012-12-27 05:20:24 +0000
@@ -117,10 +117,9 @@
         if ( criteria != null )
         {
             message = i18n.getString( "patient_could_not_be_enrolled_due_to_following_enrollment_criteria" ) + ": " + i18n.getString( criteria.getProperty() );
-
+            
             switch ( criteria.getOperator() )
             {
-
             case ValidationCriteria.OPERATOR_EQUAL_TO:
                 message += " = ";
                 break;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-12-26 03:02:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-12-27 05:20:24 +0000
@@ -486,8 +486,7 @@
 	<bean id="org.hisp.dhis.caseentry.action.patient.ValidatePatientAction"
 		class="org.hisp.dhis.caseentry.action.patient.ValidatePatientAction"
 		scope="prototype">
-		<property name="selectionManager"
-			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
+		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 		<property name="patientAttributeValueService">
 			<ref

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js	2012-12-10 12:54:54 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js	2012-12-27 05:20:24 +0000
@@ -65,11 +65,12 @@
 
 function validateData()
 {
+	var params = "programId=" + getFieldValue('programIdAddPatient') + "&" + getParamsForDiv('patientForm');
 	$("#patientForm :input").attr("disabled", true);
 	$.ajax({
 		type: "POST",
 		url: 'validatePatient.action',
-		data: getParamsForDiv('patientForm'),
+		data: params,
 		success: function( data ){
 			var type = jQuery(data).find('message').attr('type');
 			var message = jQuery(data).find('message').text();
@@ -109,47 +110,11 @@
 		data: getParamsForDiv('patientForm'),
 		success: function(json) {
 			var patientId = json.message.split('_')[0];
-			validateSingleProgramEnrollment( getFieldValue('programIdAddPatient'), patientId )
+			addData( getFieldValue('programIdAddPatient'), patientId );
 		}
      });
 }
 
-function validateSingleProgramEnrollment( programId, patientId )
-{	
-	jQuery('#loaderDiv').show();
-	jQuery.getJSON( "validatePatientProgramEnrollment.action",
-		{
-			patientId: patientId,
-			programId: programId
-		}, 
-		function( json ) 
-		{    
-			hideById('message');
-			var type = json.response;
-			if ( type == 'success' ){
-				addData( programId, patientId );
-			}
-			else if ( type == 'error' ){
-				showWarningMessage( i18n_program_enrollment_failed + ':' + '\n' + message );
-				removeEvent( patientId );
-			}
-			else if ( type == 'input' ){
-				showWarningMessage( json.message );
-				removeEvent( patientId );
-			}
-			jQuery('#loaderDiv').hide();
-		});
-}
-
-function removeEvent( patientId )
-{
-	$("#patientForm :input").attr("disabled",false);
-	jQuery.postJSON( "removePatient.action",
-		{
-			id: patientId
-		}, function(json){});
-}
-
 function addData( programId, patientId )
 {		
 	var params = "programId=" + getFieldValue('programIdAddPatient');
@@ -161,7 +126,7 @@
 		url: 'saveValues.action',
 		data: params,
 		success: function(json) {
-			showSuccessMessage( i18n_save_success );
+			$("#patientForm :input").attr("disabled", true);
 			jQuery("#resultSearchDiv").dialog("close");
 			if( _continue==true )
 			{
@@ -195,6 +160,7 @@
 					showById('contentDiv');
 				}
 			}
+			showSuccessMessage( i18n_save_success );
 		}
      });
     return false;