← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8535: Improve Aggregate QueryBuilder (WIP).

 

------------------------------------------------------------
revno: 8535
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-16 11:05:28 +0700
message:
  Improve Aggregate QueryBuilder (WIP).
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReport.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/TabularReportColumn.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.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-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReport.java	2012-06-12 03:38:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReport.java	2012-10-16 04:05:28 +0000
@@ -63,6 +63,8 @@
 
     public static String PREFIX_DATA_ELEMENT = "de";
 
+    public static String PREFIX_NUMBER_DATA_ELEMENT = "numberDe";
+    
     public static String VALUE_TYPE_OPTION_SET = "optionSet";
 
     

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/TabularReportColumn.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/TabularReportColumn.java	2012-06-24 14:29:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/TabularReportColumn.java	2012-10-16 04:05:28 +0000
@@ -7,6 +7,7 @@
     public static String PREFIX_FIXED_ATTRIBUTE = "fixedAttr";    
     public static String PREFIX_PATIENT_ATTRIBUTE = "attr";
     public static String PREFIX_DATA_ELEMENT = "de";
+    public static String PREFIX_NUMBER_DATA_ELEMENT = "numberDe";
     
     private String prefix;
     
@@ -71,7 +72,12 @@
     
     public boolean isDataElement()
     {
-        return PREFIX_DATA_ELEMENT.equals( prefix );
+        return PREFIX_DATA_ELEMENT.equals( prefix ) || PREFIX_NUMBER_DATA_ELEMENT.equals( prefix ) ;
+    }
+    
+    public boolean isNumberDataElement()
+    {
+        return PREFIX_NUMBER_DATA_ELEMENT.equals( prefix );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-10-11 06:45:11 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-10-16 04:05:28 +0000
@@ -31,13 +31,13 @@
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.AGGRERATION_SUM;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_ATTRIBUTE;
+import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_PROGRAM_STAGE_PROPERTY;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_PROPERTY;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_PROPERTY;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_DATAELEMENT;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_PROPERTY;
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_PROGRAM_STAGE_PROPERTY;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OPERATOR_AND;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_ID;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT;
@@ -52,6 +52,7 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
@@ -122,9 +123,15 @@
 
     private ProgramStageInstanceService programStageInstanceService;
 
+    private StatementBuilder statementBuilder;
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
+    public void setStatementBuilder( StatementBuilder statementBuilder )
+    {
+        this.statementBuilder = statementBuilder;
+    }
 
     public void setAggregationConditionStore( CaseAggregationConditionStore aggregationConditionStore )
     {
@@ -639,9 +646,17 @@
                     {
                         condition = getConditionForDataElement( programId, programStageId, operator, dataElementId,
                             orgunitId, startDate, endDate );
+                        DataElement dataElement = dataElementService.getDataElement( dataElementId );
                         if ( !expression[i].contains( "+" ) )
                         {
-                            condition += " AND pd.value ";
+                            if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
+                            {
+                                condition += " AND cast( pd.value as " + statementBuilder.getDoubleColumnType() + ") ";
+                            }
+                            else
+                            {
+                                condition += " AND pd.value ";
+                            }
                         }
                         else
                         {
@@ -809,7 +824,8 @@
         {
             sql = "SELECT psi.programstageinstanceid ";
             from = "FROM programstageinstance psi inner join programinstance pi "
-                + "on psi.programinstanceid=pi.programinstanceid " + "inner join patient p on p.patientid=pi.patientid ";
+                + "on psi.programinstanceid=pi.programinstanceid "
+                + "inner join patient p on p.patientid=pi.patientid ";
             where = "WHERE p.organisationunitid=" + orgunitId + "  AND p.registrationdate>= '" + startDate + "' "
                 + "AND p.registrationdate <= '" + endDate + "'";
         }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-09-18 08:31:07 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-10-16 04:05:28 +0000
@@ -385,6 +385,18 @@
                     operator = "and ";
                 }
             }
+            if ( column.isNumberDataElement() )
+            {
+                sql += "(select cast( value as "
+                    + statementBuilder.getDoubleColumnType()
+                    + " ) from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
+                    + column.getIdentifier() + ") as element_" + column.getIdentifier() + ",";
+                if ( column.hasQuery() )
+                {
+                    where += operator + "element_" + column.getIdentifier() + " " + column.getQuery() + " ";
+                    operator = "and ";
+                }
+            }
             else if ( column.isDataElement() )
             {
                 sql += "(select value from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
@@ -431,13 +443,11 @@
 
         sql += "psi.executiondate ";
         sql += descOrder ? "desc " : "";
-        sql += (min != null && max != null) ? statementBuilder.limitRecord( min, max ) : "";
         sql += ") as tabular ";// TODO page size
-
         sql += where; // filters
-
         sql = sql.substring( 0, sql.length() - 1 ) + " "; // Remove last comma
-
+        sql += (min != null && max != null) ? statementBuilder.limitRecord( min, max ) : "";
+        
         return sql;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-10-11 02:33:30 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-10-16 04:05:28 +0000
@@ -166,6 +166,7 @@
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="programStageInstanceService"
 			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+		<property name="statementBuilder" ref="statementBuilder" />
 	</bean>
 
 	<bean id="org.hisp.dhis.relationship.RelationshipService" class="org.hisp.dhis.relationship.DefaultRelationshipService">

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2012-10-07 04:42:04 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2012-10-16 04:05:28 +0000
@@ -433,6 +433,10 @@
                 {
                     int objectId = Integer.parseInt( values[1] );
                     DataElement dataElement = dataElementService.getDataElement( objectId );
+                    if(dataElement.getType().equals( DataElement.VALUE_TYPE_INT ))
+                    {
+                        column.setPrefix( PREFIX_NUMBER_DATA_ELEMENT );
+                    }
                     dataElements.add( dataElement );
 
                     String valueType = dataElement.getOptionSet() != null ? VALUE_TYPE_OPTION_SET : dataElement