← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7800: Don't search patient with many condition in Nested function.

 

------------------------------------------------------------
revno: 7800
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-08-01 15:49:36 +0700
message:
  Don't search patient with many condition in Nested function.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.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/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2012-07-26 08:53:44 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2012-08-01 08:49:36 +0000
@@ -317,7 +317,7 @@
             }
             else if ( keys[0].equals( Patient.PREFIX_IDENTIFIER_TYPE ) )
             {
-                patientWhere = operator + "( ( lower( " + statementBuilder.getPatientFullName() + " ) like '%" + id
+                patientWhere = patientOperator + "( ( lower( " + statementBuilder.getPatientFullName() + " ) like '%" + id
                     + "%' ) or lower(pi.identifier)='" + id + "') ";
                 patientOperator = " and ";
                 hasIdentifier = true;
@@ -338,20 +338,21 @@
             }
         }
 
+        if ( orgunit != null )
+        {
+            sql += "(select organisationunitid from patient where patientid=p.patientid and organisationunitid = " + orgunit.getId() + " ) as orgunitid,";
+            otherWhere += operator + "orgunitid=" + orgunit.getId();
+        }
+        
         sql = sql.substring( 0, sql.length() - 1 ) + " "; // Removing last comma
-
+        
         sql += " from patient p ";
         if ( hasIdentifier )
         {
             sql += " left join patientidentifier pi on p.patientid=pi.patientid ";
         }
 
-        if ( orgunit != null )
-        {
-            patientWhere += " and p.organisationunitid = " + orgunit.getId();
-        }
-
-        sql += patientWhere + " order by p.patientid desc ";
+        sql += patientWhere ;
         sql += " ) as searchresult";
         sql += otherWhere;