← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13167: Moved TrackedEntityQueryParams to api

 

------------------------------------------------------------
revno: 13167
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-12-06 17:26:51 +0100
message:
  Moved TrackedEntityQueryParams to api
renamed:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/TrackedEntityQueryParams.java => dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/TrackedEntityQueryParams.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.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/test/java/org/hisp/dhis/patient/PatientStoreTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.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/common/QueryItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2013-12-06 15:47:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2013-12-06 16:26:51 +0000
@@ -121,6 +121,11 @@
         return "'" + encodedFilter + "'";
     }
     
+    public String getItemId()
+    {
+        return item.getUid();
+    }
+    
     @Override
     public String toString()
     {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-11-05 08:07:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-12-06 16:26:51 +0000
@@ -109,6 +109,8 @@
     Collection<Patient> getByOrgUnitProgram( OrganisationUnit organisationUnit, Program program, Integer min,
         Integer max );
 
+    List<Patient> query( TrackedEntityQueryParams params );
+    
     /**
      * Search patient who has the same representative
      * 

=== renamed file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/TrackedEntityQueryParams.java' => 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/TrackedEntityQueryParams.java'
=== 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	2013-12-06 13:29:05 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-12-06 16:26:51 +0000
@@ -191,18 +191,22 @@
     {
         SqlHelper hlp = new SqlHelper();
         
-        String hql = 
-            "select pt from Patient pt " +
-            "inner join PatientAttributeValue av " +
-            "inner join PatientAttribute at ";
+        String hql = "select pt from Patient pt left join pt.attributeValues av";
         
         for ( QueryItem at : params.getAttributes() )
         {
-            hlp.whereAnd();
+            hql += " " + hlp.whereAnd();
+            hql += " (av.patientAttribute = :attr" + at.getItemId() + " and av.value = :filt" + at.getItemId() + ")";
         }
         
         Query query = getQuery( hql );
         
+        for ( QueryItem at : params.getAttributes() )
+        {
+            query.setEntity( "attr" + at.getItemId(), at.getItem() );
+            query.setString( "filt" + at.getItemId(), at.getFilter() );
+        }
+        
         return query.list();
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java	2013-11-28 06:19:32 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java	2013-12-06 16:26:51 +0000
@@ -373,4 +373,20 @@
         assertEquals( 0, validatePatientA1 );
         assertEquals( 2, validatePatientB1 );
     }
+    
+    @Test
+    public void testQuery()
+    {
+        patientStore.save( patientA1 );
+        patientStore.save( patientA2 );
+        patientStore.save( patientA3 );
+        patientStore.save( patientB1 );
+        patientStore.save( patientB2 );
+        
+        TrackedEntityQueryParams params = new TrackedEntityQueryParams();
+        
+        List<Patient> list = patientStore.query( params );
+        
+        assertEquals( 5, list.size() );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java	2013-11-29 09:24:58 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patientdatavalue/PatientDataValueServiceTest.java	2013-12-06 16:26:51 +0000
@@ -157,9 +157,6 @@
         stageInstanceA = programStageInstanceService.getProgramStageInstance( programInstance, stageA );
         stageInstanceB = programStageInstanceService.getProgramStageInstance( programInstance, stageB );
 
-        System.out.println( "\n\n\n ===== \n 1 stageInstanceA : " + stageInstanceA );
-        System.out.println( "\n 2 stageInstanceB : " + stageInstanceB );
-        
         dataValueA = new PatientDataValue( stageInstanceA, dataElementA, "A" );
         dataValueB = new PatientDataValue( stageInstanceA, dataElementB, "B" );
         dataValueC = new PatientDataValue( stageInstanceB, dataElementA, "C" );