← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15675: Apply web-api in searching TEI by a certain attribute value without a specifying attributeId.

 

------------------------------------------------------------
revno: 15675
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-06-14 11:35:05 +0800
message:
  Apply web-api in searching TEI by a certain attribute value without a specifying attributeId.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js


--
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	2014-05-08 17:33:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2014-06-14 03:35:05 +0000
@@ -40,6 +40,8 @@
  */
 public class QueryItem
 {
+    public static final String ALL = "ALL";
+    
     private IdentifiableObject item;
 
     private List<QueryFilter> filters = new ArrayList<QueryFilter>();
@@ -72,6 +74,17 @@
         }
     }
     
+    public QueryItem( IdentifiableObject item, QueryOperator operator, String filter )
+    {
+        this.item = item;
+        this.numeric = false;
+        
+        if ( operator != null && filter != null )
+        {
+            this.filters.add( new QueryFilter( operator, filter ) );
+        }
+    }
+    
     public QueryItem( IdentifiableObject item, List<QueryFilter> filters, boolean numeric )
     {
         this.item = item;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java	2014-05-08 17:33:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java	2014-06-14 03:35:05 +0000
@@ -297,7 +297,6 @@
     {
         Set<QueryItem> items = new HashSet<QueryItem>();
         List<QueryItem> duplicates = new ArrayList<QueryItem>();
-        
         for ( QueryItem item : getAttributes() )
         {
             if ( !items.add( item ) )

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-06-12 18:38:24 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-06-14 03:35:05 +0000
@@ -451,8 +451,8 @@
     private QueryItem getItem( String item, String operator, String filter )
     {
         TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute( item );
-
-        if ( at == null )
+        
+        if (  !item.equals( QueryItem.ALL ) && at == null )
         {
             throw new IllegalQueryException( "Attribute does not exist: " + item );
         }
@@ -461,7 +461,16 @@
         {
             QueryOperator op = QueryOperator.fromString( operator );
             
-            return new QueryItem( at, op, filter, at.isNumericType() );
+            if( at==null )
+            {
+                at = new TrackedEntityAttribute();
+                at.setUid( item );
+                return new QueryItem( at, op, filter );
+            }
+            else 
+            {
+                return new QueryItem( at, op, filter, at.isNumericType() );
+            }
         }
         else
         {

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-06-12 16:30:25 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-06-14 03:35:05 +0000
@@ -227,8 +227,12 @@
             final String joinClause = item.hasFilter() ? "inner join" : "left join";
 
             sql += joinClause + " " + 
-                "trackedentityattributevalue as " + col + " " + "on " + col + ".trackedentityinstanceid = tei.trackedentityinstanceid " + 
-                "and " + col + ".trackedentityattributeid = " + item.getItem().getId() + " ";
+                "trackedentityattributevalue as " + col + " " + "on " + col + ".trackedentityinstanceid = tei.trackedentityinstanceid ";
+
+            if( !item.getItemId().equals( QueryItem.ALL ) )
+            {
+                sql += "and " + col + ".trackedentityattributeid = " + item.getItem().getId() + " ";
+            }
 
             if ( !params.isOrQuery() && item.hasFilter() )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js	2014-06-12 06:06:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js	2014-06-14 03:35:05 +0000
@@ -616,19 +616,30 @@
 	if( getFieldValue('searchPatientByAttributes')==''){
 		return;
 	}
-	
-	jQuery('#listEntityInstanceDiv').load(
-		'searchTrackedEntityInstance.action', {
-			orgunitId: getFieldValue('orgunitId'),
-			attributeValue: getFieldValue('searchPatientByAttributes'),
-			programId: getFieldValue('program')
-		}, function() {
-			setInnerHTML('orgunitInfor', getFieldValue('orgunitName'));
-			if( getFieldValue('program')!= ''){
-				var programName = jQuery('#programIdAddTrackedEntity option:selected').text();
-				setInnerHTML('enrollmentInfor', i18n_enrollments_in + " " + programName + " " + i18n_program);
-			}
+	var params = "ou=" + getFieldValue("orgunitId");
+	params += "&page=1";
+	if (getFieldValue('program') != '') {
+		params += "&program=" + getFieldValue('program');
+		if( getFieldValue('programStatus')!=""){
+			params += "&programStatus=" + getFieldValue('programStatus');
+		}
+	}
+	
+	params += "&filter=ALL:LIKE:" + getFieldValue('searchPatientByAttributes');
+	
+	$('#attributeIds option').each(function(i, item) {
+		params += "&attribute=" + item.value;
+	}); 
+	
+	$.ajax({
+		url : '../api/trackedEntityInstances.json',
+		type : "GET",
+		data : params,
+		success : function(json) {
+			setInnerHTML('listEntityInstanceDiv', displayTEIList(json, 1));
 			showById('listEntityInstanceDiv');
 			jQuery('#loaderDiv').hide();
-		});
+			setTableStyles();
+		}
+	});
 }