← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15197: Apply web-api for searching representative functionality

 

------------------------------------------------------------
revno: 15197
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-05-08 21:39:17 +0800
message:
  Apply web-api for searching representative functionality
removed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.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/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm


--
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/trackedentity/TrackedEntityInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-05-07 09:33:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-05-08 13:39:17 +0000
@@ -197,15 +197,6 @@
     //Collection<TrackedEntityInstance> getTrackedEntityInstances( OrganisationUnit organisationUnit, Program program );
 
     /**
-     * Retrieve entityInstances base on Attribute
-     * 
-     * @param attributeId
-     * @param value
-     * @return
-     */
-    Collection<TrackedEntityInstance> getTrackedEntityInstance( Integer attributeId, String value );
-
-    /**
      * Search entityInstances base on OrganisationUnit and Program with result
      * limited name
      * 
@@ -240,13 +231,13 @@
      * Register a new entityInstance
      * 
      * @param entityInstance TrackedEntityInstance
-     * @param representativeId The id of entityInstance who is representative
+     * @param representativeId The uid of entityInstance who is representative
      * @param relationshipTypeId The id of relationship type defined
      * @param attributeValues Set of attribute values
      * 
      * @return The error code after registering entityInstance
      */
-    int createTrackedEntityInstance( TrackedEntityInstance entityInstance, Integer representativeId,
+    int createTrackedEntityInstance( TrackedEntityInstance entityInstance, String representativeId,
         Integer relationshipTypeId, Set<TrackedEntityAttributeValue> attributeValues );
 
     /**
@@ -260,7 +251,7 @@
      * @param valuesForDelete The entityInstance attribute values for deleting
      * 
      */
-    void updateTrackedEntityInstance( TrackedEntityInstance entityInstance, Integer representativeId,
+    void updateTrackedEntityInstance( TrackedEntityInstance entityInstance, String representativeId,
         Integer relationshipTypeId, List<TrackedEntityAttributeValue> valuesForSave,
         List<TrackedEntityAttributeValue> valuesForUpdate, Collection<TrackedEntityAttributeValue> valuesForDelete );
 

=== 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-05-07 09:33:33 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-05-08 13:39:17 +0000
@@ -456,7 +456,7 @@
     }
 
     @Override
-    public int createTrackedEntityInstance( TrackedEntityInstance instance, Integer representativeId,
+    public int createTrackedEntityInstance( TrackedEntityInstance instance, String representativeId,
         Integer relationshipTypeId, Set<TrackedEntityAttributeValue> attributeValues )
     {
         int id = addTrackedEntityInstance( instance );
@@ -473,7 +473,7 @@
 
         if ( representativeId != null )
         {
-            TrackedEntityInstance representative = trackedEntityInstanceStore.get( representativeId );
+            TrackedEntityInstance representative = trackedEntityInstanceStore.getByUid( representativeId );
             if ( representative != null )
             {
                 instance.setRepresentative( representative );
@@ -556,19 +556,7 @@
     }
 
     @Override
-    public Collection<TrackedEntityInstance> getTrackedEntityInstance( Integer attributeId, String value )
-    {
-        TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( attributeId );
-        if ( attribute != null )
-        {
-            return attributeValueService.getTrackedEntityInstance( attribute, value );
-        }
-
-        return null;
-    }
-
-    @Override
-    public void updateTrackedEntityInstance( TrackedEntityInstance instance, Integer representativeId,
+    public void updateTrackedEntityInstance( TrackedEntityInstance instance, String representativeId,
         Integer relationshipTypeId, List<TrackedEntityAttributeValue> valuesForSave,
         List<TrackedEntityAttributeValue> valuesForUpdate, Collection<TrackedEntityAttributeValue> valuesForDelete )
     {
@@ -591,7 +579,7 @@
 
         if ( shouldSaveRepresentativeInformation( instance, representativeId ) )
         {
-            TrackedEntityInstance representative = trackedEntityInstanceStore.get( representativeId );
+            TrackedEntityInstance representative = trackedEntityInstanceStore.getByUid( representativeId );
 
             if ( representative != null )
             {
@@ -614,14 +602,14 @@
         }
     }
 
-    private boolean shouldSaveRepresentativeInformation( TrackedEntityInstance instance, Integer representativeId )
+    private boolean shouldSaveRepresentativeInformation( TrackedEntityInstance instance, String representativeId )
     {
-        if ( representativeId == null )
+        if ( representativeId == null || representativeId.isEmpty() )
         {
             return false;
         }
 
-        return instance.getRepresentative() == null || !(instance.getRepresentative().getId() == representativeId);
+        return instance.getRepresentative() == null || !(instance.getRepresentative().getUid() == representativeId);
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java	2014-05-07 09:33:33 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java	2014-05-08 13:39:17 +0000
@@ -99,8 +99,6 @@
 
     private TrackedEntityAttribute entityInstanceAttribute;
 
-    private int attributeId;
-
     private Program programA;
 
     private Program programB;
@@ -119,12 +117,13 @@
         organisationUnitService.addOrganisationUnit( organisationUnitB );
 
         entityInstanceAttribute = createTrackedEntityAttribute( 'A' );
-        attributeId = attributeService.addTrackedEntityAttribute( entityInstanceAttribute );
+        attributeService.addTrackedEntityAttribute( entityInstanceAttribute );
 
         entityInstanceA1 = createTrackedEntityInstance( 'A', organisationUnit );
         entityInstanceA2 = createTrackedEntityInstance( 'A', organisationUnitB );
         entityInstanceA3 = createTrackedEntityInstance( 'A', organisationUnit, entityInstanceAttribute );
         entityInstanceB1 = createTrackedEntityInstance( 'B', organisationUnit );
+        entityInstanceB1.setUid( "UID-B1" );
         entityInstanceB2 = createTrackedEntityInstance( 'B', organisationUnit, entityInstanceAttribute );
 
         programA = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
@@ -204,38 +203,14 @@
         entityInstanceService.addTrackedEntityInstance( entityInstanceA2 );
         entityInstanceService.addTrackedEntityInstance( entityInstanceA3 );
 
-        Collection<TrackedEntityInstance> entityInstances = entityInstanceService.getTrackedEntityInstances( organisationUnit, null, null );
+        Collection<TrackedEntityInstance> entityInstances = entityInstanceService.getTrackedEntityInstances(
+            organisationUnit, null, null );
         assertEquals( 2, entityInstances.size() );
         assertTrue( entityInstances.contains( entityInstanceA1 ) );
         assertTrue( entityInstances.contains( entityInstanceA3 ) );
     }
 
     @Test
-    public void testGetTrackedEntityInstancesByAttribute()
-    {
-        entityInstanceService.addTrackedEntityInstance( entityInstanceA2 );
-        entityInstanceService.addTrackedEntityInstance( entityInstanceA3 );
-        entityInstanceService.addTrackedEntityInstance( entityInstanceB1 );
-        entityInstanceService.addTrackedEntityInstance( entityInstanceB2 );
-
-        TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue( 'A', entityInstanceA3,
-            entityInstanceAttribute );
-        Set<TrackedEntityAttributeValue> entityInstanceAttributeValues = new HashSet<TrackedEntityAttributeValue>();
-        entityInstanceAttributeValues.add( attributeValue );
-
-        entityInstanceService.createTrackedEntityInstance( entityInstanceA3, null, null, entityInstanceAttributeValues );
-
-        Collection<TrackedEntityInstance> entityInstances = entityInstanceService.getTrackedEntityInstance( attributeId, "AttributeA" );
-
-        assertEquals( 1, entityInstances.size() );
-        assertTrue( entityInstances.contains( entityInstanceA3 ) );
-
-        TrackedEntityInstance entityInstance = entityInstances.iterator().next();
-        assertEquals( 1, entityInstance.getAttributeValues().size() );
-        assertTrue( entityInstance.getAttributeValues().contains( attributeValue ) );
-    }
-
-    @Test
     public void testGetTrackedEntityInstancesByProgramOu()
     {
         programService.addProgram( programA );
@@ -251,8 +226,8 @@
         programInstanceService.enrollTrackedEntityInstance( entityInstanceA2, programA, date, date, organisationUnit );
         programInstanceService.enrollTrackedEntityInstance( entityInstanceB2, programB, date, date, organisationUnit );
 
-        Collection<TrackedEntityInstance> entityInstances = entityInstanceService.getTrackedEntityInstances( organisationUnit, programA, 0,
-            100 );
+        Collection<TrackedEntityInstance> entityInstances = entityInstanceService.getTrackedEntityInstances(
+            organisationUnit, programA, 0, 100 );
 
         assertEquals( 2, entityInstances.size() );
         assertTrue( entityInstances.contains( entityInstanceA1 ) );
@@ -281,7 +256,7 @@
     @Test
     public void testCreateTrackedEntityInstanceAndRelative()
     {
-        int idB = entityInstanceService.addTrackedEntityInstance( entityInstanceB1 );
+        entityInstanceService.addTrackedEntityInstance( entityInstanceB1 );
 
         RelationshipType relationshipType = createRelationshipType( 'A' );
         int relationshipTypeId = relationshipTypeService.addRelationshipType( relationshipType );
@@ -291,14 +266,15 @@
         Set<TrackedEntityAttributeValue> entityInstanceAttributeValues = new HashSet<TrackedEntityAttributeValue>();
         entityInstanceAttributeValues.add( attributeValue );
 
-        int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA1, idB, relationshipTypeId, entityInstanceAttributeValues );
+        int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA1, entityInstanceB1.getUid(),
+            relationshipTypeId, entityInstanceAttributeValues );
         assertNotNull( entityInstanceService.getTrackedEntityInstance( idA ) );
     }
 
     @Test
     public void testUpdateTrackedEntityInstanceAndRelative()
     {
-        int idB = entityInstanceService.addTrackedEntityInstance( entityInstanceB1 );
+        entityInstanceService.addTrackedEntityInstance( entityInstanceB1 );
 
         RelationshipType relationshipType = createRelationshipType( 'A' );
         int relationshipTypeId = relationshipTypeService.addRelationshipType( relationshipType );
@@ -308,15 +284,17 @@
             entityInstanceAttribute );
         Set<TrackedEntityAttributeValue> entityInstanceAttributeValues = new HashSet<TrackedEntityAttributeValue>();
         entityInstanceAttributeValues.add( attributeValue );
-        int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA3, idB, relationshipTypeId, entityInstanceAttributeValues );
+        int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA3, entityInstanceB1.getUid(),
+            relationshipTypeId, entityInstanceAttributeValues );
         assertNotNull( entityInstanceService.getTrackedEntityInstance( idA ) );
 
         attributeValue.setValue( "AttributeB" );
         List<TrackedEntityAttributeValue> attributeValues = new ArrayList<TrackedEntityAttributeValue>();
         attributeValues.add( attributeValue );
 
-        entityInstanceService.updateTrackedEntityInstance( entityInstanceA3, idB, relationshipTypeId, attributeValues,
-            new ArrayList<TrackedEntityAttributeValue>(), new ArrayList<TrackedEntityAttributeValue>() );
+        entityInstanceService.updateTrackedEntityInstance( entityInstanceA3, entityInstanceB1.getUid(),
+            relationshipTypeId, attributeValues, new ArrayList<TrackedEntityAttributeValue>(),
+            new ArrayList<TrackedEntityAttributeValue>() );
         assertEquals( "B", entityInstanceService.getTrackedEntityInstance( idA ).getName() );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java	2014-04-12 12:12:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java	2014-05-08 13:39:17 +0000
@@ -92,7 +92,7 @@
     // Input
     // -------------------------------------------------------------------------
 
-    private Integer representativeId;
+    private String representativeId;
 
     private Integer relationshipTypeId;
 
@@ -269,7 +269,7 @@
         this.attributeService = attributeService;
     }
 
-    public void setRepresentativeId( Integer representativeId )
+    public void setRepresentativeId( String representativeId )
     {
         this.representativeId = representativeId;
     }

=== removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java	1970-01-01 00:00:00 +0000
@@ -1,135 +0,0 @@
-package org.hisp.dhis.caseentry.action.trackedentity;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.hisp.dhis.trackedentity.TrackedEntityInstance;
-import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
-import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
-import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Viet
- * @version $Id$
- */
-
-public class SearchPersonAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private TrackedEntityInstanceService entityInstanceService;
-
-    private TrackedEntityAttributeValueService attributeValueService;
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer attributeId;
-
-    private String searchValue;
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private Map<String, String> attributeValueMap = new HashMap<String, String>();
-
-    private Collection<TrackedEntityInstance> entityInstances;
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        entityInstances = entityInstanceService.getTrackedEntityInstance(  attributeId, searchValue );
-
-        if ( entityInstances != null && entityInstances.size() > 0 )
-        {
-            for ( TrackedEntityInstance p : entityInstances )
-            {
-                Collection<TrackedEntityAttributeValue> attributeValues = attributeValueService
-                    .getTrackedEntityAttributeValues( p );
-
-                for ( TrackedEntityAttributeValue attributeValue : attributeValues )
-                {
-                    attributeValueMap.put(
-                        p.getId() + "_" + attributeValue.getAttribute().getId(),
-                        attributeValue.getValue() );
-                }
-            }
-        }
-        
-        return SUCCESS;
-    }
-
-    // -------------------------------------------------------------------------
-    // Getter/Setter
-    // -------------------------------------------------------------------------
-
-    public void setAttributeId( Integer attributeId )
-    {
-        this.attributeId = attributeId;
-    }
-
-    public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
-    {
-        this.entityInstanceService = entityInstanceService;
-    }
-
-    public Collection<TrackedEntityInstance> getEntityInstances()
-    {
-        return entityInstances;
-    }
-
-    public Map<String, String> getAttributeValueMap()
-    {
-        return attributeValueMap;
-    }
-
-    public void setAttributeValueService( TrackedEntityAttributeValueService attributeValueService )
-    {
-        this.attributeValueService = attributeValueService;
-    }
-
-    public void setSearchValue( String searchValue )
-    {
-        this.searchValue = searchValue;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java	2014-04-12 12:12:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java	2014-05-08 13:39:17 +0000
@@ -79,7 +79,7 @@
 
     private Integer id;
 
-    private Integer representativeId;
+    private String representativeId;
 
     private Integer relationshipTypeId;
 
@@ -207,7 +207,7 @@
         return entityInstance;
     }
 
-    public void setRepresentativeId( Integer representativeId )
+    public void setRepresentativeId( String representativeId )
     {
         this.representativeId = representativeId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-05-07 10:09:11 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-05-08 13:39:17 +0000
@@ -364,13 +364,6 @@
 
 	<!-- Tracked Entity Instance -->
 
-	<bean id="org.hisp.dhis.caseentry.action.trackedentity.SearchPersonAction"
-		class="org.hisp.dhis.caseentry.action.trackedentity.SearchPersonAction">
-		<property name="entityInstanceService" ref="org.hisp.dhis.trackedentity.TrackedEntityInstanceService" />
-		<property name="attributeValueService"
-			ref="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService" />
-	</bean>
-
 	<bean id="org.hisp.dhis.caseentry.action.trackedentity.SelectAction"
 		class="org.hisp.dhis.caseentry.action.trackedentity.SelectAction" scope="prototype">
 		<property name="selectionManager"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2014-04-30 12:57:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2014-05-08 13:39:17 +0000
@@ -515,13 +515,6 @@
 			<param name="requiredAuthorities">F_TRACKED_ENTITY_INSTANCE_ADD</param>
 		</action>
 
-		<action name="searchPerson"
-			class="org.hisp.dhis.caseentry.action.trackedentity.SearchPersonAction">
-			<result name="success" type="velocity-xml">responseTrackedEntityInstances.vm
-			</result>
-			<param name="requiredAuthorities">F_TRACKED_ENTITY_INSTANCE_SEARCH</param>
-		</action>
-
 		<action name="addRepresentative"
 			class="org.hisp.dhis.caseentry.action.trackedentity.AddRepresentativeAction">
 			<result name="success" type="velocity-xml">responseRepresentative.vm

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js	2014-02-10 05:42:16 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js	2014-05-08 13:39:17 +0000
@@ -23,7 +23,7 @@
 				,data: jQuery("#addRepresentativeForm").serialize()
 				,dataType : "xml"
 				,success: function(xml){ 
-					autoChoosePerson( xml );
+					autoChooseTEI( xml );
 				}
 				,error: function()
 				{
@@ -49,7 +49,7 @@
 	 else if( type == 'duplicate' )
 	 {
 		 jQuery("#formContainer").hide();
-		 showPersons("listPersonsDuplicate", messageElement);
+		 showTEIs("listPersonsDuplicate", messageElement);
 	 }
 }
 
@@ -68,55 +68,98 @@
 	return params;
 }
 
-function searchPerson()
+function searchTEI()
 {
-	jQuery.ajax({
-		   type: "POST"
-		   ,url: "searchPerson.action"
-		   ,data: jQuery("#searchForm").serialize()
-		   ,dataType : "xml"
-		   ,success: function(xmlObject){
-				showPersons( "searchForm div[id=listPersons]", xmlObject );
-			}
-		   ,error: function(request,status,errorThrown)
-		   {
-				alert(i18n_error_connect_to_server);
-		   }
-		 });
+	contentDiv = 'listEntityInstanceDiv';
+	var params  = "ou=" + getFieldValue("orgunitId");
+		params += "&ouMode=ALL";
+		params += "&attribute=" + getFieldValue("attributeId") + ":LIKE:" + getFieldValue('searchValue');
+	
+	var p = params;
+	$('#attributeIds option').each(function(i, item){
+		if ( p.indexOf(item.value) < 0 ) {
+			params += "&attribute=" + item.value;
+		}
+	});
+	
+	$.ajax({
+		type : "GET",
+		url : "../api/trackedEntityInstances.json",
+		data : params,
+		dataType : "json",
+		success : function(json) {
+			showTEIs( "searchForm div[id=listPersons]", json );
+		}
+	});
 }
 
-function showPersons( divContainer, xmlElement )
+function showTEIs( divContainer, json )
 {
-	var container = jQuery("#"+divContainer);
+	var container = jQuery( "#" + divContainer );
 	container.html("");
-	var entityInstances = $(xmlElement).find('entityInstance');
-	var sEntityInstance = "";
-	
-	if ( entityInstances.length == 0 )
-	{
-		var message = "<p>" + i18n_no_result + "</p>";
+	if ( json.rows.length == 0 ){
+		var message = "<p>" + i18n_no_result_found + "</p>";
 		container.html(message);
 	}
-	
-	$( entityInstances ).each( function( i, entityInstance )
-    {
-		sEntityInstance += "<hr style='margin:5px 0px;'><table>";
-		var attributes = $( entityInstance ).find('attribute');
-		$( attributes ).each( function( i, attribute )
-		{
-				sEntityInstance += "<tr class='attributeRow'>"
-					+ "<td class='bold'>" + $(attribute).find('name').text() + "</td>"
-					+ "<td>" + $(attribute).find('value').text() + "</td>	"	
-					+ "</tr>";
+	else{
+		var attList = new Array();
+		var attDate = new Array();
+		$('#attributeIds option').each(function(i, item) {
+			var valueType = $(item).attr('valueType');
+			var value = $(item).val();
+			if ( valueType == 'bool' || valueType == 'trueOnly' ) {
+				for (var i = idx; i < json.width; i++) {
+					if( value==json.headers[i].name ){
+						attList.push(i);
+					}
+					else if( valueType=='date'){
+						attDate.push(i);
+					}
+				}
+			}
+			else if ( valueType == 'date' ) {
+				for (var i = idx; i < json.width; i++) {
+					if( value==json.headers[i].name ){
+						attDate.push(i);
+					}
+				}
+			}
 		});
-		sEntityInstance += "<tr><td colspan='2'><input type='button' id='" + $(entityInstance).find('id' ).first().text() +"' value='" + i18n_choose_this_tracked_entity_instance + "' onclick='choosePerson(this)'/></td></tr>";
-		sEntityInstance += "</table>";
-		container.append(i18n_duplicate_warning + "<br>" + sEntityInstance);
-	 } );
+		
+		var result = "";
+		var idx = 4;
+		for ( var i in json.rows) {
+			result += "<hr style='margin:5px 0px;'><table>";
+			var cols = json.rows[i];
+			var uid = cols[0];
+			for (var j = idx; j < json.width; j++) {
+				var colVal = cols[j];
+				if( colVal!=''){
+					if (j == 4) {
+						colVal = json.metaData.names[colVal];
+					}
+					
+					if( jQuery.inArray( j, attList )>=0 && colVal!="" ){
+						colVal = (colVal=='true')? i18n_yes : i18n_no;
+					}
+					else if( jQuery.inArray( j, attDate )>=0 && colVal!="" ){
+						colVal = colVal.split(' ')[0];
+					}
+					result += "<tr class='attributeRow'>"
+							+ "<td class='bold'>" + json.headers[j].column + "</td>"
+							+ "<td>" + colVal + "</td>	"	
+							+ "</tr>";
+				}
+			}
+			result += "<tr><td colspan='2'><input type='button' id='" + uid +"' value='" + i18n_choose_this_tracked_entity_instance + "' onclick='chooseTEI(this)'/></td></tr>";
+			result += "</table>";
+		}
+		container.append(i18n_duplicate_warning + "<br>" + result);
+	}		
 }
 
-// Will be call after save new person successfully
-function autoChoosePerson( xmlElement )
+// Will be call after save new TEI successfully
+function autoChooseTEI( xmlElement )
 {
 	jQuery("#tab-2").html("<center><span class='bold'>" + i18n_add_person_successfully + "</span></center>");
 	var root = jQuery(xmlElement);
@@ -135,7 +178,7 @@
 // Set Representative information to parent page.
 //------------------------------------------------------------------------------
 
-function choosePerson(this_)
+function chooseTEI(this_)
 {
 	var relationshipTypeId = jQuery("#searchForm [id=relationshipTypeId]").val();
 	if( isBlank( relationshipTypeId ))

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm	2014-05-08 13:39:17 +0000
@@ -1,14 +1,13 @@
 <script type="text/javascript">
 	jQuery("#representativeDiv").ready(function() {
-		addEventForTrackedEntityInstanceForm('addRepresentativeForm');
-				
+	
 		jQuery("#searchForm").validate({
 			meta:"validate"
 			,errorElement:"span"
-			,submitHandler: function(form) { searchPerson(); }
+			,submitHandler: function(form) { searchTEI(); }
 			,rules : {
 				relationshipTypeId  : { required: true },
-				searchType			: { required: true },
+				attributeId			: { required: true },
 				searchValue			: { required: true }
 			}
 		});
@@ -35,7 +34,7 @@
 
 	<!-- Search Person TAB -->
 	<div id="tab-1">
-		<form id="searchForm" name="searchForm" action="searchPerson.action" method="post" >
+		<form id="searchForm" name="searchForm" method="post" >
 			<table>
 				<tr>
 					<td >$i18n.getString("relationship_type")<em title="$i18n.getString( "required" )" class="required">*</em></td>
@@ -48,24 +47,14 @@
 						</select>
 					</td>
 				</tr>
-				<tr>
-					<td>$i18n.getString("search_by")<em title="$i18n.getString( "required" )" class="required">*</em></td>
-					<td>
-						<select id="searchType" name="searchType" onclick="toggleSearchType(this)" style='width:18em'>
-							<option value="">[$i18n.getString( "please_select" )]</option>        
-							<option value="attribute">$i18n.getString("attribute")</option>
-							<option value="name">$i18n.getString("name")</option>		
-						</select>
-					</td>
-				</tr>
 				<tr><td colspan="2"></td></tr>
-				<tr id="rowAttribute" style="display: none">
-					<td>$i18n.getString("attribute")</td>
+				<tr id="rowAttribute">
+					<td>$i18n.getString("attribute")<em title="$i18n.getString( "required" )" class="required">*</em></td>
 					<td>
 						<select name="attributeId" id="attributeId" style='width:18em'>
 							<option value="">[$i18n.getString( "please_select" )]</option>       
 							#foreach($attribute in $attributes)
-								<option value="$attribute.id">$attribute.displayName</option>
+								<option value="$attribute.uid">$attribute.displayName</option>
 							#end
 						</select>
 					</td>
@@ -119,6 +108,9 @@
 </div>
 
 <script>
-	var i18n_no_result = '$encoder.jsEscape( $i18n.getString( "no_result" ) , "'")';
+	var i18n_no_result_found = '$encoder.jsEscape( $i18n.getString( "no_result_found" ) , "'")';
+	var i18n_duplicate_warning = '$encoder.jsEscape( $i18n.getString( "duplicate_warning" ) , "'")';
+	var i18n_choose_this_tracked_entity_instance = '$encoder.jsEscape( $i18n.getString( "choose_this_tracked_entity_instance" ) , "'")';
+	var i18n_please_select_relationshipType = '$encoder.jsEscape( $i18n.getString( "please_select_relationshipType" ) , "'")';
 </script>