← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13433: Fixed bug - the result from query build fomulas of anonymous program is wrong.

 

------------------------------------------------------------
revno: 13433
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-12-26 14:40:42 +0700
message:
  Fixed bug - the result from query build fomulas of anonymous program is wrong.
modified:
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.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-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2013-12-26 03:01:38 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java	2013-12-26 07:40:42 +0000
@@ -300,19 +300,23 @@
 
                 sql += "FROM ";
                 boolean hasDataelement = hasDataelementCriteria( caseExpression );
-
-                if ( hasDataelement )
+                boolean hasPatient = hasPatientCriteria( caseExpression );
+                if ( hasPatient && hasDataelement )
                 {
                     sql += " programinstance as pi ";
                     sql += " INNER JOIN patient p on p.patientid=pi.patientid ";
                     sql += " INNER JOIN programstageinstance psi ON pi.programinstanceid=psi.programinstanceid ";
                     sql += " INNER JOIN organisationunit ou ON ou.organisationunitid=psi.organisationunitid ";
                 }
-                else
+                else if ( hasPatient )
                 {
                     sql += " programinstance as pi INNER JOIN patient p on p.patientid=pi.patientid ";
                     sql += " INNER JOIN organisationunit ou ON ou.organisationunitid=p.organisationunitid ";
                 }
+                else
+                {
+                    sql += " programstageinstance psi INNER JOIN organisationunit ou ON ou.organisationunitid=psi.organisationunitid ";
+                }
 
                 sql += " WHERE "
                     + createSQL( caseExpression, operator, orgunitIds,
@@ -347,7 +351,7 @@
         }
 
         sql = sql.replaceAll( "COMBINE", "" );
-
+        System.out.println( "\n\n === \n " + sql );
         return sql;
     }
 
@@ -848,7 +852,9 @@
      */
     private Collection<Integer> getServiceOrgunit()
     {
-        String sql = "select distinct organisationunitid from patient";
+        String sql = "(select distinct organisationunitid from patient)";
+        sql += " UNION ";
+        sql += "(select distinct organisationunitid from programstageinstance where organisationunitid is not null)";
 
         Collection<Integer> orgunitIds = new HashSet<Integer>();
         orgunitIds = jdbcTemplate.query( sql, new RowMapper<Integer>()