← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3309: Fix bug: Don't search patients by full-name and attribute-value.

 

------------------------------------------------------------
revno: 3309
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-04-07 15:21:36 +0700
message:
  Fix bug: Don't search patients by full-name and attribute-value.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java
  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/hibernate/HibernatePatientStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientsByNameAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/ShowAddRelationshipFormAction.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/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2011-04-06 03:19:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2011-04-07 08:21:36 +0000
@@ -99,14 +99,6 @@
     Collection<Patient> getPatientsByNames( String name );
     
     /**
-     * Search Patient base on firstname/middlename/lastname/
-     * 
-     * @param name firstName/middleName/lastName/
-     * @return Patient List
-     */
-    Collection<Patient> getPatients( String searchText );
-    
-    /**
      * Search Patient base on identifier value with result limited
      * 
      * @param searchText value

=== 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-04-06 03:19:11 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2011-04-07 08:21:36 +0000
@@ -214,28 +214,6 @@
     }
 
     @Override
-    public Collection<Patient> getPatientsByNames( String name )
-    {
-        return patientStore.getByNames( name );
-    }
-
-    @Override
-    public Collection<Patient> getPatients( String searchText )
-    {
-        Set<Patient> patients = new HashSet<Patient>();
-
-        patients.addAll( getPatientsByNames( searchText ) );
-
-        for ( PatientIdentifier patientIdentifier : patientIdentifierService
-            .getPatientIdentifiersByIdentifier( searchText ) )
-        {
-            patients.add( patientIdentifier.getPatient() );
-        }
-
-        return patients;
-    }
-
-    @Override
     public Collection<Patient> getPatients( String searchText, int min, int max )
     {
         int countPatientName = patientStore.countGetPatientsByName( searchText );
@@ -309,7 +287,7 @@
     {
         Collection<Patient> patients = new ArrayList<Patient>();
 
-        Collection<Patient> allPatients = getPatients( searchText );
+        Collection<Patient> allPatients = getPatientsByNames( searchText );
 
         if ( allPatients.retainAll( getPatients( organisationUnit, min, max ) ) )
         {
@@ -356,7 +334,7 @@
     {
         SortedMap<String, Patient> patientsSortedByAttribute = new TreeMap<String, Patient>();
 
-        Collection<Patient> sortedPatients = new ArrayList<Patient>();
+        Set<Patient> sortedPatients = new HashSet<Patient>();
 
         // ---------------------------------------------------------------------
         // Better to fetch all attribute values at once than fetching the
@@ -401,9 +379,15 @@
     }
 
     @Override
+    public Collection<Patient> getPatientsByNames( String name )
+    {
+        return patientStore.getByNames( name.toLowerCase() );
+    }
+    
+    @Override
     public Collection<Patient> getPatientsByNames( String name, int min, int max )
     {
-        return patientStore.getByNames( name, min, max );
+        return patientStore.getByNames( name.toLowerCase(), min, max );
     }
 
     @Override

=== 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	2011-03-31 01:55:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2011-04-07 08:21:36 +0000
@@ -100,8 +100,9 @@
         return getCriteria( Restrictions.eq( "birthDate", birthDate ) ).list();
     }
 
+    @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByNames( String name )
-    {
+    {   
         String sql = statementBuilder.getPatientsByFullName( name );
 
         StatementHolder holder = statementManager.getHolder();
@@ -131,15 +132,38 @@
 
         return patients;
     }
-
+    
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByNames( String name, int min, int max )
-    {
-        return getCriteria(
-            Restrictions.disjunction().add( Restrictions.ilike( "firstName", "%" + name + "%" ) ).add(
-                Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
-                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) )
-            .setFirstResult( min ).setMaxResults( max ).list();
+    {   
+        String sql = statementBuilder.getPatientsByFullName( name, min, max );
+
+        StatementHolder holder = statementManager.getHolder();
+
+        Set<Patient> patients = new HashSet<Patient>();
+
+        try
+        {
+            Statement statement = holder.getStatement();
+
+            ResultSet resultSet = statement.executeQuery( sql );
+
+            while ( resultSet.next() )
+            {
+                Patient p = get( resultSet.getInt( 1 ) );
+                patients.add( p );
+            }
+        }
+        catch ( Exception ex )
+        {
+            ex.printStackTrace();
+        }
+        finally
+        {
+            holder.close();
+        }
+
+        return patients;
     }
 
     @SuppressWarnings( "unchecked" )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2011-03-31 01:55:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2011-04-07 08:21:36 +0000
@@ -131,13 +131,11 @@
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> searchPatients( PatientAttribute patientAttribute, String searchText, int min, int max )
     {
-        String hql = "select pav.patient from PatientAttributeValue pav where pav.patientAttribute = :patientAttribute and pav.value like '%"
-            + searchText + "%'";
-
-        Query query = getQuery( hql );
-        query.setEntity( "patientAttribute", patientAttribute );
-
-        return query.setFirstResult( min ).setMaxResults( max ).list();
+        return getCriteria( Restrictions.eq( "patientAttribute", patientAttribute ),
+            Restrictions.ilike( "value", "%" + searchText + "%" ) )
+            .setProjection(Projections.distinct(Projections.property( "patient") ))
+            .setFirstResult( min ).setMaxResults( max ).list();
+
     }
 
     @SuppressWarnings( "unchecked" )

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java	2011-03-12 10:25:49 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java	2011-04-07 08:21:36 +0000
@@ -141,6 +141,8 @@
     
     String getPatientsByFullName( String fullName );
     
+    String getPatientsByFullName( String fullName, int min, int max );
+    
     String countPatientsByFullName( String fullName );
 
     String queryDataElementStructureForOrgUnit();

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2011-03-12 10:25:49 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2011-04-07 08:21:36 +0000
@@ -345,6 +345,14 @@
                "like lower('%" + fullName + "%') ";
    }
    
+   public String getPatientsByFullName( String fullName, int min, int max )
+   {
+       return "SELECT patientid FROM patient " +
+               "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
+               "like lower('%" + fullName + "%') " +
+               "limit " + max + " OFFSET " + min;
+   }
+   
    public String countPatientsByFullName( String fullName )
    {
        return "SELECT count(patientid) FROM patient " +

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2011-03-12 10:25:49 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2011-04-07 08:21:36 +0000
@@ -345,12 +345,19 @@
     
     public String getPatientsByFullName( String fullName )
     {
-        return "SELECT patientid, birthdate, deathdate, registrationdate, isdead, bloodgroup, " +
-                "gender, dobType, firstname, middlename, lastname FROM patient " +
+        return "SELECT patientid FROM patient " +
                 "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
                 "like lower('%" + fullName + "%') ";
     }
     
+    public String getPatientsByFullName( String fullName, int min, int max )
+    {
+        return "SELECT patientid FROM patient " +
+                "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
+                "like lower('%" + fullName + "%') " +
+                "limit " + max + " OFFSET " + min;
+    }
+    
     public String countPatientsByFullName( String fullName )
     {
         return "SELECT count(patientid) FROM patient " +

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2011-03-12 10:25:49 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2011-04-07 08:21:36 +0000
@@ -337,12 +337,20 @@
                "AND d.categoryoptioncomboid=a.categoryoptioncomboid " +
                "AND a.timestamp<=d.timestamp;";
    }
-   
+
    public String getPatientsByFullName( String fullName )
    {
        return "SELECT patientid FROM patient " +
                "where lower(concat( firstname, \" \",middleName , \" \" , lastname) ) " +
-               "like lower('%" + fullName + "%')";
+               "like lower('%" + fullName + "%') ";
+   }
+   
+   public String getPatientsByFullName( String fullName, int min, int max )
+   {
+       return "SELECT patientid FROM patient " +
+               "where lower(concat( firstname, \" \",middleName , \" \" , lastname) ) " +
+               "like lower('%" + fullName + "%') " +
+               "limit " + min + " ," + max;
    }
    
    public String countPatientsByFullName( String fullName )

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2011-03-12 10:25:49 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2011-04-07 08:21:36 +0000
@@ -342,14 +342,22 @@
     {
         return "SELECT patientid FROM patient " +
                 "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
-                "like lower('%" + fullName + "%')";
+                "like lower('%" + fullName + "%') ";
+    }
+    
+    public String getPatientsByFullName( String fullName, int min, int max )
+    {
+        return "SELECT patientid FROM patient " +
+                "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
+                "like lower('%" + fullName + "%') " +
+                "limit " + max + " OFFSET " + min;
     }
     
     public String countPatientsByFullName( String fullName )
     {
         return "SELECT count(patientid) FROM patient " +
-        "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
-        "like lower('%" + fullName + "%')";
+               "where lower( firstname || ' ' || middleName || ' ' || lastname) " +
+               "like lower('%" + fullName + "%') ";
     }
 
     public String queryDataElementStructureForOrgUnit()

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientsByNameAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/GetPatientsByNameAction.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/patient/GetPatientsByNameAction.java	2011-04-07 08:21:36 +0000
@@ -104,7 +104,7 @@
             }
         }
 
-        patients = new ArrayList<Patient>( patientService.getPatients( firstName + " " + middleName + " " + lastName ) );
+        patients = new ArrayList<Patient>( patientService.getPatientsByNames( firstName + " " + middleName + " " + lastName ) );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/ShowAddRelationshipFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/relationship/ShowAddRelationshipFormAction.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/relationship/ShowAddRelationshipFormAction.java	2011-04-07 08:21:36 +0000
@@ -222,7 +222,7 @@
 
             if ( searchText.length() > 0 )
             {
-                patients = patientService.getPatients( searchText );
+                patients = patientService.getPatientsByNames( searchText );
 
                 patients.remove( patient );