← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14055: Add TrackedEntity object to allow multiple types of entities to be tracked in the same db.

 

------------------------------------------------------------
revno: 14055
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-02-17 22:00:27 +0700
message:
  Add TrackedEntity object to allow multiple types of entities to be tracked in the same db.
removed:
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionStoreTest.java
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntity.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntity.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/AddTrackedEntityAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/RemoveTrackedEntityAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/UpdateTrackedEntityAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/ValidateTrackedEntityAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addTrackedEntity.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/trackedEntity.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateTrackedEntity.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityInstance.hbm.xml
  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/GetTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentSelectAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ShowAddTrackedEntityInstanceFormAction.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/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultTrackedEntityForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowUpdateProgramFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/index.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/menu.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-02-17 15:00:27 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
@@ -141,6 +142,8 @@
 
     private Boolean dataEntryMethod = false;
 
+    private TrackedEntity trackedEntity;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -606,4 +609,19 @@
     {
         this.attributes = attributes;
     }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "trackedEntity", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "trackedEntity", namespace = DxfNamespaces.DXF_2_0 )
+    public TrackedEntity getTrackedEntity()
+    {
+        return trackedEntity;
+    }
+
+    public void setTrackedEntity( TrackedEntity trackedEntity )
+    {
+        this.trackedEntity = trackedEntity;
+    }
+
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java	2013-11-14 09:36:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java	2014-02-17 15:00:27 +0000
@@ -31,6 +31,7 @@
 import java.util.Collection;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.validation.ValidationCriteria;
 
 /**
@@ -178,4 +179,12 @@
      * @param organisationUnit {@link OrganisationUnit}
      */
     Collection<Program> getProgramsByCurrentUser( OrganisationUnit organisationUnit );
+    
+    /**
+     * Get {@link Program} by TrackedEntity
+     * 
+     * @param trackedEntity {@link TrackedEntity}
+     */
+    Collection<Program> getProgramsByTrackedEntity( TrackedEntity trackedEntity );
+    
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java	2013-11-04 03:13:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java	2014-02-17 15:00:27 +0000
@@ -30,6 +30,7 @@
 
 import org.hisp.dhis.common.GenericNameableObjectStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 
 import java.util.Collection;
 
@@ -95,4 +96,12 @@
      * @return Program list
      */
     Collection<Program> getProgramsByDisplayOnAllOrgunit( boolean displayOnAllOrgunit, OrganisationUnit orgunit );
+
+    /**
+     * Get {@link Program} by TrackedEntity
+     * 
+     * @param trackedEntity {@link TrackedEntity}
+     */
+    Collection<Program> getByTrackedEntity( TrackedEntity trackedEntity );
+    
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntity.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntity.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntity.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity;
+
+import org.hisp.dhis.common.BaseNameableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ TrackedEntity.java Feb 14, 2014 11:52:47 PM $
+ */
+@JacksonXmlRootElement( localName = "trackedEntity", namespace = DxfNamespaces.DXF_2_0 )
+public class TrackedEntity
+    extends BaseNameableObject
+{
+    private static final long serialVersionUID = 3520485123419518620L;
+
+    // -------------------------------------------------------------------------
+    // Constructor
+    // -------------------------------------------------------------------------
+
+    public TrackedEntity()
+    {
+    }
+
+    public TrackedEntity( String name, String description )
+    {
+        this.name = name;
+        this.description = description;
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstance.java	2014-02-17 15:00:27 +0000
@@ -42,6 +42,7 @@
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
@@ -58,7 +59,7 @@
     private static final long serialVersionUID = 884114994005945275L;
 
     public static String SEARCH_SAPERATE = "_";
-    
+
     public static String PREFIX_TRACKED_ENTITY_ATTRIBUTE = "attr";
 
     public static String PREFIX_PROGRAM = "prg";
@@ -77,6 +78,8 @@
 
     private TrackedEntityInstance representative;
 
+    private TrackedEntity trackedEntity;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -152,5 +155,18 @@
         attributeValues.remove( attributeValue );
         attributeValue.setEntityInstance( null );
     }
+    
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "trackedEntity", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "trackedEntity", namespace = DxfNamespaces.DXF_2_0 )
+    public TrackedEntity getTrackedEntity()
+    {
+        return trackedEntity;
+    }
 
+    public void setTrackedEntity( TrackedEntity trackedEntity )
+    {
+        this.trackedEntity = trackedEntity;
+    }
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity;
+
+import java.util.Collection;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ TrackedEntityService.java Feb 15, 2014 7:23:48 PM $
+ */
+public interface TrackedEntityService
+{
+    String ID = TrackedEntityService.class.getName();
+
+    /**
+     * Adds an {@link TrackedEntity}
+     * 
+     * @param trackedEntity The to TrackedEntity
+     *        add.
+     * 
+     * @return A generated unique id of the added
+     *         {@link TrackedEntity}.
+     */
+    int addTrackedEntity( TrackedEntity trackedEntity );
+
+    /**
+     * Deletes a {@link TrackedEntity}.
+     * 
+     * @param trackedEntity the TrackedEntity to
+     *        delete.
+     */
+    void deleteTrackedEntity( TrackedEntity trackedEntity );
+
+    /**
+     * Updates a {@link TrackedEntity}.
+     * 
+     * @param trackedEntity the TrackedEntity to
+     *        update.
+     */
+    void updateTrackedEntity( TrackedEntity trackedEntity );
+
+    /**
+     * Returns a {@link TrackedEntity}.
+     * 
+     * @param id the id of the TrackedEntity to return.
+     * 
+     * @return the TrackedEntity with the given id
+     */
+    TrackedEntity getTrackedEntity( int id );
+
+    /**
+     * Returns a {@link TrackedEntity} with a given name.
+     * 
+     * @param name the name of the TrackedEntity to return.
+     * 
+     * @return the TrackedEntity with the given name, or null if
+     *         no match.
+     */
+    TrackedEntity getTrackedEntityByName( String name );
+
+    /**
+     * Returns all {@link TrackedEntity}
+     * 
+     * @return a collection of all TrackedEntity, or an empty
+     *         collection if there are no TrackedEntitys.
+     */
+    Collection<TrackedEntity> getAllTrackedEntity();
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2014-02-17 15:00:27 +0000
@@ -31,6 +31,7 @@
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.validation.ValidationCriteria;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -193,4 +194,9 @@
         return programs;
     }
 
+    @Override
+    public Collection<Program> getProgramsByTrackedEntity( TrackedEntity trackedEntity )
+    {
+        return i18n( i18nService, programStore.getByTrackedEntity( trackedEntity ) );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2014-02-17 15:00:27 +0000
@@ -28,6 +28,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
@@ -35,14 +39,11 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStore;
 import org.hisp.dhis.system.util.CollectionUtils;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.user.UserService;
 
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
 /**
  * @author Chau Thu Tran
  */
@@ -72,14 +73,14 @@
     // Implemented methods
     // -------------------------------------------------------------------------
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     @Override
     public Collection<Program> getByType( int type )
     {
         return getCriteria( Restrictions.eq( "type", type ) ).list();
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     @Override
     public Collection<Program> get( int type, OrganisationUnit organisationUnit )
     {
@@ -112,7 +113,7 @@
         {
             programs = getAll();
         }
-        
+
         return programs;
     }
 
@@ -138,12 +139,12 @@
         {
             programs = getByType( type );
         }
-        
+
         return programs;
     }
 
     @Override
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public Collection<Program> getProgramsByDisplayOnAllOrgunit( boolean displayOnAllOrgunit, OrganisationUnit orgunit )
     {
         Criteria criteria = getCriteria();
@@ -157,4 +158,12 @@
 
         return criteria.list();
     }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public Collection<Program> getByTrackedEntity( TrackedEntity trackedEntity )
+    {
+        return getCriteria( Restrictions.eq( "trackedEntity", trackedEntity ) ).list();
+    }
+
 }

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity;
+
+import java.util.Collection;
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ DefaultTrackedEntityService.java Feb 15, 2014 7:28:41 PM $
+ */
+@Transactional
+public class DefaultTrackedEntityService
+    implements TrackedEntityService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private GenericIdentifiableObjectStore<TrackedEntity> trackedEntityStore;
+
+    public void setTrackedEntityStore( GenericIdentifiableObjectStore<TrackedEntity> trackedEntityStore )
+    {
+        this.trackedEntityStore = trackedEntityStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // TrackedEntity
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int addTrackedEntity( TrackedEntity trackedEntity )
+    {
+        return trackedEntityStore.save( trackedEntity );
+    }
+
+    @Override
+    public void deleteTrackedEntity( TrackedEntity trackedEntity )
+    {
+        trackedEntityStore.delete( trackedEntity );
+    }
+
+    @Override
+    public void updateTrackedEntity( TrackedEntity trackedEntity )
+    {
+        trackedEntityStore.update( trackedEntity );
+    }
+
+    @Override
+    public TrackedEntity getTrackedEntity( int id )
+    {
+        return trackedEntityStore.get( id );
+    }
+
+    @Override
+    public TrackedEntity getTrackedEntityByName( String name )
+    {
+        return trackedEntityStore.getByName( name );
+    }
+
+    @Override
+    public Collection<TrackedEntity> getAllTrackedEntity()
+    {
+        return trackedEntityStore.getAll();
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-02-10 11:24:32 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-02-17 15:00:27 +0000
@@ -38,6 +38,7 @@
 import org.amplecode.quick.StatementManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataentryform.DataEntryForm;
@@ -274,6 +275,8 @@
         executeSql( "update userroleauthorities set authority='F_TRACKED_ENTITY_ATTRIBUTEVALUE_DELETE' where authority='F_PATIENTATTRIBUTEVALUE_DELETE'" );
         executeSql( "update userroleauthorities set authority='F_TRACKED_ENTITY_INSTANCE_REMINDER_MANAGEMENT' where authority='F_PATIENT_REMINDER_MANAGEMENT'" );
 
+        createPersonTrackedEntity();
+
     }
 
     // -------------------------------------------------------------------------
@@ -416,6 +419,24 @@
         }
     }
 
+    private void createPersonTrackedEntity()
+    {
+        int exist = jdbcTemplate.queryForInt( "SELECT count(*) FROM trackedentity where name='Person'" );
+        if ( exist == 0 )
+        {
+            String id = statementBuilder.getAutoIncrementValue();
+            
+            jdbcTemplate.execute( "INSERT INTO trackedentity(trackedentityid,uid, name, description) values(" + id
+                + ",'" + CodeGenerator.generateCode() + "','Person','Person')" );
+            
+            jdbcTemplate.execute( "UPDATE program SET trackedentityid="
+                + "  (SELECT trackedentityid FROM trackedentity where name='Person') where trackedentityid is null" );
+            
+            jdbcTemplate.execute( "UPDATE trackedentityinstance SET trackedentityid="
+                + "  (SELECT trackedentityid FROM trackedentity where name='Person') where trackedentityid is null" );
+        }
+    }
+
     private int executeSql( String sql )
     {
         try

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-02-15 18:00:27 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-02-17 15:00:27 +0000
@@ -131,7 +131,13 @@
 			value="org.hisp.dhis.trackedentity.TrackedEntityAudit" />
 		<property name="sessionFactory" ref="sessionFactory" />
 	</bean>
-
+	
+	<bean id="org.hisp.dhis.trackedentity.TrackedEntityStore" 
+		class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
+		<property name="clazz" value="org.hisp.dhis.trackedentity.TrackedEntity" />
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
+	
 	<!-- Service definitions -->
 
 	<bean id="org.hisp.dhis.program.ProgramDataEntryService" class="org.hisp.dhis.program.DefaultProgramDataEntryService">
@@ -284,6 +290,12 @@
 		<property name="auditStore"
 			ref="org.hisp.dhis.trackedentity.TrackedEntityAuditStore" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.trackedentity.TrackedEntityService"
+		class="org.hisp.dhis.trackedentity.DefaultTrackedEntityService">
+		<property name="trackedEntityStore"
+			ref="org.hisp.dhis.trackedentity.TrackedEntityStore" />
+	</bean>
 
 	<!-- TrackedEntityComment -->
 

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2014-02-17 15:00:27 +0000
@@ -6,104 +6,108 @@
   >
 
 <hibernate-mapping>
-	<class name="org.hisp.dhis.program.Program" table="program">
-
-		<cache usage="read-write" />
-
-		<id name="id" column="programid">
-			<generator class="native" />
-		</id>
-        &identifiableProperties;
-
-		<property name="name" column="name" not-null="true" length="230" />
-
-		<property name="description" type="text" />
-
-		<property name="version" />
-
-		<property name="dateOfEnrollmentDescription" type="text" />
-
-		<property name="dateOfIncidentDescription" type="text" />
-
-		<set name="programStages" order-by="mindaysfromstart" cascade="all">
-			<key column="programid" />
-			<one-to-many class="org.hisp.dhis.program.ProgramStage" />
-		</set>
-
-		<set name="organisationUnits" table="program_organisationunits">
-			<key column="programid" foreign-key="fk_program_organisationunits_programid" />
-			<many-to-many column="organisationunitid"
-				class="org.hisp.dhis.organisationunit.OrganisationUnit" foreign-key="fk_program_organisationunits_organisationunitid" />
-		</set>
-
-		<set name="validationCriteria" table="program_criteria">
-			<key column="programid" foreign-key="fk_program_criteria_programid" />
-			<many-to-many column="validationcriteriaid"
-				class="org.hisp.dhis.validation.ValidationCriteria" foreign-key="fk_program_criteria_validationcriteriaid" />
-		</set>
-
-		<property name="type" />
-
-		<property name="displayIncidentDate" />
-
-		<property name="onlyEnrollOnce" />
-
-		<set name="attributes" cascade="all,delete-orphan" order-by="sort_order">
-			<key column="programid" />
-			<one-to-many class="org.hisp.dhis.program.ProgramTrackedEntityAttribute" />
-		</set>
-		
-		<property name="ignoreOverdueEvents" />
-
-		<set name="userRoles" table="program_userroles">
-			<key column="programid" />
-			<many-to-many class="org.hisp.dhis.user.UserAuthorityGroup"
-				column="userroleid" foreign-key="fk_program_userroles" />
-		</set>
-
-		<set name="instanceReminders" order-by="daysAllowedSendMessage"
-			cascade="all">
-			<key column="programid" />
-			<one-to-many class="org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder" />
-		</set>
-
-		<set name="organisationUnitGroups" table="orgunitgroupprograms">
-			<key column="programid" />
-			<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup"
-				column="orgunitgroupid" />
-		</set>
-
-		<property name="displayOnAllOrgunit" />
-
-		<property name="selectEnrollmentDatesInFuture" />
-
-		<property name="selectIncidentDatesInFuture" />
-
-		<property name="relationshipText" />
-
-		<many-to-one name="relationshipType"
-			class="org.hisp.dhis.relationship.RelationshipType" column="relationshiptypeid"
-			foreign-key="fk_program_relationshipid" />
-
-		<property name="relationshipFromA" />
-
-		<many-to-one name="relatedProgram" class="org.hisp.dhis.program.Program"
-			column="relatedprogramid" foreign-key="fk_program_relatedprogram" />
-
-		<property name="dataEntryMethod" />
-
-		<!-- Access properties -->
-
-		<many-to-one name="user" class="org.hisp.dhis.user.User"
-			column="userid" foreign-key="fk_program_userid" />
-
-		<property name="publicAccess" length="8" />
-
-		<set name="userGroupAccesses" table="programusergroupaccesses">
-			<key column="programid" />
-			<many-to-many class="org.hisp.dhis.user.UserGroupAccess"
-				column="usergroupaccessid" unique="true" />
-		</set>
-
-	</class>
+  <class name="org.hisp.dhis.program.Program" table="program">
+
+	<cache usage="read-write" />
+
+	<id name="id" column="programid">
+		<generator class="native" />
+	</id>
+       &identifiableProperties;
+
+	<property name="name" column="name" not-null="true" length="230" />
+
+	<property name="description" type="text" />
+
+	<property name="version" />
+
+	<property name="dateOfEnrollmentDescription" type="text" />
+
+	<property name="dateOfIncidentDescription" type="text" />
+
+	<set name="programStages" order-by="mindaysfromstart" cascade="all">
+		<key column="programid" />
+		<one-to-many class="org.hisp.dhis.program.ProgramStage" />
+	</set>
+
+	<set name="organisationUnits" table="program_organisationunits">
+		<key column="programid" foreign-key="fk_program_organisationunits_programid" />
+		<many-to-many column="organisationunitid"
+			class="org.hisp.dhis.organisationunit.OrganisationUnit" foreign-key="fk_program_organisationunits_organisationunitid" />
+	</set>
+
+	<set name="validationCriteria" table="program_criteria">
+		<key column="programid" foreign-key="fk_program_criteria_programid" />
+		<many-to-many column="validationcriteriaid"
+			class="org.hisp.dhis.validation.ValidationCriteria" foreign-key="fk_program_criteria_validationcriteriaid" />
+	</set>
+
+	<property name="type" />
+
+	<property name="displayIncidentDate" />
+
+	<property name="onlyEnrollOnce" />
+
+	<set name="attributes" cascade="all,delete-orphan" order-by="sort_order">
+		<key column="programid" />
+		<one-to-many class="org.hisp.dhis.program.ProgramTrackedEntityAttribute" />
+	</set>
+	
+	<property name="ignoreOverdueEvents" />
+
+	<set name="userRoles" table="program_userroles">
+		<key column="programid" />
+		<many-to-many class="org.hisp.dhis.user.UserAuthorityGroup"
+			column="userroleid" foreign-key="fk_program_userroles" />
+	</set>
+
+	<set name="instanceReminders" order-by="daysAllowedSendMessage"
+		cascade="all">
+		<key column="programid" />
+		<one-to-many class="org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder" />
+	</set>
+
+	<set name="organisationUnitGroups" table="orgunitgroupprograms">
+		<key column="programid" />
+		<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup"
+			column="orgunitgroupid" />
+	</set>
+
+	<property name="displayOnAllOrgunit" />
+
+	<property name="selectEnrollmentDatesInFuture" />
+
+	<property name="selectIncidentDatesInFuture" />
+
+	<property name="relationshipText" />
+
+	<many-to-one name="relationshipType"
+		class="org.hisp.dhis.relationship.RelationshipType" column="relationshiptypeid"
+		foreign-key="fk_program_relationshipid" />
+
+	<property name="relationshipFromA" />
+
+	<many-to-one name="relatedProgram" class="org.hisp.dhis.program.Program"
+		column="relatedprogramid" foreign-key="fk_program_relatedprogram" />
+
+	<property name="dataEntryMethod" />
+	
+	<many-to-one name="trackedEntity"
+		class="org.hisp.dhis.trackedentity.TrackedEntity" column="trackedentityid"
+		foreign-key="fk_program_trackedentityid" />
+
+	<!-- Access properties -->
+
+	<many-to-one name="user" class="org.hisp.dhis.user.User"
+		column="userid" foreign-key="fk_program_userid" />
+
+	<property name="publicAccess" length="8" />
+
+	<set name="userGroupAccesses" table="programusergroupaccesses">
+		<key column="programid" />
+		<many-to-many class="org.hisp.dhis.user.UserGroupAccess"
+			column="usergroupaccessid" unique="true" />
+	</set>
+
+  </class>
 </hibernate-mapping>

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntity.hbm.xml	2014-02-17 15:00:27 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
+  [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+  >
+
+<hibernate-mapping>
+  <class name="org.hisp.dhis.trackedentity.TrackedEntity" table="trackedentity">
+
+	<id name="id" column="trackedentityid">
+		<generator class="native" />
+	</id>
+  		&identifiableProperties;
+
+	<property name="name" column="name" not-null="true" unique="true"
+		length="230" />
+	
+    <property name="description" type="text" />
+    
+  </class>
+</hibernate-mapping>

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityInstance.hbm.xml	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityInstance.hbm.xml	2014-02-17 15:00:27 +0000
@@ -28,5 +28,9 @@
     <many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid"
       foreign-key="fk_trackedentityinstance_organisationunitid" not-null="true" />
 	
+	<many-to-one name="trackedEntity"
+			class="org.hisp.dhis.trackedentity.TrackedEntity" column="trackedentityid"
+			foreign-key="fk_trackedentityinstance_trackedentityid" />
+	
   </class>
 </hibernate-mapping>

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ TrackedEntityAttributeOptionServiceTest.java Nov 5, 2013 4:25:29 PM $
+ */
+public class TrackedEntityAttributeOptionServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private TrackedEntityAttributeService attributeService;
+
+    private TrackedEntityAttributeOption attributeOptionA;
+
+    private TrackedEntityAttributeOption attributeOptionB;
+
+    private TrackedEntityAttributeOption attributeOptionC;
+
+    private TrackedEntityAttribute attributeA;
+
+    private TrackedEntityAttribute attributeB;
+
+    @Override
+    public void setUpTest()
+    {
+        attributeA = createTrackedEntityAttribute( 'A' );
+        attributeB = createTrackedEntityAttribute( 'B' );
+
+        attributeService.saveTrackedEntityAttribute( attributeA );
+        attributeService.saveTrackedEntityAttribute( attributeB );
+
+        attributeOptionA = createTrackedEntityAttributeOption( 'A', attributeA );
+        attributeOptionB = createTrackedEntityAttributeOption( 'B', attributeA );
+        attributeOptionC = createTrackedEntityAttributeOption( 'C', attributeB );
+    }
+
+    @Test
+    public void testAddTrackedEntityAttributeOption()
+    {
+        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
+        int idB = attributeService.addTrackedEntityAttributeOption( attributeOptionB );
+
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idB ) );
+    }
+
+    @Test
+    public void testDeleteTrackedEntityAttributeGroup()
+    {
+        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
+        int idB = attributeService.addTrackedEntityAttributeOption( attributeOptionB );
+
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idB ) );
+
+        attributeService.deleteTrackedEntityAttributeOption( attributeOptionA );
+
+        assertNull( attributeService.getTrackedEntityAttributeOption( idA ) );
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idB ) );
+
+        attributeService.deleteTrackedEntityAttributeOption( attributeOptionB );
+
+        assertNull( attributeService.getTrackedEntityAttributeOption( idA ) );
+        assertNull( attributeService.getTrackedEntityAttributeOption( idB ) );
+    }
+
+    @Test
+    public void testUpdateTrackedEntityAttributeOption()
+    {
+        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
+
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
+
+        attributeOptionA.setName( "B" );
+        attributeService.updateTrackedEntityAttributeOption( attributeOptionA );
+
+        assertEquals( "B", attributeService.getTrackedEntityAttributeOption( idA ).getName() );
+    }
+
+    @Test
+    public void testGetTrackedEntityAttributeGroupById()
+    {
+        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
+        int idB = attributeService.addTrackedEntityAttributeOption( attributeOptionB );
+
+        assertEquals( attributeOptionA, attributeService.getTrackedEntityAttributeOption( idA ) );
+        assertEquals( attributeOptionB, attributeService.getTrackedEntityAttributeOption( idB ) );
+    }
+
+    @Test
+    public void testGetTrackedEntityAttributeGroupByName()
+    {
+        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
+
+        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
+
+        assertEquals( attributeOptionA, attributeService.getTrackedEntityAttributeOption( attributeA, "AttributeOptionA" ) );
+    }
+
+    @Test
+    public void testGetTrackedEntityAttributeOptionByAttribute()
+    {
+        attributeService.addTrackedEntityAttributeOption( attributeOptionA );
+        attributeService.addTrackedEntityAttributeOption( attributeOptionB );
+        attributeService.addTrackedEntityAttributeOption( attributeOptionC );
+
+        assertTrue( equals( attributeService.getTrackedEntityAttributeOption( attributeA ), attributeOptionA, attributeOptionB ) );
+        assertTrue( equals( attributeService.getTrackedEntityAttributeOption( attributeB ), attributeOptionC ) );
+    }
+
+}
\ No newline at end of file

=== removed file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java	2014-02-15 03:50:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionServiceTest.java	1970-01-01 00:00:00 +0000
@@ -1,144 +0,0 @@
-/*
- * Copyright (c) 2004-2013, 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.
- */
-
-package org.hisp.dhis.trackedentity;
-
-import org.hisp.dhis.DhisSpringTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Chau Thu Tran
- * @version $ TrackedEntityAttributeOptionServiceTest.java Nov 5, 2013 4:25:29 PM $
- */
-public class TrackedEntityAttributeOptionServiceTest
-    extends DhisSpringTest
-{
-    @Autowired
-    private TrackedEntityAttributeService attributeService;
-
-    private TrackedEntityAttributeOption attributeOptionA;
-
-    private TrackedEntityAttributeOption attributeOptionB;
-
-    private TrackedEntityAttributeOption attributeOptionC;
-
-    private TrackedEntityAttribute attributeA;
-
-    private TrackedEntityAttribute attributeB;
-
-    @Override
-    public void setUpTest()
-    {
-        attributeA = createTrackedEntityAttribute( 'A' );
-        attributeB = createTrackedEntityAttribute( 'B' );
-
-        attributeService.saveTrackedEntityAttribute( attributeA );
-        attributeService.saveTrackedEntityAttribute( attributeB );
-
-        attributeOptionA = createTrackedEntityAttributeOption( 'A', attributeA );
-        attributeOptionB = createTrackedEntityAttributeOption( 'B', attributeA );
-        attributeOptionC = createTrackedEntityAttributeOption( 'C', attributeB );
-    }
-
-    @Test
-    public void testAddTrackedEntityAttributeOption()
-    {
-        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-        int idB = attributeService.addTrackedEntityAttributeOption( attributeOptionB );
-
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( (idA) ) );
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idB ) );
-    }
-
-    @Test
-    public void testDeleteTrackedEntityAttributeGroup()
-    {
-        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-        int idB = attributeService.addTrackedEntityAttributeOption( attributeOptionB );
-
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idB ) );
-
-        attributeService.deleteTrackedEntityAttributeOption( attributeOptionA );
-
-        assertNull( attributeService.getTrackedEntityAttributeOption( idA ) );
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idB ) );
-
-        attributeService.deleteTrackedEntityAttributeOption( attributeOptionB );
-
-        assertNull( attributeService.getTrackedEntityAttributeOption( idA ) );
-        assertNull( attributeService.getTrackedEntityAttributeOption( idB ) );
-    }
-
-    @Test
-    public void testUpdateTrackedEntityAttributeOption()
-    {
-        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
-
-        attributeOptionA.setName( "B" );
-        attributeService.updateTrackedEntityAttributeOption( attributeOptionA );
-
-        assertEquals( "B", attributeService.getTrackedEntityAttributeOption( idA ).getName() );
-    }
-
-    @Test
-    public void testGetTrackedEntityAttributeGroupById()
-    {
-        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-        int idB = attributeService.addTrackedEntityAttributeOption( attributeOptionB );
-
-        assertEquals( attributeOptionA, attributeService.getTrackedEntityAttributeOption( idA ) );
-        assertEquals( attributeOptionB, attributeService.getTrackedEntityAttributeOption( idB ) );
-    }
-
-    @Test
-    public void testGetTrackedEntityAttributeGroupByName()
-    {
-        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
-
-        assertEquals( attributeOptionA, attributeService.getTrackedEntityAttributeOption( attributeA, "AttributeOptionA" ) );
-    }
-
-    @Test
-    public void testGetTrackedEntityAttributeOptionByAttribute()
-    {
-        attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-        attributeService.addTrackedEntityAttributeOption( attributeOptionB );
-        attributeService.addTrackedEntityAttributeOption( attributeOptionC );
-
-        assertTrue( equals( attributeService.getTrackedEntityAttributeOption( attributeA ), attributeOptionA, attributeOptionB ) );
-        assertTrue( equals( attributeService.getTrackedEntityAttributeOption( attributeB ), attributeOptionC ) );
-    }
-
-}
\ No newline at end of file

=== removed file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionStoreTest.java	2014-02-15 03:50:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeOptionStoreTest.java	1970-01-01 00:00:00 +0000
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2004-2013, 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.
- */
-
-package org.hisp.dhis.trackedentity;
-
-import org.hisp.dhis.DhisSpringTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Chau Thu Tran
- * @version $ TrackedEntityAttributeOptionStoreTest.java Nov 5, 2013 4:43:12 PM $
- */
-public class TrackedEntityAttributeOptionStoreTest
-    extends DhisSpringTest
-{
-    @Autowired
-    private TrackedEntityAttributeService attributeService;
-
-    private TrackedEntityAttributeOption attributeOptionA;
-
-    private TrackedEntityAttributeOption attributeOptionB;
-
-    private TrackedEntityAttributeOption attributeOptionC;
-
-    private TrackedEntityAttribute attributeA;
-
-    private TrackedEntityAttribute attributeB;
-
-    @Override
-    public void setUpTest()
-    {
-        attributeA = createTrackedEntityAttribute( 'A' );
-        attributeB = createTrackedEntityAttribute( 'B' );
-
-        attributeService.saveTrackedEntityAttribute( attributeA );
-        attributeService.saveTrackedEntityAttribute( attributeB );
-
-        attributeOptionA = createTrackedEntityAttributeOption( 'A', attributeA );
-        attributeOptionB = createTrackedEntityAttributeOption( 'B', attributeA );
-        attributeOptionC = createTrackedEntityAttributeOption( 'C', attributeB );
-    }
-
-    @Test
-    public void testGetTrackedEntityAttributeGroupByName()
-    {
-        int idA = attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-
-        assertNotNull( attributeService.getTrackedEntityAttributeOption( idA ) );
-
-        assertEquals( attributeOptionA, attributeService.getTrackedEntityAttributeOption( attributeA, "AttributeOptionA" ) );
-    }
-
-    @Test
-    public void testGetTrackedEntityAttributeOptionByAttribute()
-    {
-        attributeService.addTrackedEntityAttributeOption( attributeOptionA );
-        attributeService.addTrackedEntityAttributeOption( attributeOptionB );
-        attributeService.addTrackedEntityAttributeOption( attributeOptionC );
-
-        assertTrue( equals( attributeService.getTrackedEntityAttributeOption( attributeA ), attributeOptionA, attributeOptionB ) );
-        assertTrue( equals( attributeService.getTrackedEntityAttributeOption( attributeB ), attributeOptionC ) );
-    }
-
-}
\ No newline at end of file

=== 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-02-14 16:13:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java	2014-02-17 15:00:27 +0000
@@ -39,16 +39,21 @@
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeOption;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -75,6 +80,12 @@
 
     private OrganisationUnitSelectionManager selectionManager;
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    @Autowired
+    private ProgramService programService;
+
     private I18nFormat format;
 
     // -------------------------------------------------------------------------
@@ -89,6 +100,10 @@
 
     private boolean relationshipFromA;
 
+    private Integer trackedEntityId;
+
+    private Integer programId;
+
     private String message;
 
     // -------------------------------------------------------------------------
@@ -98,13 +113,20 @@
     public String execute()
     {
         OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
-
         TrackedEntityInstance entityInstance = new TrackedEntityInstance();
-
-        // ---------------------------------------------------------------------
-        // Set location
-        // ---------------------------------------------------------------------
-
+        TrackedEntity trackedEntity = null;
+        
+        if ( programId != null )
+        {
+            Program program = programService.getProgram( programId );
+            trackedEntity = program.getTrackedEntity();   
+        }
+        else
+        {
+            trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
+        }
+        
+        entityInstance.setTrackedEntity( trackedEntity );
         entityInstance.setOrganisationUnit( organisationUnit );
 
         // ---------------------------------------------------------------------
@@ -137,7 +159,8 @@
                     }
                     else if ( TrackedEntityAttribute.TYPE_COMBO.equalsIgnoreCase( attribute.getValueType() ) )
                     {
-                        TrackedEntityAttributeOption option = attributeService.getTrackedEntityAttributeOption( Integer.parseInt( value ) );
+                        TrackedEntityAttributeOption option = attributeService.getTrackedEntityAttributeOption( Integer
+                            .parseInt( value ) );
                         if ( option != null )
                         {
                             attributeValue.setAttributeOption( option );
@@ -149,8 +172,8 @@
             }
         }
 
-        int entityInstanceId = entityInstanceService.createTrackedEntityInstance( entityInstance, representativeId, relationshipTypeId,
-            attributeValues );
+        int entityInstanceId = entityInstanceService.createTrackedEntityInstance( entityInstance, representativeId,
+            relationshipTypeId, attributeValues );
 
         // -------------------------------------------------------------------------
         // Create relationship
@@ -218,6 +241,11 @@
         this.selectionManager = selectionManager;
     }
 
+    public void setTrackedEntityId( Integer trackedEntityId )
+    {
+        this.trackedEntityId = trackedEntityId;
+    }
+
     public String getMessage()
     {
         return message;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java	2014-02-17 15:00:27 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeGroup;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeGroupService;
@@ -52,9 +53,11 @@
 import org.hisp.dhis.trackedentity.TrackedEntityFormService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.trackedentity.comparator.TrackedEntityAttributeGroupSortOrderComparator;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -81,6 +84,9 @@
 
     private TrackedEntityAttributeService attributeService;
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
     private I18n i18n;
 
     private I18nFormat format;
@@ -160,6 +166,13 @@
         return trackedEntityForm;
     }
 
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -168,6 +181,7 @@
         throws Exception
     {
         relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
+        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
         entityInstance = entityInstanceService.getTrackedEntityInstance( id );
 
         healthWorkers = entityInstance.getOrganisationUnit().getUsers();
@@ -179,9 +193,9 @@
 
             if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
             {
-                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd(
-                    trackedEntityForm.getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(),
-                    healthWorkers, null, null, i18n, format );
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
+                    format );
             }
         }
         else
@@ -191,9 +205,9 @@
 
             if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
             {
-                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd(
-                    trackedEntityForm.getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(),
-                    healthWorkers, null, null, i18n, format );
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
+                    format );
             }
         }
 
@@ -211,7 +225,7 @@
                 Collection<Program> programs = programService.getAllPrograms();
                 for ( Program p : programs )
                 {
-                    for ( TrackedEntityAttribute attribute : p.getEntityAttributes())
+                    for ( TrackedEntityAttribute attribute : p.getEntityAttributes() )
                     {
                         if ( !attribute.getDisplayInListNoProgram() )
                         {
@@ -272,7 +286,6 @@
     // Getter / Setter
     // -----------------------------------------------------------------------------
 
-  
     public void setI18n( I18n i18n )
     {
         this.i18n = i18n;
@@ -298,13 +311,11 @@
         return attributeGroupsMap;
     }
 
-
     public Relationship getRelationship()
     {
         return relationship;
     }
 
-
     public void setId( int id )
     {
         this.id = id;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentSelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentSelectAction.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentSelectAction.java	2014-02-17 15:00:27 +0000
@@ -40,6 +40,8 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -120,6 +122,7 @@
         // Get all programs
 
         programs = new ArrayList<Program>( programService.getProgramsByCurrentUser( orgunit ) );
+        programs.retainAll( programService.getProgramsByTrackedEntity( entityInstance.getTrackedEntity() ) );
         programs.removeAll( programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION ) );
 
         Iterator<Program> iterProgram = programs.iterator();

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ShowAddTrackedEntityInstanceFormAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ShowAddTrackedEntityInstanceFormAction.java	2014-02-08 15:19:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ShowAddTrackedEntityInstanceFormAction.java	2014-02-17 15:00:27 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeGroup;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeGroupService;
@@ -50,6 +51,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityForm;
 import org.hisp.dhis.trackedentity.TrackedEntityFormService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.trackedentity.comparator.TrackedEntityAttributeGroupSortOrderComparator;
 import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -69,7 +71,7 @@
 
     @Autowired
     private TrackedEntityInstanceService entityInstanceService;
-    
+
     private OrganisationUnitSelectionManager selectionManager;
 
     public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
@@ -77,7 +79,6 @@
         this.selectionManager = selectionManager;
     }
 
-
     private ProgramService programService;
 
     public void setProgramService( ProgramService programService )
@@ -113,6 +114,9 @@
         this.relationshipTypeService = relationshipTypeService;
     }
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
     private I18n i18n;
 
     public void setI18n( I18n i18n )
@@ -255,17 +259,26 @@
         return relationshipTypes;
     }
 
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
     public String execute()
     {
-        if( entityInstanceId!=null)
+        if ( entityInstanceId != null )
         {
             entityInstanceUid = entityInstanceService.getTrackedEntityInstance( entityInstanceId ).getUid();
         }
-        
+
+        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
+
         organisationUnit = selectionManager.getSelectedOrganisationUnit();
         healthWorkers = organisationUnit.getUsers();
 
@@ -275,9 +288,9 @@
 
             if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
             {
-                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd(
-                    trackedEntityForm.getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(),
-                    healthWorkers, null, null, i18n, format );
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
+                    format );
             }
         }
         else
@@ -287,9 +300,9 @@
 
             if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
             {
-                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd(
-                    trackedEntityForm.getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(),
-                    healthWorkers, null, null, i18n, format );
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, null, null, i18n,
+                    format );
             }
         }
 
@@ -303,7 +316,7 @@
             {
                 attributes = new ArrayList<TrackedEntityAttribute>( attributeService.getAllTrackedEntityAttributes() );
                 Collection<Program> programs = programService.getAllPrograms();
-                
+
                 for ( Program p : programs )
                 {
                     attributes.removeAll( p.getAttributes() );

=== 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-02-14 16:13:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java	2014-02-17 15:00:27 +0000
@@ -38,15 +38,18 @@
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeOption;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -67,7 +70,11 @@
 
     private TrackedEntityAttributeValueService attributeValueService;
 
-    private OrganisationUnitSelectionManager selectionManager;
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    @Autowired
+    private ProgramService programService;
 
     private I18nFormat format;
 
@@ -81,6 +88,10 @@
 
     private Integer relationshipTypeId;
 
+    private Integer trackedEntityId;
+
+    private Integer programId;
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -94,15 +105,19 @@
     public String execute()
         throws Exception
     {
-        OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
-
-        entityInstance = entityInstanceService.getTrackedEntityInstance( id );
-
-        // ---------------------------------------------------------------------
-        // Set location
-        // ---------------------------------------------------------------------
-
-        entityInstance.setOrganisationUnit( organisationUnit );
+        TrackedEntityInstance entityInstance = entityInstanceService.getTrackedEntityInstance( id );
+        TrackedEntity trackedEntity = null;
+
+        if ( programId != null )
+        {
+            Program program = programService.getProgram( programId );
+            trackedEntity = program.getTrackedEntity();
+        }
+        else
+        {
+            trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
+        }
+        entityInstance.setTrackedEntity( trackedEntity );
 
         // ---------------------------------------------------------------------
         // Save Tracked Entity Instance Attributes
@@ -124,7 +139,8 @@
 
             for ( TrackedEntityAttribute attribute : attributes )
             {
-                String value = request.getParameter( AddTrackedEntityInstanceAction.PREFIX_ATTRIBUTE + attribute.getId() );
+                String value = request.getParameter( AddTrackedEntityInstanceAction.PREFIX_ATTRIBUTE
+                    + attribute.getId() );
 
                 if ( StringUtils.isNotBlank( value ) )
                 {
@@ -143,8 +159,8 @@
                         attributeValue.setValue( value.trim() );
                         if ( TrackedEntityAttribute.TYPE_COMBO.equalsIgnoreCase( attribute.getValueType() ) )
                         {
-                            TrackedEntityAttributeOption option = attributeService.getTrackedEntityAttributeOption( Integer
-                                .parseInt( value ) );
+                            TrackedEntityAttributeOption option = attributeService
+                                .getTrackedEntityAttributeOption( Integer.parseInt( value ) );
                             if ( option != null )
                             {
                                 attributeValue.setAttributeOption( option );
@@ -157,8 +173,8 @@
                     {
                         if ( TrackedEntityAttribute.TYPE_COMBO.equalsIgnoreCase( attribute.getValueType() ) )
                         {
-                            TrackedEntityAttributeOption option = attributeService.getTrackedEntityAttributeOption( NumberUtils.toInt(
-                                value, 0 ) );
+                            TrackedEntityAttributeOption option = attributeService
+                                .getTrackedEntityAttributeOption( NumberUtils.toInt( value, 0 ) );
                             if ( option != null )
                             {
                                 attributeValue.setAttributeOption( option );
@@ -177,8 +193,8 @@
             }
         }
 
-        entityInstanceService.updateTrackedEntityInstance( entityInstance, representativeId, relationshipTypeId, valuesForSave, valuesForUpdate,
-            valuesForDelete );
+        entityInstanceService.updateTrackedEntityInstance( entityInstance, representativeId, relationshipTypeId,
+            valuesForSave, valuesForUpdate, valuesForDelete );
 
         return SUCCESS;
     }
@@ -192,6 +208,11 @@
         this.format = format;
     }
 
+    public void setTrackedEntityService( TrackedEntityService trackedEntityService )
+    {
+        this.trackedEntityService = trackedEntityService;
+    }
+
     public void setentityInstanceService( TrackedEntityInstanceService entityInstanceService )
     {
         this.entityInstanceService = entityInstanceService;
@@ -207,11 +228,6 @@
         this.attributeValueService = attributeValueService;
     }
 
-    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
-    {
-        this.selectionManager = selectionManager;
-    }
-
     public void setId( Integer id )
     {
         this.id = id;

=== 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-02-14 16:13:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-02-17 15:00:27 +0000
@@ -469,8 +469,6 @@
 		<property name="attributeService">
 			<ref bean="org.hisp.dhis.trackedentity.TrackedEntityAttributeService" />
 		</property>
-		<property name="selectionManager"
-			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
 	</bean>
 
 	<bean id="org.hisp.dhis.caseentry.action.trackedentity.ShowAddTrackedEntityInstanceFormAction"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2014-02-14 13:59:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2014-02-17 15:00:27 +0000
@@ -677,4 +677,5 @@
 events = Events
 add_filter=Add filter
 relationship_description = Relationship description
-this_tracked_entity_instance_could_not_be_enrolled_please_check_validation_criteria = This tracked entity instance could not be enrolled please check validation criteria
\ No newline at end of file
+this_tracked_entity_instance_could_not_be_enrolled_please_check_validation_criteria = This tracked entity instance could not be enrolled please check validation criteria
+tracked_entity = Tracked entity
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultTrackedEntityForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultTrackedEntityForm.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultTrackedEntityForm.vm	2014-02-17 15:00:27 +0000
@@ -2,25 +2,22 @@
 	<th colspan="2" class="heading-column">$i18n.getString( "demographics" )</th>
 </tr>
 
-#if($trackedEntityForm.fixedAttributes.contains( 'healthWorker' ))
+#if($program)
+	<input type='hidden' id='trackedEntityId' name='trackedEntityId' value='$program.trackedEntity.id'>
+#else
 	<tr>
-		<td class='text-column'><label for="healthWorker">$i18n.getString( "health_worker" )</label></td>
+		<td class='text-column'><label>$i18n.getString('tracked_entity')<em title="$i18n.getString( 'required' )" class="required">*</em> #end</label></td>
 		<td class="input-column">
-			<select id="healthWorker" name="healthWorker">
-				<option value="">[$i18n.getString("please_select")]</option>
-				#foreach( $healthWorker in $healthWorkers)
-					<option value="$healthWorker.id" #if($entityInstance.associate.id == $healthWorker.id) selected #end>$healthWorker.name</option>
+			<select type='hidden' id='trackedEntityId' name='trackedEntityId' value='$program.trackedEntity.id'>
+				<option value=''>[$i18n.getString('please_select')]</option>
+				#foreach($trackedEntity in $trackedEntities)
+				<option value='$trackedEntity.id' #if($entityInstance.trackedEntity>$trackedEntity.displayName</option>
 				#end
 			</select>
-		</td>
+		</td>	
 	</tr>
 #end
 
-<tr>
-	<td></td>
-	<td><input type="button" class='button' id='checkDuplicateBtn' name='checkDuplicateBtn' value="$i18n.getString('check_duplicate')" /></td>
-</tr>
-
 <!-- ATTRIBUTES IN GROUPS -->
 
 #foreach($attribute in $$trackedEntityForm.dynamicAttributes )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm	2014-02-17 15:00:27 +0000
@@ -12,6 +12,24 @@
 		{validate:{required:true}}
 	  #end
 	#end
+	<tr>
+		<th colspan="2" class="heading-column">$i18n.getString( "demographics" )</th>
+	</tr>
+	#if($program)
+		<input type='hidden' id='trackedEntityId' name='trackedEntityId' value='$program.trackedEntity.id'>
+	#else
+		<tr>
+			<td class='text-column'><label>$i18n.getString('tracked_entity')<em title="$i18n.getString( 'required' )" class="required">*</em> </label></td>
+			<td class="input-column">
+				<select type='hidden' id='trackedEntityId' name='trackedEntityId' value='$program.trackedEntity.id'>
+					<option value=''>[$i18n.getString('please_select')]</option>
+					#foreach($trackedEntity in $trackedEntities)
+					<option value='$trackedEntity.id' #if($entityInstance.trackedEntity.id==$trackedEntity.id) selected #end >$trackedEntity.displayName</option>
+					#end
+				</select>
+			</td>	
+		</tr>
+	#end
 
 #foreach ($attributeGroup in $attributeGroups )
 	 #set($attributesByGroup = $!attributesMap.get($attributeGroup.displayName))

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntity.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntity.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntity.vm	2014-02-17 15:00:27 +0000
@@ -0,0 +1,7 @@
+{ "trackedEntity": 
+  {
+    "id": $!{trackedEntity.id},
+    "name": "$!encoder.jsonEncode( ${trackedEntity.displayName} )",
+    "description": "$!encoder.jsonEncode( ${trackedEntity.displayDescription} )"
+  } 
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2014-02-17 15:00:27 +0000
@@ -41,9 +41,12 @@
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -97,6 +100,9 @@
         this.relationshipTypeService = relationshipTypeService;
     }
 
+    @Autowired 
+    private TrackedEntityService trackedEntityService;
+    
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -227,6 +233,13 @@
         this.dataEntryMethod = dataEntryMethod;
     }
 
+    private Integer trackedEntityId;
+
+    public void setTrackedEntityId( Integer trackedEntityId )
+    {
+        this.trackedEntityId = trackedEntityId;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -280,6 +293,11 @@
         program.setRelationshipFromA( relationshipFromA );
         program.setRelationshipText( relationshipText );
 
+        if( trackedEntityId!=null)
+        {
+            TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
+            program.setTrackedEntity( trackedEntity );
+        }
         programService.addProgram( program );
 
         int index = 0;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java	2014-02-17 15:00:27 +0000
@@ -38,10 +38,13 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -84,6 +87,9 @@
         this.relationshipTypeService = relationshipTypeService;
     }
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -116,6 +122,13 @@
         return programs;
     }
 
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -133,6 +146,9 @@
         relationshipTypes = new ArrayList<RelationshipType>( relationshipTypeService.getAllRelationshipTypes() );
         Collections.sort( relationshipTypes, IdentifiableObjectNameComparator.INSTANCE );
 
+        trackedEntities = new ArrayList<TrackedEntity>(trackedEntityService.getAllTrackedEntity());
+        Collections.sort( trackedEntities, IdentifiableObjectNameComparator.INSTANCE );
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowUpdateProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowUpdateProgramFormAction.java	2014-02-10 05:42:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowUpdateProgramFormAction.java	2014-02-17 15:00:27 +0000
@@ -41,10 +41,13 @@
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -87,6 +90,9 @@
         this.relationshipTypeService = relationshipTypeService;
     }
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -176,6 +182,13 @@
         return programs;
     }
 
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -201,6 +214,9 @@
         relationshipTypes = new ArrayList<RelationshipType>( relationshipTypeService.getAllRelationshipTypes() );
         Collections.sort( relationshipTypes, IdentifiableObjectNameComparator.INSTANCE );
 
+        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
+        Collections.sort( trackedEntities, IdentifiableObjectNameComparator.INSTANCE );
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java	2014-02-17 15:00:27 +0000
@@ -36,9 +36,12 @@
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -74,6 +77,9 @@
         this.relationshipTypeService = relationshipTypeService;
     }
 
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -251,6 +257,13 @@
         this.dataEntryMethod = dataEntryMethod;
     }
 
+    private Integer trackedEntityId;
+
+    public void setTrackedEntityId( Integer trackedEntityId )
+    {
+        this.trackedEntityId = trackedEntityId;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -307,6 +320,16 @@
         program.setRelationshipFromA( relationshipFromA );
         program.setRelationshipText( relationshipText );
 
+        if ( trackedEntityId != null )
+        {
+            TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
+            program.setTrackedEntity( trackedEntity );
+        }
+        else if ( program.getTrackedEntity() != null )
+        {
+            program.setTrackedEntity( null );
+        }
+
         if ( program.getAttributes() != null )
         {
             program.getAttributes().clear();

=== added directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity'
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/AddTrackedEntityAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/AddTrackedEntityAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/AddTrackedEntityAction.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity.action.trackedentity;
+
+import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ AddTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
+ */
+public class AddTrackedEntityAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private String name;
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    private String description;
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        TrackedEntity trackedEntity = new TrackedEntity( name, description );
+
+        trackedEntityService.addTrackedEntity( trackedEntity );
+        return SUCCESS;
+    }
+
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityAction.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity.action.trackedentity;
+
+import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ GetTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
+ */
+public class GetTrackedEntityAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private TrackedEntity trackedEntity;
+
+    public TrackedEntity getTrackedEntity()
+    {
+        return trackedEntity;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        trackedEntity = trackedEntityService.getTrackedEntity( id );
+
+        return SUCCESS;
+    }
+
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/GetTrackedEntityListAction.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity.action.trackedentity;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ AddTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
+ */
+public class GetTrackedEntityListAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
+
+        Collections.sort( trackedEntities, IdentifiableObjectNameComparator.INSTANCE );
+
+        return SUCCESS;
+    }
+
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/RemoveTrackedEntityAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/RemoveTrackedEntityAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/RemoveTrackedEntityAction.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity.action.trackedentity;
+
+import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ RemoveTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
+ */
+public class RemoveTrackedEntityAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private TrackedEntity trackedEntity;
+
+    public TrackedEntity getTrackedEntity()
+    {
+        return trackedEntity;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( id );
+        
+        trackedEntityService.deleteTrackedEntity( trackedEntity );
+
+        return SUCCESS;
+    }
+
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/UpdateTrackedEntityAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/UpdateTrackedEntityAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/UpdateTrackedEntityAction.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+package org.hisp.dhis.trackedentity.action.trackedentity;
+
+import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ UpdateTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
+ */
+public class UpdateTrackedEntityAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+    
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private String name;
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    private String description;
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( id );
+
+        trackedEntity.setName( name );
+
+        trackedEntity.setDescription( description );
+        
+        trackedEntityService.updateTrackedEntity( trackedEntity );
+
+        return SUCCESS;
+    }
+
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/ValidateTrackedEntityAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/ValidateTrackedEntityAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentity/ValidateTrackedEntityAction.java	2014-02-17 15:00:27 +0000
@@ -0,0 +1,107 @@
+package org.hisp.dhis.trackedentity.action.trackedentity;
+
+/*
+ * Copyright (c) 2004-2013, 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 org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ValidateTrackedEntityAction.java Feb 15, 2014 7:20:44 PM $
+ */
+public class ValidateTrackedEntityAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private String name;
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        name = name.trim();
+
+        TrackedEntity match = trackedEntityService.getTrackedEntityByName( name );
+
+        if ( match != null && (id == null || match.getId() != id.intValue()) )
+        {
+            message = i18n.getString( "name_in_use" );
+
+            return INPUT;
+        }
+
+        message = i18n.getString( "everything_is_ok" );
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml	2014-02-14 16:13:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml	2014-02-17 15:00:27 +0000
@@ -1129,4 +1129,43 @@
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
 	</bean>
+	
+	<!-- TrackedEntity -->
+	
+	<bean
+		id="org.hisp.dhis.trackedentity.action.trackedentity.AddTrackedEntityAction"
+		class="org.hisp.dhis.trackedentity.action.trackedentity.AddTrackedEntityAction"
+		scope="prototype">
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityAction"
+		class="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityAction"
+		scope="prototype">
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityListAction"
+		class="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityListAction"
+		scope="prototype">
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.trackedentity.action.trackedentity.RemoveTrackedEntityAction"
+		class="org.hisp.dhis.trackedentity.action.trackedentity.RemoveTrackedEntityAction"
+		scope="prototype">
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.trackedentity.action.trackedentity.UpdateTrackedEntityAction"
+		class="org.hisp.dhis.trackedentity.action.trackedentity.UpdateTrackedEntityAction"
+		scope="prototype">
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.trackedentity.action.trackedentity.ValidateTrackedEntityAction"
+		class="org.hisp.dhis.trackedentity.action.trackedentity.ValidateTrackedEntityAction"
+		scope="prototype">
+	</bean>
+	
 </beans>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties	2014-02-16 13:04:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties	2014-02-17 15:00:27 +0000
@@ -396,7 +396,6 @@
 tracked_entity_attribute_visit_schedule_form = Tracked entity attribute visit schedule
 intro_tracked_entity_attribute_visit_schedule = Configure which tracked entity attributes are added to the visit schedule. Gives better overview when used for tracking.
 selected_program_stages = Selected program stages
-tracked_entity = Tracked entity
 orgunit_registered = Organisation unit phone number
 all_users_in_orgunit_registered = All users in organisation unit registered
 date_in_future = Date in future
@@ -477,4 +476,11 @@
 display_in_list_no_program = Display in list without program
 manage_attributes_with_no_program = Manage attributes with no program
 tracked_entity_attributes_displayed_in_list = Tracked entity attributes displayed in list
-unique = Unique
\ No newline at end of file
+unique = Unique
+tracked_entity = Tracked Entity
+tracked_entity_management = Tracked entity management
+intro_tracked_entity =  Allow multiple types of entities to be tracked in the same db. Examples of tracked entities: person, commodity, medicine, student, labtest...
+create_new_tracked_entity = Create new tracked entity
+tracked_entity_details = Tracked entity details
+edit_tracked_entity = Edit tracked entity
+confirm_delete_tracked_entity = Are you sure you want to delete this tracked entity?
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml	2014-02-10 11:24:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml	2014-02-17 15:00:27 +0000
@@ -1174,5 +1174,72 @@
 			</result>
 		</action>
 		
+		<!-- TrackedEntity -->
+	
+		<action name="trackedEntity"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityListAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-program/trackedEntity.vm</param>
+			<param name="menu">/dhis-web-maintenance-program/menu.vm</param>
+			<param name="javascripts">javascript/trackedEntity.js</param>
+			<param name="requiredAuthorities">F_TRACKED_ENTITY_MANAGEMENT</param>
+		</action>
+
+		<action name="showAddTrackedEntityForm"
+			class="org.hisp.dhis.trackedentity.action.NoAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-program/addTrackedEntity.vm</param>
+			<param name="javascripts">javascript/trackedEntity.js</param>
+			<param name="requiredAuthorities">F_TRACKED_ENTITY_ADD</param>
+		</action>
+
+		<action name="addTrackedEntity"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.AddTrackedEntityAction">
+			<result name="success" type="redirect">trackedEntity.action
+			</result>
+			<param name="requiredAuthorities">F_TRACKED_ENTITY_ADD</param>
+		</action>
+
+		<action name="showUpdateTrackedEntityForm"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-program/updateTrackedEntity.vm</param>
+			<param name="javascripts">javascript/trackedEntity.js</param>
+			<param name="requiredAuthorities">F_TRACKED_ENTITY_UPDATE</param>
+		</action>
+
+		<action name="updateTrackedEntity"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.UpdateTrackedEntityAction">
+			<result name="success" type="redirect">trackedEntity.action
+			</result>
+			<param name="requiredAuthorities">F_TRACKED_ENTITY_UPDATE</param>
+		</action>
+
+		<action name="removeTrackedEntity"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.RemoveTrackedEntityAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+			<param name="requiredAuthorities">F_TRACKED_ENTITY_DELETE</param>
+		</action>
+
+		<action name="getTrackedEntity"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.GetTrackedEntityAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonTrackedEntity.vm
+			</result>
+			<param name="onExceptionReturn">plainTextError</param>
+		</action>
+
+		<action name="validateTrackedEntity"
+			class="org.hisp.dhis.trackedentity.action.trackedentity.ValidateTrackedEntityAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+			<result name="error" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseError.vm
+			</result>
+		</action>
+		
 	</package>
 </struts>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm	2014-01-23 14:18:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm	2014-02-17 15:00:27 +0000
@@ -88,6 +88,19 @@
 			</td>
 			<td></td>
 		</tr>
+		
+		<tr>
+			<td><label for="dataEntryMethod">$i18n.getString( "tracked_entity" ) </label></td>
+			<td>
+				<select id='trackedEntityId' name='trackedEntityId' style="width: 335px;">
+					<option value=''>[$i18n.getString('please_select')]</option>
+					#foreach($trackedEntity in $trackedEntities)
+					<option value='$trackedEntity.id'>$trackedEntity.displayName</option>
+					#end
+				</select>
+			</td>
+			<td></td>
+		</tr>
 
 		<tr name='nonAnonymous'>
 			<th colspan="2" style="width: 590px;">$i18n.getString( "enrollment_details" )</th>
@@ -158,7 +171,7 @@
 		</tr>
 
 		<tr name='nonAnonymous'>
-			<td><label for="relationshipFromA">$i18n.getString("who_is_the_new_relative_to_the_existing_person")</a></td>
+			<td><label for="relationshipFromA">$i18n.getString("who_is_the_new_relative_to_the_existing_tracked_entity_instance")</a></td>
 			<td>
 				<select type='text' id='relationshipFromA' name='relationshipFromA'></select>
 			</td>

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addTrackedEntity.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addTrackedEntity.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addTrackedEntity.vm	2014-02-17 15:00:27 +0000
@@ -0,0 +1,43 @@
+<script>
+	jQuery(document).ready(	function(){
+		validation( 'addTrackedEntityForm', function(form){
+				form.submit();
+		}); 
+		
+		checkValueIsExist( "name", "validateTrackedEntity.action");
+	});	
+</script>
+
+<h3>$i18n.getString( "create_new_tracked_entity" )</h3>
+<form id="addTrackedEntityForm" action="addTrackedEntity.action" method="post" class="inputForm">
+
+<table id="attrTable"> 
+	<thead>
+		<tr><th colspan="2">$i18n.getString( "tracked_entity_details" )</th></tr>
+    </thead>
+	
+    <tbody>
+		<tr>
+			<td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+			<td><input type="text" id="name" name="name" class="{validate:{required:true,rangelength:[2,160]}}"/></td>
+			<td></td>
+		</tr>   
+		
+		<tr>
+			<td><label>$i18n.getString( "description" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+			<td><input type="text" id="description" name="description" class="{validate:{required:true,minlength:2}}"/></td>
+			<td></td>
+		</tr>
+    </tbody>
+
+	<tr>
+		<td></td>
+		<td>
+			<input type="submit" value="$i18n.getString( 'add' )" />
+			<input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='trackedEntity.action'" />
+		</td>
+	</tr>
+</table>
+<span id='message'></span>
+
+</form>   

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm	2014-02-17 15:00:27 +0000
@@ -32,7 +32,7 @@
 			</thead>
 			<tbody id="list">
           #foreach( $attribute in $attributes )
-            <tr id="tr${attribute.id}" data-id="$!attribute.id" data-uid="$!attribute.uid" data-type="attribute" data-name="$encoder.htmlEncode( $!attribute.displayName )"
+            <tr id="tr${attribute.id}" data-id="$!attribute.id" data-uid="$!attribute.uid" data-type="TrackedEntityAttribute" data-name="$encoder.htmlEncode( $!attribute.displayName )"
                 data-can-manage="$security.canManage( $attribute )"
                 data-can-update="$security.canUpdate( $attribute )"
                 data-can-delete="$security.canDelete( $attribute )">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/index.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/index.vm	2014-02-16 13:04:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/index.vm	2014-02-17 15:00:27 +0000
@@ -2,9 +2,15 @@
 
 <ul class="introList">
     #introListImgItem( "attribute.action" "attribute" "patient" )
+<<<<<<< TREE
+    #introListImgItem( "attributeVisitSchedule.action" "tracked_entity_attribute_visit_schedule" "patient" )
+    #introListImgItem( "attributeGroup.action" "tracked_entity_attribute_group" "patient" )
+=======
     #introListImgItem( "attributeVisitSchedule.action" "attribute_visit_schedule" "patient" )
     #introListImgItem( "attributeGroup.action" "attribute_group" "patient" )
+>>>>>>> MERGE-SOURCE
     #introListImgItem( "relationshipType.action" "relationship_type" "patient" )
+    #introListImgItem( "trackedEntity.action" "tracked_entity" "patient" )
     #introListImgItem( "trackedEntityForm.action" "tracked_entity_form" "pivottable" )
     #introListImgItem( "program.action" "program" "program" )
     #introListImgItem( "caseAggregation.action" "aggregation_query_builder" "caseaggregationmapping" )

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/trackedEntity.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/trackedEntity.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/trackedEntity.js	2014-02-17 15:00:27 +0000
@@ -0,0 +1,32 @@
+$(function() {
+  dhis2.contextmenu.makeContextMenu({
+    menuId: 'contextMenu',
+    menuItemActiveClass: 'contextMenuItemActive'
+  });
+});
+
+// -----------------------------------------------------------------------------
+// View details
+// -----------------------------------------------------------------------------
+
+function showUpdateTrackedEntityForm( context ) {
+  location.href = 'showUpdateTrackedEntityForm.action?id=' + context.id;
+}
+
+function showTrackedEntityDetails( context ) {
+  jQuery.getJSON('getTrackedEntity.action', { id: context.id },
+    function( json ) {
+      setInnerHTML('nameField', json.trackedEntity.name);
+      setInnerHTML('descriptionField', json.trackedEntity.description);
+
+      showDetails();
+    });
+}
+
+// -----------------------------------------------------------------------------
+// Remove Attribute
+// -----------------------------------------------------------------------------
+
+function removeTrackedEntity( context ) {
+  removeItem(context.id, context.name, i18n_confirm_delete, 'removeTrackedEntity.action');
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/menu.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/menu.vm	2014-02-10 10:37:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/menu.vm	2014-02-17 15:00:27 +0000
@@ -4,6 +4,7 @@
 	<li><a href="attributeVisitSchedule.action">$i18n.getString( "tracked_entity_attribute_visit_schedule" )</a></li>
 	<li><a href="attributeGroup.action">$i18n.getString( "tracked_entity_attribute_group" )</a></li>
 	<li><a href="relationshipType.action">$i18n.getString( "relationship_type" )</a></li>
+	<li><a href="trackedEntity.action">$i18n.getString( "tracked_entity" )</a></li>
 	<li><a href="trackedEntityForm.action">$i18n.getString( "tracked_entity_form" )</a></li>
 </ul>
 

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/trackedEntity.vm	2014-02-17 15:00:27 +0000
@@ -0,0 +1,60 @@
+
+<h3>$i18n.getString( "tracked_entity_management" )</h3>
+
+<div id="contextMenu" class="contextMenu">
+  <ul id="contextMenuItems" class="contextMenuItems">
+    <li><a data-target-fn="showUpdateTrackedEntityForm"><i class="fa fa-edit"></i>&nbsp;&nbsp;$i18n.getString( "edit" )</a></li>
+    <li><a data-target-fn="translateWithContext"><i class="fa fa-globe"></i>&nbsp;&nbsp;$i18n.getString( "translation_translate" )</a></li>
+    <li><a data-target-fn="removeTrackedEntity"><i class="fa fa-trash-o"></i>&nbsp;&nbsp;$i18n.getString( "remove" )</a></li>
+    <li><a data-target-fn="showTrackedEntityDetails"><i class="fa fa-info-circle"></i>&nbsp;&nbsp;$i18n.getString( "show_details" )</a></li>
+  </ul>
+</div>
+
+<table class="mainPageTable">
+  <tr>
+    <td style="vertical-align:top">
+		<table width="100%">
+			<tr>
+				<td>
+					$i18n.getString( "filter_by_name" ): <input type="text" onkeyup="filterValues( this.value , 1)" style="width:250px"/>
+				</td>
+				<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddTrackedEntityForm.action'" style="width:70px"></td>				
+			</tr>
+		</table>
+			
+		<table class="listTable">
+			<col>          
+			<thead>
+			  <tr>
+				<th>$i18n.getString( "name" )</th>
+			  </tr>
+			</thead>
+			<tbody id="list">
+          #foreach( $trackedEntity in $trackedEntities )
+            <tr id="tr${trackedEntity.id}" data-id="$!trackedEntity.id" 
+				data-uid="$!trackedEntity.uid" data-type="TrackedEntity" 
+				data-name="$encoder.htmlEncode( $!trackedEntity.displayName )"
+                data-can-manage="$security.canManage( $trackedEntity )"
+                data-can-update="$security.canUpdate( $trackedEntity )"
+                data-can-delete="$security.canDelete( $trackedEntity )">
+                <td>$encoder.htmlEncode( $!trackedEntity.displayName )</td>
+            </tr>
+          #end
+      </tbody>
+      </table>
+    </td>
+
+		<td id="detailsData">
+      <div id="detailsArea">
+        <div id="hideDetailsArea">
+          <a href="javascript:hideDetails()" title="$i18n.getString( 'hide_details' )"><img src="../images/hide.png" alt="$i18n.getString( 'hide_details' )"></a>
+				</div>
+        <p><label class="bold">$i18n.getString( "name" ):</label><br><span id="nameField"></span></p>
+        <p><label class="bold">$i18n.getString( "description" ):</label><br><span id="descriptionField"></span></p>
+		</td>
+  </tr>
+</table>
+
+<script type="text/javascript">
+	var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_tracked_entity" ) , "'" )';
+</script>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm	2014-02-17 15:00:27 +0000
@@ -86,6 +86,19 @@
 		</tr>
 		
 		<tr>
+			<td><label for="dataEntryMethod">$i18n.getString( "tracked_entity" ) </label></td>
+			<td>
+				<select id='trackedEntityId' name='trackedEntityId' style="width: 335px;">
+					<option value=''>[$i18n.getString('please_select')]</option>
+					#foreach($trackedEntity in $trackedEntities)
+					<option value='$trackedEntity.id' #if($trackedEntity.id==$program.trackedEntity.id) selected #end >$trackedEntity.displayName</option>
+					#end
+				</select>
+			</td>
+			<td></td>
+		</tr>
+		
+		<tr>
 			<td><label for="version">$i18n.getString( "version" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
 			<td><input type="text" id="version" name="version" style="width: 330px;" value="$program.version" class="{validate:{required:true,integer:true}}"></td>
 			<td></td>
@@ -160,7 +173,7 @@
 		</tr>
 		
 		<tr name='nonAnonymous'>
-			<td><label for="relationshipFromA">$i18n.getString("who_is_the_new_relative_to_the_existing_person")</label></td>
+			<td><label for="relationshipFromA">$i18n.getString("who_is_the_new_relative_to_the_existing_tracked_entity_instance")</label></td>
 			<td>
 				<select id='relationshipFromA' name='relationshipFromA'>
 					#if($!program.relationshipType)

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateTrackedEntity.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateTrackedEntity.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateTrackedEntity.vm	2014-02-17 15:00:27 +0000
@@ -0,0 +1,43 @@
+<script>
+	jQuery(document).ready(	function(){
+		validation( 'updateTrackedEntityForm', function(form){
+				form.submit();
+		});
+		
+		checkValueIsExist( "name", "validateTrackedEntity.action", {id:getFieldValue('id')});
+	});	
+</script>
+
+<h3>$i18n.getString( "edit_tracked_entity" )</h3>
+<form id="updateTrackedEntityForm" action="updateTrackedEntity.action" method="post" class="inputForm">
+
+<input type='hidden' id='id' name='id' value='$trackedEntity.id'/>
+<table id="attrTable"> 
+	<thead>
+		<tr><th colspan="2">$i18n.getString( "tracked_entity_details" )</th></tr>
+    </thead>
+	
+    <tbody>
+		<tr>
+			<td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+			<td><input type="text" id="name" name="name" class="{validate:{required:true,rangelength:[2,160]}}" value='$trackedEntity.name' /></td>
+			<td></td>
+		</tr>   
+		
+		<tr>
+			<td><label>$i18n.getString( "description" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+			<td><input type="text" id="description" name="description" class="{validate:{required:true,minlength:2}}" value='$trackedEntity.description' /></td>
+			<td></td>
+		</tr>
+    </tbody>
+
+	<tr>
+		<td></td>
+		<td>
+			<input type="submit" value="$i18n.getString( 'update' )" />
+			<input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='trackedEntity.action'" />
+		</td>
+	</tr>
+</table>
+
+</form>