← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3243: Remove getObject method into action files and use getObjectValue method of service-patient.

 

------------------------------------------------------------
revno: 3243
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-04-01 10:00:35 +0700
message:
  Remove getObject method into action files and use getObjectValue method of service-patient.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateValueAction.java
  dhis-2/dhis-web/dhis-web-caseentry/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/validation/AddValidationCriteriaAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateValidationCriteriaAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml


--
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-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2011-03-31 01:55:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2011-04-01 03:00:35 +0000
@@ -508,7 +508,6 @@
         {
             Type type = Patient.class.getMethod( "get" + StringUtils.capitalize( property ) ).getReturnType();
 
-            // Get value
             if ( type == Integer.class || type == Integer.TYPE )
             {
                 return Integer.valueOf( value );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateValueAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateValueAction.java	2011-03-31 01:49:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateValueAction.java	2011-04-01 03:00:35 +0000
@@ -34,9 +34,9 @@
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.program.Program;
@@ -74,6 +74,8 @@
 
     private PatientDataValueService patientDataValueService;
 
+    private PatientService patientService;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -86,8 +88,6 @@
 
     private int statusCode;
 
-    private I18nFormat format;
-
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -118,11 +118,6 @@
         this.dataElementService = dataElementService;
     }
 
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
     public void setProgramInstanceService( ProgramInstanceService programInstanceService )
     {
         this.programInstanceService = programInstanceService;
@@ -133,6 +128,11 @@
         this.patientDataValueService = patientDataValueService;
     }
 
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
     public int getDataElementId()
     {
         return dataElementId;
@@ -242,7 +242,8 @@
     @SuppressWarnings( "unchecked" )
     private List<ProgramStageDataElementValidation> validation(
         Collection<ProgramStageDataElementValidation> validations, OrganisationUnit organisationUnit,
-        ProgramInstance programInstance, String value, ProgramStage programStage, DataElement dataElement )throws Exception
+        ProgramInstance programInstance, String value, ProgramStage programStage, DataElement dataElement )
+        throws Exception
     {
         List<ProgramStageDataElementValidation> result = new ArrayList<ProgramStageDataElementValidation>();
 
@@ -264,7 +265,7 @@
                     && leftSide.getDataElement().equals( dataElement ) )
                 {
                     // get left-side value
-                    Object objectValue = getObject( leftSide.getDataElement().getType(), value );
+                    Object objectValue = patientService.getObjectValue( leftSide.getDataElement().getType(), value );
 
                     // get program-stage of right-side
                     comparerogramStageInstance = programStageInstanceService.getProgramStageInstance( programInstance,
@@ -277,7 +278,7 @@
                     if ( patientDataValue != null )
                     {
                         String dbValue = patientDataValue.getValue();
-                        Object compareValue = getObject( rightSide.getDataElement().getType(), dbValue );
+                        Object compareValue = patientService.getObjectValue( rightSide.getDataElement().getType(), dbValue );
 
                         i = ((Comparable<Object>) objectValue).compareTo( (Comparable<Object>) compareValue );
                     }
@@ -286,8 +287,8 @@
                 else
                 {
                     // get right-side value
-                    Object objectValue = getObject( rightSide.getDataElement().getType(), value );
-                
+                    Object objectValue = patientService.getObjectValue( rightSide.getDataElement().getType(), value );
+
                     comparerogramStageInstance = programStageInstanceService.getProgramStageInstance( programInstance,
                         leftSide.getProgramStage() );
 
@@ -297,12 +298,12 @@
                     if ( patientDataValue != null )
                     {
                         String dbValue = patientDataValue.getValue();
-                        Object compareValue = getObject( leftSide.getDataElement().getType(), dbValue );
+                        Object compareValue = patientService.getObjectValue( leftSide.getDataElement().getType(), dbValue );
 
                         i = ((Comparable<Object>) compareValue).compareTo( (Comparable<Object>) objectValue );
                     }
                 }
-                
+
                 if ( i != validation.getOperator() && i != 2 )
                 {
                     result.add( validation );
@@ -314,23 +315,4 @@
         return result;
     }
 
-    private Object getObject( String type, String value )
-        throws Exception
-    {
-        if ( type.equals( DataElement.VALUE_TYPE_INT) )
-        {
-            return Integer.valueOf( value );
-        }
-        else if ( type.equals( DataElement.VALUE_TYPE_BOOL) )
-        {
-            return Boolean.valueOf( value );
-        }
-        else if ( type.equals( DataElement.VALUE_TYPE_DATE) )
-        {
-            return format.parseDate( value.trim() );
-        }
-        
-        return value;
-    }
-
 }

=== 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	2011-03-31 05:38:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2011-04-01 03:00:35 +0000
@@ -203,6 +203,7 @@
 			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
 		<property name="validationService"
 			ref="org.hisp.dhis.program.ProgramStageDataElementValidationService" />
+		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 	</bean>
 
 	<!-- Multi DataEntry -->

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddValidationCriteriaAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddValidationCriteriaAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddValidationCriteriaAction.java	2011-04-01 03:00:35 +0000
@@ -33,6 +33,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.validation.ValidationCriteria;
 import org.hisp.dhis.validation.ValidationCriteriaService;
 
@@ -50,6 +51,8 @@
     // -------------------------------------------------------------------------
 
     private ValidationCriteriaService validationCriteriaService;
+    
+    private PatientService patientService;
 
     // -------------------------------------------------------------------------
     // Input
@@ -65,8 +68,6 @@
 
     private String value;
 
-    private I18nFormat format;
-
     // -------------------------------------------------------------------------
     // Setters
     // -------------------------------------------------------------------------
@@ -76,6 +77,11 @@
         this.validationCriteriaService = validationCriteriaService;
     }
 
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
     public void setName( String name )
     {
         this.name = name;
@@ -86,11 +92,6 @@
         this.description = description;
     }
 
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
     public void setProperty( String property )
     {
         this.property = property;
@@ -120,39 +121,11 @@
         criteria.setDescription( description );
         criteria.setProperty( property );
         criteria.setOperator( operator );
-        criteria.setValue( getObject() );
+        criteria.setValue( patientService.getObjectValue( property, value ));
 
         validationCriteriaService.saveValidationCriteria( criteria );
 
         return SUCCESS;
     }
 
-    // -------------------------------------------------------------------------
-    // Supporting method
-    // -------------------------------------------------------------------------
-
-    private Object getObject()
-        throws Exception
-    {
-        Type type = Patient.class.getMethod( "get" + StringUtils.capitalize( property ) ).getReturnType();
-
-        if ( type == Integer.class || type == Integer.TYPE )
-        {
-            return Integer.valueOf( value );
-        }
-        else if ( type.equals( Boolean.class ) || type == Boolean.TYPE )
-        {
-            return Boolean.valueOf( value );
-        }
-        else if ( type.equals( Date.class ) )
-        {
-            return format.parseDate( value.trim() );
-        }
-        else if ( type.equals( Character.class ) || type == Character.TYPE )
-        {
-            return Character.valueOf ( value.charAt( 0 ) );
-        }
-
-        return value;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateValidationCriteriaAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateValidationCriteriaAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateValidationCriteriaAction.java	2011-04-01 03:00:35 +0000
@@ -33,6 +33,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.validation.ValidationCriteria;
 import org.hisp.dhis.validation.ValidationCriteriaService;
 
@@ -51,6 +52,8 @@
 
     private ValidationCriteriaService validationCriteriaService;
 
+    private PatientService patientService;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -67,8 +70,6 @@
 
     private String value;
 
-    private I18nFormat format;
-
     // -------------------------------------------------------------------------
     // Setters
     // -------------------------------------------------------------------------
@@ -78,6 +79,11 @@
         this.validationCriteriaService = validationCriteriaService;
     }
 
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
     public void setName( String name )
     {
         this.name = name;
@@ -98,11 +104,6 @@
         this.property = property;
     }
 
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
     public void setOperator( int operator )
     {
         this.operator = operator;
@@ -127,39 +128,11 @@
         criteria.setDescription( description );
         criteria.setProperty( property );
         criteria.setOperator( operator );
-        criteria.setValue( getObject() );
+        criteria.setValue( patientService.getObjectValue( property, value ) );
 
         validationCriteriaService.updateValidationCriteria( criteria );
 
         return SUCCESS;
     }
 
-    // -------------------------------------------------------------------------
-    // Supporting method
-    // -------------------------------------------------------------------------
-
-    private Object getObject()
-        throws Exception
-    {
-        Type type = Patient.class.getMethod( "get" + StringUtils.capitalize( property ) ).getReturnType();
-
-        if ( type == Integer.class || type == Integer.TYPE )
-        {
-            return Integer.valueOf( value );
-        }
-        else if ( type.equals( Boolean.class ) || type == Boolean.TYPE )
-        {
-            return Boolean.valueOf( value );
-        }
-        else if ( type.equals( Date.class ) )
-        {
-            return format.parseDate( value.trim() );
-        }
-        else if ( type.equals( Character.class ) || type == Character.TYPE )
-        {
-            return Character.valueOf ( value.charAt( 0 ) );
-        }
-
-        return value;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2011-03-31 01:39:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2011-04-01 03:00:35 +0000
@@ -1131,6 +1131,7 @@
 		<property name="validationCriteriaService">
 			<ref bean="org.hisp.dhis.validation.ValidationCriteriaService" />
 		</property>
+		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 	</bean>
 
 	<bean
@@ -1191,6 +1192,7 @@
 		<property name="validationCriteriaService">
 			<ref bean="org.hisp.dhis.validation.ValidationCriteriaService" />
 		</property>
+		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 	</bean>
 
 	<bean