← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6978: (patient) Error generating talubar report if orgunit doesnnot have any children.

 

------------------------------------------------------------
revno: 6978
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-05-17 22:09:51 +0700
message:
  (patient) Error generating talubar report if orgunit doesnnot have any children.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.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-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-05-15 02:36:43 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-05-17 15:09:51 +0000
@@ -193,15 +193,29 @@
         Collection<Integer> bottomOrgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc,
         boolean orderByExecutionDateByAsc, int min, int max )
     {
-        String sql = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes, searchingAttrKeys,
-            searchingDEKeys, upperOrgunitIds, startDate, endDate, orderByOrgunitAsc, orderByExecutionDateByAsc );
-
-        if ( bottomOrgunitIds.size() > 0 )
-        {
-            String sqlBottom = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes,
+        String sql = "";
+        if ( upperOrgunitIds != null && upperOrgunitIds.size() > 0 )
+        {
+            sql = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes, searchingAttrKeys,
+                searchingDEKeys, upperOrgunitIds, startDate, endDate, orderByOrgunitAsc, orderByExecutionDateByAsc );
+        }
+
+        String sqlBottom = "";
+
+        if ( bottomOrgunitIds != null && bottomOrgunitIds.size() > 0 )
+        {
+            sqlBottom = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes,
                 searchingAttrKeys, searchingDEKeys, bottomOrgunitIds, startDate, endDate, orderByOrgunitAsc,
                 orderByExecutionDateByAsc );
-            sql = "( " + sqlBottom + ") union all ( " + sql + " ) ";
+
+            if ( sql.isEmpty() )
+            {
+                sql = sqlBottom;
+            }
+            else
+            {
+                sql = "( " + sqlBottom + ") union all ( " + sql + " ) ";
+            }
         }
 
         sql += statementBuilder.limitRecord( min, max );
@@ -222,15 +236,28 @@
         Collection<Integer> bottomOrgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc,
         boolean orderByExecutionDateByAsc )
     {
-        String sql = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes, searchingAttrKeys,
-            searchingDEKeys, upperOrgunitIds, startDate, endDate, orderByOrgunitAsc, orderByExecutionDateByAsc );
+        String sql = "";
+        
+        if ( upperOrgunitIds != null && upperOrgunitIds.size() > 0 )
+        {
+            getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes, searchingAttrKeys,
+                searchingDEKeys, upperOrgunitIds, startDate, endDate, orderByOrgunitAsc, orderByExecutionDateByAsc );
+        }
+        String sqlBottom = "";
 
         if ( bottomOrgunitIds.size() > 0 )
         {
-            String sqlBottom = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes,
+            sqlBottom = getTabularReportStatement( 1, programStage, searchingIdenKeys, fixedAttributes,
                 searchingAttrKeys, searchingDEKeys, bottomOrgunitIds, startDate, endDate, orderByOrgunitAsc,
                 orderByExecutionDateByAsc );
-            sql = "( " + sqlBottom + ") union all ( " + sql + " ) ";
+            if ( sql.isEmpty() )
+            {
+                sql = sqlBottom;
+            }
+            else
+            {
+                sql = "( " + sqlBottom + ") union all ( " + sql + " ) ";
+            }
         }
 
         List<Integer> ids = executeSQL( sql );
@@ -355,7 +382,7 @@
 
         String sqlDE = " select distinct psi.programstageinstanceid from patientdatavalue pdv "
             + "inner join programstageinstance psi on pdv.programstageinstanceid=psi.programstageinstanceid ";
-        
+
         String condition = " WHERE psi.executiondate >= '" + DateUtils.getMediumDateString( startDate )
             + "' AND psi.executiondate <= '" + DateUtils.getMediumDateString( endDate ) + "' "
             + " AND psi.organisationunitid in " + splitListHelper( orgunitIds ) + " AND psi.programstageid = "