← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14703: Fixed bug - The programs which are assigned to orgunit-groups doesn't work properly.

 

------------------------------------------------------------
revno: 14703
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-04-06 22:48:31 +0700
message:
  Fixed bug - The programs which are assigned to orgunit-groups doesn't work properly.
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/ProgramStore.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/MultiDataEntrySelectAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageInstanceCompletenessAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveAttributeAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.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/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addSingleEventRegistration.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addTrackedEntityInstanceForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingSelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.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-03-21 07:19:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2014-04-06 15:48:31 +0000
@@ -121,8 +121,8 @@
     private Set<OrganisationUnitGroup> organisationUnitGroups = new HashSet<OrganisationUnitGroup>();
 
     /**
-     * Allow enrolling trackedEntity to all orgunit no matter what the program is
-     * assigned for the orgunit or not
+     * Allow enrolling trackedEntity to all orgunit no matter what the program
+     * is assigned for the orgunit or not
      */
     private Boolean displayOnAllOrgunit = true;
 
@@ -173,10 +173,10 @@
                 return programAttribute;
             }
         }
-        
+
         return null;
     }
-    
+
     /**
      * Returns all data elements which are part of the stages of this program.
      */

=== 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	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStore.java	2014-04-06 15:48:31 +0000
@@ -57,6 +57,15 @@
     /**
      * Get {@link Program} assigned to an {@link OrganisationUnit} by a type
      * 
+     * @param organisationUnit Where programs assigned
+     * 
+     * @return Program list by a type specified
+     */
+    Collection<Program> get( OrganisationUnit organisationUnit );
+
+    /**
+     * Get {@link Program} assigned to an {@link OrganisationUnit} by a type
+     * 
      * @param type The type of program. There are three types, include Multi
      *        events with registration, Single event with registration and
      *        Single event without registration
@@ -103,5 +112,5 @@
      * @param trackedEntity {@link TrackedEntity}
      */
     Collection<Program> getByTrackedEntity( TrackedEntity trackedEntity );
-    
+
 }

=== 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-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2014-04-06 15:48:31 +0000
@@ -28,20 +28,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
 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;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.hisp.dhis.i18n.I18nUtils.i18n;
-
 /**
  * @author Abyot Asalefew
  * @version $Id$
@@ -111,25 +110,21 @@
     @Override
     public Collection<Program> getPrograms( OrganisationUnit organisationUnit )
     {
-        Set<Program> programs = new HashSet<Program>();
-
-        for ( Program program : getAllPrograms() )
-        {
-            Set<OrganisationUnitGroup> orgunitGroups = program.getOrganisationUnitGroups();
-            for ( OrganisationUnitGroup orgunitGroup : orgunitGroups )
-            {
-                if ( orgunitGroup.getMembers().contains( organisationUnit ) )
-                {
-                    programs.add( program );
-                }
-            }
-            if ( program.getOrganisationUnits().contains( organisationUnit ) )
-            {
-                programs.add( program );
-            }
-        }
-
-        return i18n( i18nService, programs );
+        /*
+         * Set<Program> programs = new HashSet<Program>();
+         * 
+         * for ( Program program : getAllPrograms() ) {
+         * Set<OrganisationUnitGroup> orgunitGroups =
+         * program.getOrganisationUnitGroups(); for ( OrganisationUnitGroup
+         * orgunitGroup : orgunitGroups ) { if (
+         * orgunitGroup.getMembers().contains( organisationUnit ) ) {
+         * programs.add( program ); } } if (
+         * program.getOrganisationUnits().contains( organisationUnit ) ) {
+         * programs.add( program ); } }
+         * 
+         * return i18n( i18nService, programs );
+         */
+        return i18n( i18nService, programStore.get( organisationUnit ) );
     }
 
     @Override
@@ -157,7 +152,7 @@
     @Override
     public Collection<Program> getPrograms( int type, OrganisationUnit orgunit )
     {
-        return i18n( i18nService, programStore.get( type, orgunit ) );
+        return i18n( i18nService, getPrograms( type, orgunit ) );
     }
 
     @Override

=== 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-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2014-04-06 15:48:31 +0000
@@ -82,13 +82,44 @@
 
     @SuppressWarnings( "unchecked" )
     @Override
+    public Collection<Program> get( OrganisationUnit organisationUnit )
+    {
+        Criteria criteria = getCriteria();
+        criteria.createAlias( "organisationUnits", "orgunit" );
+        criteria.createAlias( "organisationUnitGroups", "orgunitGroup" );
+        criteria.createAlias( "orgunitGroup.members", "orgunitMembers" );
+        criteria.add( Restrictions.or( Restrictions.eq( "orgunit.id", organisationUnit.getId() ),
+            Restrictions.eq( "orgunitMembers.id", organisationUnit.getId() ) ) );
+        return criteria.list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    @Override
     public Collection<Program> get( int type, OrganisationUnit organisationUnit )
     {
-        Criteria criteria = getCriteria();
-        criteria.createAlias( "organisationUnits", "orgunit" );
-        criteria.add( Restrictions.eq( "type", type ) );
-        criteria.add( Restrictions.eq( "orgunit.id", organisationUnit.getId() ) );
-        return criteria.list();
+        Criteria criteria1 = getCriteria();
+        criteria1.createAlias( "organisationUnits", "orgunit" );
+        criteria1.add( Restrictions.eq( "type", type ) );
+        criteria1.add( Restrictions.eq( "orgunit.id", organisationUnit.getId() ) );
+
+        Criteria criteria2 = getCriteria();
+        criteria2.createAlias( "organisationUnitGroups", "orgunitGroup" );
+        criteria2.createAlias( "orgunitGroup.members", "orgunitMember" );
+        criteria2.add( Restrictions.eq( "type", type ) );
+        criteria2.add( Restrictions.eq( "orgunitMember.id", organisationUnit.getId() ) );
+
+        Collection<Program> programs = new HashSet<Program>();
+        if ( criteria1.list() != null )
+        {
+            programs.addAll( criteria1.list() );
+        }
+
+        if ( criteria2.list() != null )
+        {
+            programs.addAll( criteria2.list() );
+        }
+
+        return programs;
     }
 
     @Override
@@ -147,16 +178,40 @@
     @SuppressWarnings( "unchecked" )
     public Collection<Program> getProgramsByDisplayOnAllOrgunit( boolean displayOnAllOrgunit, OrganisationUnit orgunit )
     {
-        Criteria criteria = getCriteria();
-        criteria.add( Restrictions.eq( "displayOnAllOrgunit", displayOnAllOrgunit ) );
+        Collection<Program> programs = new HashSet<Program>();
 
         if ( orgunit != null )
         {
-            criteria.createAlias( "organisationUnits", "orgunit" );
-            criteria.add( Restrictions.eq( "orgunit.id", orgunit.getId() ) );
-        }
-
-        return criteria.list();
+            Criteria criteria1 = getCriteria();
+            criteria1.add( Restrictions.eq( "displayOnAllOrgunit", displayOnAllOrgunit ) );
+            criteria1.createAlias( "organisationUnits", "orgunit" );
+            criteria1.add( Restrictions.eq( "orgunit.id", orgunit.getId() ) );
+
+            Criteria criteria2 = getCriteria();
+            criteria1.add( Restrictions.eq( "displayOnAllOrgunit", displayOnAllOrgunit ) );
+            criteria2.createAlias( "organisationUnitGroups", "orgunitGroup" );
+            criteria2.createAlias( "orgunitGroup.members", "orgunitMember" );
+            criteria2.add( Restrictions.eq( "orgunitMember.id", orgunit.getId() ) );
+
+            if ( criteria1.list() != null )
+            {
+                programs.addAll( criteria1.list() );
+            }
+
+            if ( criteria2.list() != null )
+            {
+                programs.addAll( criteria2.list() );
+            }
+        }
+        else
+        {
+            Criteria criteria = getCriteria();
+            criteria.add( Restrictions.eq( "displayOnAllOrgunit", displayOnAllOrgunit ) );
+
+            programs = criteria.list();
+        }
+
+        return programs;
     }
 
     @Override

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java	2014-04-06 15:48:31 +0000
@@ -101,9 +101,9 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2014-04-06 15:48:31 +0000
@@ -95,9 +95,9 @@
     // Input/output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2014-04-06 15:48:31 +0000
@@ -93,9 +93,9 @@
         this.entityInstanceId = entityInstanceId;
     }
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/MultiDataEntrySelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/MultiDataEntrySelectAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/MultiDataEntrySelectAction.java	2014-04-06 15:48:31 +0000
@@ -79,14 +79,14 @@
         return organisationUnit;
     }
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }
 
-    public Integer getProgramId()
+    public String getProgramId()
     {
         return programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageInstanceCompletenessAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageInstanceCompletenessAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageInstanceCompletenessAction.java	2014-04-06 15:48:31 +0000
@@ -93,9 +93,9 @@
     // Input/output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveExecutionDateAction.java	2014-04-06 15:48:31 +0000
@@ -132,9 +132,9 @@
         this.programStageInstanceId = programStageInstanceId;
     }
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValuesAction.java	2014-04-06 15:48:31 +0000
@@ -121,9 +121,9 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java	2014-03-20 10:17:37 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java	2014-04-06 15:48:31 +0000
@@ -127,7 +127,7 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
     private Collection<TrackedEntityAttribute> noGroupAttributes = new HashSet<TrackedEntityAttribute>();
 
@@ -236,7 +236,7 @@
         return customRegistrationForm;
     }
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== 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-03-27 14:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
@@ -61,230 +61,216 @@
  * @author Abyot Asalefew Gizaw
  * @version $Id$
  */
-public class AddTrackedEntityInstanceAction
-    implements Action
-{
-    public static final String PREFIX_ATTRIBUTE = "attr";
-
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private TrackedEntityInstanceService entityInstanceService;
-
-    private TrackedEntityAttributeService attributeService;
-
-    private RelationshipTypeService relationshipTypeService;
-
-    private RelationshipService relationshipService;
-
-    private OrganisationUnitSelectionManager selectionManager;
-
-    @Autowired
-    private TrackedEntityService trackedEntityService;
-
-    @Autowired
-    private ProgramService programService;
-
-    @Autowired
-    private TrackedEntityAttributeValueService attributeValueService;
-
-    private I18nFormat format;
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer representativeId;
-
-    private Integer relationshipTypeId;
-
-    private Integer relationshipId;
-
-    private boolean relationshipFromA;
-
-    private Integer trackedEntityId;
-
-    private Integer programId;
-
-    private String message;
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-    {
-        OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
-        TrackedEntityInstance entityInstance = new TrackedEntityInstance();
-        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 );
-
-        // ---------------------------------------------------------------------
-        // Tracked Entity Attributes
-        // ---------------------------------------------------------------------
-
-        TrackedEntityInstance relationship = null;
-
-        if ( relationshipId != null && relationshipTypeId != null )
-        {
-            relationship = entityInstanceService.getTrackedEntityInstance( relationshipId );
-        }
-
-        HttpServletRequest request = ServletActionContext.getRequest();
-
-        Collection<TrackedEntityAttribute> attributes = attributeService.getAllTrackedEntityAttributes();
-
-        Set<TrackedEntityAttributeValue> attributeValues = new HashSet<TrackedEntityAttributeValue>();
-
-        TrackedEntityAttributeValue attributeValue = null;
-
-        if ( attributes != null && attributes.size() > 0 )
-        {
-            for ( TrackedEntityAttribute attribute : attributes )
-            {
-                String value = request.getParameter( PREFIX_ATTRIBUTE + attribute.getId() );
-                if ( StringUtils.isNotBlank( value ) )
-                {
-                    attributeValue = new TrackedEntityAttributeValue();
-                    attributeValue.setEntityInstance( entityInstance );
-                    attributeValue.setAttribute( attribute );
-
-                    if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_AGE ) )
-                    {
-                        value = format.formatDate( TrackedEntityAttribute.getDateFromAge( Integer.parseInt( value ) ) );
-                    }
-
-                    attributeValue.setValue( value.trim() );
-                    attributeValues.add( attributeValue );
-                }
-                else if ( attribute.getInherit() && relationship != null )
-                {
-                    TrackedEntityAttributeValue av = attributeValueService.getTrackedEntityAttributeValue(
-                        relationship, attribute );
-                    if ( av != null )
-                    {
-                        attributeValue = new TrackedEntityAttributeValue();
-                        attributeValue.setEntityInstance( entityInstance );
-                        attributeValue.setAttribute( attribute );
-                        attributeValue.setValue( av.getValue() );
-                        
-                        attributeValues.add( attributeValue );
-                    }
-                }
-            }
-        }
-
-        int entityInstanceId = entityInstanceService.createTrackedEntityInstance( entityInstance, representativeId,
-            relationshipTypeId, attributeValues );
-
-        // -------------------------------------------------------------------------
-        // Create relationship
-        // -------------------------------------------------------------------------
-
-        if ( relationship != null )
-        {
-            Relationship rel = new Relationship();
-            if ( relationshipFromA )
-            {
-                rel.setEntityInstanceA( relationship );
-                rel.setEntityInstanceB( entityInstance );
-            }
-            else
-            {
-                rel.setEntityInstanceA( entityInstance );
-                rel.setEntityInstanceB( relationship );
-            }
-            if ( relationshipTypeId != null )
-            {
-                RelationshipType relType = relationshipTypeService.getRelationshipType( relationshipTypeId );
-                if ( relType != null )
-                {
-                    rel.setRelationshipType( relType );
-                    relationshipService.addRelationship( rel );
-                }
-            }
-        }
-
-        message = entityInstance.getUid() + "_" + entityInstanceId;
-
-        return SUCCESS;
-    }
-
-    // -----------------------------------------------------------------------------
-    // Getter/Setter
-    // -----------------------------------------------------------------------------
-
-    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
-    {
-        this.relationshipTypeService = relationshipTypeService;
-    }
-
-    public void setRelationshipId( Integer relationshipId )
-    {
-        this.relationshipId = relationshipId;
-    }
-
-    public void setRelationshipFromA( boolean relationshipFromA )
-    {
-        this.relationshipFromA = relationshipFromA;
-    }
-
-    public void setRelationshipService( RelationshipService relationshipService )
-    {
-        this.relationshipService = relationshipService;
-    }
-
-    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
-    {
-        this.selectionManager = selectionManager;
-    }
-
-    public void setTrackedEntityId( Integer trackedEntityId )
-    {
-        this.trackedEntityId = trackedEntityId;
-    }
-
-    public String getMessage()
-    {
-        return message;
-    }
-
-    public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
-    {
-        this.entityInstanceService = entityInstanceService;
-    }
-
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
-    public void setAttributeService( TrackedEntityAttributeService attributeService )
-    {
-        this.attributeService = attributeService;
-    }
-
-    public void setRepresentativeId( Integer representativeId )
-    {
-        this.representativeId = representativeId;
-    }
-
-    public void setRelationshipTypeId( Integer relationshipTypeId )
-    {
-        this.relationshipTypeId = relationshipTypeId;
-    }
+public class AddTrackedEntityInstanceAction implements Action {
+	public static final String PREFIX_ATTRIBUTE = "attr";
+
+	// -------------------------------------------------------------------------
+	// Dependencies
+	// -------------------------------------------------------------------------
+
+	private TrackedEntityInstanceService entityInstanceService;
+
+	private TrackedEntityAttributeService attributeService;
+
+	private RelationshipTypeService relationshipTypeService;
+
+	private RelationshipService relationshipService;
+
+	private OrganisationUnitSelectionManager selectionManager;
+
+	@Autowired
+	private TrackedEntityService trackedEntityService;
+
+	@Autowired
+	private ProgramService programService;
+
+	@Autowired
+	private TrackedEntityAttributeValueService attributeValueService;
+
+	private I18nFormat format;
+
+	// -------------------------------------------------------------------------
+	// Input
+	// -------------------------------------------------------------------------
+
+	private Integer representativeId;
+
+	private Integer relationshipTypeId;
+
+	private Integer relationshipId;
+
+	private boolean relationshipFromA;
+
+	private Integer trackedEntityId;
+
+	private String programId;
+
+	private String message;
+
+	// -------------------------------------------------------------------------
+	// Action implementation
+	// -------------------------------------------------------------------------
+
+	public String execute() {
+		OrganisationUnit organisationUnit = selectionManager
+				.getSelectedOrganisationUnit();
+		TrackedEntityInstance entityInstance = new TrackedEntityInstance();
+		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);
+
+		// ---------------------------------------------------------------------
+		// Tracked Entity Attributes
+		// ---------------------------------------------------------------------
+
+		TrackedEntityInstance relationship = null;
+
+		if (relationshipId != null && relationshipTypeId != null) {
+			relationship = entityInstanceService
+					.getTrackedEntityInstance(relationshipId);
+		}
+
+		HttpServletRequest request = ServletActionContext.getRequest();
+
+		Collection<TrackedEntityAttribute> attributes = attributeService
+				.getAllTrackedEntityAttributes();
+
+		Set<TrackedEntityAttributeValue> attributeValues = new HashSet<TrackedEntityAttributeValue>();
+
+		TrackedEntityAttributeValue attributeValue = null;
+
+		if (attributes != null && attributes.size() > 0) {
+			for (TrackedEntityAttribute attribute : attributes) {
+				String value = request.getParameter(PREFIX_ATTRIBUTE
+						+ attribute.getId());
+				if (StringUtils.isNotBlank(value)) {
+					attributeValue = new TrackedEntityAttributeValue();
+					attributeValue.setEntityInstance(entityInstance);
+					attributeValue.setAttribute(attribute);
+
+					if (attribute.getValueType().equals(
+							TrackedEntityAttribute.TYPE_AGE)) {
+						value = format.formatDate(TrackedEntityAttribute
+								.getDateFromAge(Integer.parseInt(value)));
+					}
+
+					attributeValue.setValue(value.trim());
+					attributeValues.add(attributeValue);
+				} else if (attribute.getInherit() && relationship != null) {
+					TrackedEntityAttributeValue av = attributeValueService
+							.getTrackedEntityAttributeValue(relationship,
+									attribute);
+					if (av != null) {
+						attributeValue = new TrackedEntityAttributeValue();
+						attributeValue.setEntityInstance(entityInstance);
+						attributeValue.setAttribute(attribute);
+						attributeValue.setValue(av.getValue());
+
+						attributeValues.add(attributeValue);
+					}
+				}
+			}
+		}
+
+		int entityInstanceId = entityInstanceService
+				.createTrackedEntityInstance(entityInstance, representativeId,
+						relationshipTypeId, attributeValues);
+
+		// -------------------------------------------------------------------------
+		// Create relationship
+		// -------------------------------------------------------------------------
+
+		if (relationship != null) {
+			Relationship rel = new Relationship();
+			if (relationshipFromA) {
+				rel.setEntityInstanceA(relationship);
+				rel.setEntityInstanceB(entityInstance);
+			} else {
+				rel.setEntityInstanceA(entityInstance);
+				rel.setEntityInstanceB(relationship);
+			}
+			if (relationshipTypeId != null) {
+				RelationshipType relType = relationshipTypeService
+						.getRelationshipType(relationshipTypeId);
+				if (relType != null) {
+					rel.setRelationshipType(relType);
+					relationshipService.addRelationship(rel);
+				}
+			}
+		}
+
+		message = entityInstance.getUid() + "_" + entityInstanceId;
+
+		return SUCCESS;
+	}
+
+	// -----------------------------------------------------------------------------
+	// Getter/Setter
+	// -----------------------------------------------------------------------------
+
+	public void setRelationshipTypeService(
+			RelationshipTypeService relationshipTypeService) {
+		this.relationshipTypeService = relationshipTypeService;
+	}
+
+	public void setRelationshipId(Integer relationshipId) {
+		this.relationshipId = relationshipId;
+	}
+
+	public void setRelationshipFromA(boolean relationshipFromA) {
+		this.relationshipFromA = relationshipFromA;
+	}
+
+	public void setRelationshipService(RelationshipService relationshipService) {
+		this.relationshipService = relationshipService;
+	}
+
+	public void setSelectionManager(
+			OrganisationUnitSelectionManager selectionManager) {
+		this.selectionManager = selectionManager;
+	}
+
+	public void setTrackedEntityId(Integer trackedEntityId) {
+		this.trackedEntityId = trackedEntityId;
+	}
+
+	public void setProgramId(String programId) {
+		this.programId = programId;
+	}
+
+	public String getMessage() {
+		return message;
+	}
+
+	public void setEntityInstanceService(
+			TrackedEntityInstanceService entityInstanceService) {
+		this.entityInstanceService = entityInstanceService;
+	}
+
+	public void setFormat(I18nFormat format) {
+		this.format = format;
+	}
+
+	public void setAttributeService(
+			TrackedEntityAttributeService attributeService) {
+		this.attributeService = attributeService;
+	}
+
+	public void setRepresentativeId(Integer representativeId) {
+		this.representativeId = representativeId;
+	}
+
+	public void setRelationshipTypeId(Integer relationshipTypeId) {
+		this.relationshipTypeId = relationshipTypeId;
+	}
 
 }

=== 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-03-31 16:44:18 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
@@ -68,334 +68,303 @@
  * @author Abyot Asalefew Gizaw
  * @version $Id$
  */
-public class GetTrackedEntityInstanceAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private TrackedEntityInstanceService entityInstanceService;
-
-    private ProgramService programService;
-
-    private RelationshipTypeService relationshipTypeService;
-
-    private TrackedEntityFormService trackedEntityFormService;
-
-    private TrackedEntityAttributeGroupService attributeGroupService;
-
-    private TrackedEntityAttributeService attributeService;
-
-    @Autowired
-    private TrackedEntityService trackedEntityService;
-
-    @Autowired
-    private ProgramInstanceService programInstanceService;
-
-    private I18n i18n;
-
-    private I18nFormat format;
-
-    // -------------------------------------------------------------------------
-    // Input/Output
-    // -------------------------------------------------------------------------
-
-    private Collection<RelationshipType> relationshipTypes;
-
-    private String id;
-
-    private TrackedEntityInstance entityInstance;
-
-    private Collection<Program> programs;
-
-    private Map<Integer, String> attributeValueMap = new HashMap<Integer, String>();
-
-    private Collection<TrackedEntityAttribute> noGroupAttributes = new HashSet<TrackedEntityAttribute>();
-
-    private List<TrackedEntityAttributeGroup> attributeGroups;
-
-    private Relationship relationship;
-
-    private Map<Integer, Collection<TrackedEntityAttribute>> attributeGroupsMap = new HashMap<Integer, Collection<TrackedEntityAttribute>>();
-
-    private Collection<User> healthWorkers;
-
-    private Integer programId;
-
-    private Map<String, List<TrackedEntityAttribute>> attributesMap = new HashMap<String, List<TrackedEntityAttribute>>();
-
-    private TrackedEntityForm trackedEntityForm;
-
-    public void setProgramId( Integer programId )
-    {
-        this.programId = programId;
-    }
-
-    private String customRegistrationForm;
-
-    public String getCustomRegistrationForm()
-    {
-        return customRegistrationForm;
-    }
-
-    private Integer programStageInstanceId;
-
-    public Integer getProgramStageInstanceId()
-    {
-        return programStageInstanceId;
-    }
-
-    public void setProgramStageInstanceId( Integer programStageInstanceId )
-    {
-        this.programStageInstanceId = programStageInstanceId;
-    }
-
-    public void setAttributeService( TrackedEntityAttributeService attributeService )
-    {
-        this.attributeService = attributeService;
-    }
-
-    public Map<String, List<TrackedEntityAttribute>> getAttributesMap()
-    {
-        return attributesMap;
-    }
-
-    public TrackedEntityForm getTrackedEntityForm()
-    {
-        return trackedEntityForm;
-    }
-
-    private List<TrackedEntity> trackedEntities;
-
-    public List<TrackedEntity> getTrackedEntities()
-    {
-        return trackedEntities;
-    }
-
-    private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
-
-    public Map<Integer, Boolean> getMandatoryMap()
-    {
-        return mandatoryMap;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
-        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
-        entityInstance = entityInstanceService.getTrackedEntityInstance( id );
-
-        healthWorkers = entityInstance.getOrganisationUnit().getUsers();
-        Program program = null;
-
-        if ( programId == null )
-        {
-            trackedEntityForm = trackedEntityFormService.getCommonTrackedEntityForm();
-
-            if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
-            {
-                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
-                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, entityInstance,
-                    null, i18n, format );
-            }
-        }
-        else
-        {
-            program = programService.getProgram( programId );
-            trackedEntityForm = trackedEntityFormService.getTrackedEntityForm( program );
-
-            Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( entityInstance,
-                program, ProgramInstance.STATUS_ACTIVE );
-            ProgramInstance programIntance = null;
-            if ( programInstances != null )
-            {
-                programIntance = programInstances.iterator().next();
-            }
-            if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
-            {
-                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
-                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, entityInstance,
-                    programIntance, i18n, format );
-            }
-        }
-
-        List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
-
-        if ( customRegistrationForm == null )
-        {
-            attributeGroups = new ArrayList<TrackedEntityAttributeGroup>(
-                attributeGroupService.getAllTrackedEntityAttributeGroups() );
-            Collections.sort( attributeGroups, new TrackedEntityAttributeGroupSortOrderComparator() );
-
-            if ( program == null )
-            {
-                attributes = new ArrayList<TrackedEntityAttribute>( attributeService.getAllTrackedEntityAttributes() );
-                Collection<Program> programs = programService.getAllPrograms();
-                for ( Program p : programs )
-                {
-                    for ( ProgramTrackedEntityAttribute programAttribute : p.getAttributes() )
-                    {
-                        if ( !programAttribute.isDisplayInList() )
-                        {
-                            attributes.remove( programAttribute.getAttribute() );
-                        }
-                    }
-                }
-
-                for ( TrackedEntityAttribute attribute : attributes )
-                {
-                    mandatoryMap.put( attribute.getId(), false );
-                }
-            }
-            else
-            {
-                attributes = program.getTrackedEntityAttributes();
-                for ( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() )
-                {
-                    mandatoryMap.put( programAttribute.getAttribute().getId(), programAttribute.isMandatory() );
-                }
-            }
-
-            for ( TrackedEntityAttribute attribute : attributes )
-            {
-                TrackedEntityAttributeGroup attributeGroup = attribute.getAttributeGroup();
-                String groupName = (attributeGroup == null) ? "" : attributeGroup.getDisplayName();
-                if ( attributesMap.containsKey( groupName ) )
-                {
-                    List<TrackedEntityAttribute> attrs = attributesMap.get( groupName );
-                    attrs.add( attribute );
-                }
-                else
-                {
-                    List<TrackedEntityAttribute> attrs = new ArrayList<TrackedEntityAttribute>();
-                    attrs.add( attribute );
-                    attributesMap.put( groupName, attrs );
-                }
-            }
-
-        }
-
-        // -------------------------------------------------------------------------
-        // Get attribute values
-        // -------------------------------------------------------------------------
-
-        Collection<TrackedEntityAttributeValue> attributeValues = entityInstance.getAttributeValues();
-
-        for ( TrackedEntityAttributeValue attributeValue : attributeValues )
-        {
-            String value = attributeValue.getValue();
-
-            if ( attributeValue.getAttribute().getValueType().equals( TrackedEntityAttribute.TYPE_AGE ) )
-            {
-                Date date = format.parseDate( value );
-                value = TrackedEntityAttribute.getAgeFromDate( date ) + "";
-            }
-
-            attributeValueMap.put( attributeValue.getAttribute().getId(), value );
-        }
-
-        return SUCCESS;
-
-    }
-
-    // -----------------------------------------------------------------------------
-    // Getter / Setter
-    // -----------------------------------------------------------------------------
-
-    public void setI18n( I18n i18n )
-    {
-        this.i18n = i18n;
-    }
-
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
-    public Collection<RelationshipType> getRelationshipTypes()
-    {
-        return relationshipTypes;
-    }
-
-    public Collection<User> getHealthWorkers()
-    {
-        return healthWorkers;
-    }
-
-    public Map<Integer, Collection<TrackedEntityAttribute>> getAttributeGroupsMap()
-    {
-        return attributeGroupsMap;
-    }
-
-    public Relationship getRelationship()
-    {
-        return relationship;
-    }
-
-    public void setId( String id )
-    {
-        this.id = id;
-    }
-
-    public TrackedEntityInstance getEntityInstance()
-    {
-        return entityInstance;
-    }
-
-    public Collection<Program> getPrograms()
-    {
-        return programs;
-    }
-
-    public Map<Integer, String> getAttributeValueMap()
-    {
-        return attributeValueMap;
-    }
-
-    public Collection<TrackedEntityAttribute> getNoGroupAttributes()
-    {
-        return noGroupAttributes;
-    }
-
-    public List<TrackedEntityAttributeGroup> getAttributeGroups()
-    {
-        return attributeGroups;
-    }
-
-    public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
-    {
-        this.entityInstanceService = entityInstanceService;
-    }
-
-    public void setProgramService( ProgramService programService )
-    {
-        this.programService = programService;
-    }
-
-    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
-    {
-        this.relationshipTypeService = relationshipTypeService;
-    }
-
-    public void setTrackedEntityFormService( TrackedEntityFormService trackedEntityFormService )
-    {
-        this.trackedEntityFormService = trackedEntityFormService;
-    }
-
-    public void setAttributeGroupService( TrackedEntityAttributeGroupService attributeGroupService )
-    {
-        this.attributeGroupService = attributeGroupService;
-    }
-
-    public void setTrackedEntityForm( TrackedEntityForm trackedEntityForm )
-    {
-        this.trackedEntityForm = trackedEntityForm;
-    }
+public class GetTrackedEntityInstanceAction implements Action {
+	// -------------------------------------------------------------------------
+	// Dependencies
+	// -------------------------------------------------------------------------
+
+	private TrackedEntityInstanceService entityInstanceService;
+
+	public void setEntityInstanceService(
+			TrackedEntityInstanceService entityInstanceService) {
+		this.entityInstanceService = entityInstanceService;
+	}
+
+	private ProgramService programService;
+
+	public void setProgramService(ProgramService programService) {
+		this.programService = programService;
+	}
+
+	private RelationshipTypeService relationshipTypeService;
+
+	public void setRelationshipTypeService(
+			RelationshipTypeService relationshipTypeService) {
+		this.relationshipTypeService = relationshipTypeService;
+	}
+
+	private TrackedEntityFormService trackedEntityFormService;
+
+	public void setTrackedEntityFormService(
+			TrackedEntityFormService trackedEntityFormService) {
+		this.trackedEntityFormService = trackedEntityFormService;
+	}
+
+	private TrackedEntityAttributeGroupService attributeGroupService;
+
+	public void setAttributeGroupService(
+			TrackedEntityAttributeGroupService attributeGroupService) {
+		this.attributeGroupService = attributeGroupService;
+	}
+
+	private TrackedEntityAttributeService attributeService;
+
+	public void setAttributeService(
+			TrackedEntityAttributeService attributeService) {
+		this.attributeService = attributeService;
+	}
+
+	@Autowired
+	private TrackedEntityService trackedEntityService;
+
+	@Autowired
+	private ProgramInstanceService programInstanceService;
+
+	private I18n i18n;
+
+	public void setI18n(I18n i18n) {
+		this.i18n = i18n;
+	}
+
+	private I18nFormat format;
+
+	public void setFormat(I18nFormat format) {
+		this.format = format;
+	}
+
+	// -------------------------------------------------------------------------
+	// Input/Output
+	// -------------------------------------------------------------------------
+
+	private String id;
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	private Collection<RelationshipType> relationshipTypes;
+
+	public Collection<RelationshipType> getRelationshipTypes() {
+		return relationshipTypes;
+	}
+
+	private TrackedEntityInstance entityInstance;
+
+	public TrackedEntityInstance getEntityInstance() {
+		return entityInstance;
+	}
+
+	private Collection<Program> programs;
+
+	public Collection<Program> getPrograms() {
+		return programs;
+	}
+
+	private Map<Integer, String> attributeValueMap = new HashMap<Integer, String>();
+
+	public Map<Integer, String> getAttributeValueMap() {
+		return attributeValueMap;
+	}
+
+	private Collection<TrackedEntityAttribute> noGroupAttributes = new HashSet<TrackedEntityAttribute>();
+
+	public Collection<TrackedEntityAttribute> getNoGroupAttributes() {
+		return noGroupAttributes;
+	}
+
+	private List<TrackedEntityAttributeGroup> attributeGroups;
+
+	public List<TrackedEntityAttributeGroup> getAttributeGroups() {
+		return attributeGroups;
+	}
+
+	private Relationship relationship;
+
+	public Relationship getRelationship() {
+		return relationship;
+	}
+
+	private Map<Integer, Collection<TrackedEntityAttribute>> attributeGroupsMap = new HashMap<Integer, Collection<TrackedEntityAttribute>>();
+
+	public Map<Integer, Collection<TrackedEntityAttribute>> getAttributeGroupsMap() {
+		return attributeGroupsMap;
+	}
+
+	private Collection<User> healthWorkers;
+
+	public Collection<User> getHealthWorkers() {
+		return healthWorkers;
+	}
+
+	public void setTrackedEntityForm(TrackedEntityForm trackedEntityForm) {
+		this.trackedEntityForm = trackedEntityForm;
+	}
+
+	private String programId;
+
+	public void setProgramId(String programId) {
+		this.programId = programId;
+	}
+
+	private Map<String, List<TrackedEntityAttribute>> attributesMap = new HashMap<String, List<TrackedEntityAttribute>>();
+
+	public Map<String, List<TrackedEntityAttribute>> getAttributesMap() {
+		return attributesMap;
+	}
+
+	private TrackedEntityForm trackedEntityForm;
+
+	public TrackedEntityForm getTrackedEntityForm() {
+		return trackedEntityForm;
+	}
+
+	private String customRegistrationForm;
+
+	public String getCustomRegistrationForm() {
+		return customRegistrationForm;
+	}
+
+	private Integer programStageInstanceId;
+
+	public Integer getProgramStageInstanceId() {
+		return programStageInstanceId;
+	}
+
+	public void setProgramStageInstanceId(Integer programStageInstanceId) {
+		this.programStageInstanceId = programStageInstanceId;
+	}
+
+	private List<TrackedEntity> trackedEntities;
+
+	public List<TrackedEntity> getTrackedEntities() {
+		return trackedEntities;
+	}
+
+	private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
+
+	public Map<Integer, Boolean> getMandatoryMap() {
+		return mandatoryMap;
+	}
+
+	// -------------------------------------------------------------------------
+	// Action implementation
+	// -------------------------------------------------------------------------
+
+	public String execute() throws Exception {
+		relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
+		trackedEntities = new ArrayList<TrackedEntity>(
+				trackedEntityService.getAllTrackedEntity());
+		entityInstance = entityInstanceService.getTrackedEntityInstance(id);
+
+		healthWorkers = entityInstance.getOrganisationUnit().getUsers();
+		Program program = null;
+
+		if (programId == null) {
+			trackedEntityForm = trackedEntityFormService
+					.getCommonTrackedEntityForm();
+
+			if (trackedEntityForm != null
+					&& trackedEntityForm.getDataEntryForm() != null) {
+				customRegistrationForm = trackedEntityFormService
+						.prepareDataEntryFormForAdd(trackedEntityForm
+								.getDataEntryForm().getHtmlCode(),
+								trackedEntityForm.getProgram(), healthWorkers,
+								entityInstance, null, i18n, format);
+			}
+		} else {
+			program = programService.getProgram(programId);
+			trackedEntityForm = trackedEntityFormService
+					.getTrackedEntityForm(program);
+
+			Collection<ProgramInstance> programInstances = programInstanceService
+					.getProgramInstances(entityInstance, program,
+							ProgramInstance.STATUS_ACTIVE);
+			ProgramInstance programIntance = null;
+			if (programInstances != null) {
+				programIntance = programInstances.iterator().next();
+			}
+			if (trackedEntityForm != null
+					&& trackedEntityForm.getDataEntryForm() != null) {
+				customRegistrationForm = trackedEntityFormService
+						.prepareDataEntryFormForAdd(trackedEntityForm
+								.getDataEntryForm().getHtmlCode(),
+								trackedEntityForm.getProgram(), healthWorkers,
+								entityInstance, programIntance, i18n, format);
+			}
+		}
+
+		List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
+
+		if (customRegistrationForm == null) {
+			attributeGroups = new ArrayList<TrackedEntityAttributeGroup>(
+					attributeGroupService.getAllTrackedEntityAttributeGroups());
+			Collections.sort(attributeGroups,
+					new TrackedEntityAttributeGroupSortOrderComparator());
+
+			if (program == null) {
+				attributes = new ArrayList<TrackedEntityAttribute>(
+						attributeService.getAllTrackedEntityAttributes());
+				Collection<Program> programs = programService.getAllPrograms();
+				for (Program p : programs) {
+					for (ProgramTrackedEntityAttribute programAttribute : p
+							.getAttributes()) {
+						if (!programAttribute.isDisplayInList()) {
+							attributes.remove(programAttribute.getAttribute());
+						}
+					}
+				}
+
+				for (TrackedEntityAttribute attribute : attributes) {
+					mandatoryMap.put(attribute.getId(), false);
+				}
+			} else {
+				attributes = program.getTrackedEntityAttributes();
+				for (ProgramTrackedEntityAttribute programAttribute : program
+						.getAttributes()) {
+					mandatoryMap.put(programAttribute.getAttribute().getId(),
+							programAttribute.isMandatory());
+				}
+			}
+
+			for (TrackedEntityAttribute attribute : attributes) {
+				TrackedEntityAttributeGroup attributeGroup = attribute
+						.getAttributeGroup();
+				String groupName = (attributeGroup == null) ? ""
+						: attributeGroup.getDisplayName();
+				if (attributesMap.containsKey(groupName)) {
+					List<TrackedEntityAttribute> attrs = attributesMap
+							.get(groupName);
+					attrs.add(attribute);
+				} else {
+					List<TrackedEntityAttribute> attrs = new ArrayList<TrackedEntityAttribute>();
+					attrs.add(attribute);
+					attributesMap.put(groupName, attrs);
+				}
+			}
+
+		}
+
+		// -------------------------------------------------------------------------
+		// Get attribute values
+		// -------------------------------------------------------------------------
+
+		Collection<TrackedEntityAttributeValue> attributeValues = entityInstance
+				.getAttributeValues();
+
+		for (TrackedEntityAttributeValue attributeValue : attributeValues) {
+			String value = attributeValue.getValue();
+
+			if (attributeValue.getAttribute().getValueType()
+					.equals(TrackedEntityAttribute.TYPE_AGE)) {
+				Date date = format.parseDate(value);
+				value = TrackedEntityAttribute.getAgeFromDate(date) + "";
+			}
+
+			attributeValueMap.put(attributeValue.getAttribute().getId(), value);
+		}
+
+		return SUCCESS;
+
+	}
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentAction.java	2014-03-31 16:44:18 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ProgramEnrollmentAction.java	2014-04-06 15:48:31 +0000
@@ -39,6 +39,7 @@
 
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
@@ -215,16 +216,27 @@
 
     private boolean showDataEntry( OrganisationUnit orgunit, Program program, ProgramInstance programInstance )
     {
-        if ( !program.getOrganisationUnits().contains( orgunit ) )
+        Collection<OrganisationUnit> orgunits = new HashSet<OrganisationUnit>();
+        
+        if ( program.getOrganisationUnitGroups().size() > 0 )
+        {
+            for ( OrganisationUnitGroup orgunitGroup : program.getOrganisationUnitGroups() )
+            {
+                orgunits.addAll( orgunitGroup.getMembers() );
+            }
+
+        }
+
+        if ( !orgunits.contains( orgunit ) && !program.getOrganisationUnits().contains( orgunit ) )
         {
             return false;
         }
-        else if ( !program.isSingleEvent() && programInstance == null )
+
+        if ( !program.isSingleEvent() && programInstance == null )
         {
             return false;
         }
 
         return true;
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveAttributeAction.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveAttributeAction.java	2014-04-06 15:48:31 +0000
@@ -72,7 +72,7 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
     private Integer entityInstanceId;
 
@@ -102,12 +102,12 @@
         this.programService = programService;
     }
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }
 
-    public Integer getProgramId()
+    public String getProgramId()
     {
         return programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.java	2014-03-26 14:01:14 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SaveProgramEnrollmentAction.java	2014-04-06 15:48:31 +0000
@@ -110,9 +110,9 @@
         this.entityInstanceId = entityInstanceId;
     }
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== 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-03-20 22:27:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ShowAddTrackedEntityInstanceFormAction.java	2014-04-06 15:48:31 +0000
@@ -139,9 +139,9 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private Integer programId;
+    private String programId;
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== 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-03-28 07:24:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
@@ -55,179 +55,173 @@
  * @author Abyot Asalefew Gizaw
  * @version $Id$
  */
-public class UpdateTrackedEntityInstanceAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private TrackedEntityInstanceService entityInstanceService;
-
-    private TrackedEntityAttributeService attributeService;
-
-    private TrackedEntityAttributeValueService attributeValueService;
-
-    @Autowired
-    private TrackedEntityService trackedEntityService;
-
-    @Autowired
-    private ProgramService programService;
-
-    private I18nFormat format;
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer id;
-
-    private Integer representativeId;
-
-    private Integer relationshipTypeId;
-
-    private Integer trackedEntityId;
-
-    private Integer programId;
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private TrackedEntityInstance entityInstance;
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        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
-        // ---------------------------------------------------------------------
-
-        HttpServletRequest request = ServletActionContext.getRequest();
-
-        Collection<TrackedEntityAttribute> attributes = attributeService.getAllTrackedEntityAttributes();
-
-        List<TrackedEntityAttributeValue> valuesForSave = new ArrayList<TrackedEntityAttributeValue>();
-        List<TrackedEntityAttributeValue> valuesForUpdate = new ArrayList<TrackedEntityAttributeValue>();
-        Collection<TrackedEntityAttributeValue> valuesForDelete = null;
-
-        TrackedEntityAttributeValue attributeValue = null;
-
-        if ( attributes != null && attributes.size() > 0 )
-        {
-            valuesForDelete = attributeValueService.getTrackedEntityAttributeValues( entityInstance );
-
-            for ( TrackedEntityAttribute attribute : attributes )
-            {
-                String value = request.getParameter( AddTrackedEntityInstanceAction.PREFIX_ATTRIBUTE
-                    + attribute.getId() );
-
-                if ( StringUtils.isNotBlank( value ) )
-                {
-                    if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_AGE ) )
-                    {
-                       value = format.formatDate( TrackedEntityAttribute.getDateFromAge( Integer.parseInt( value ) ) );
-                    }
-
-                    attributeValue = attributeValueService.getTrackedEntityAttributeValue( entityInstance, attribute );
-
-                    if ( attributeValue == null )
-                    {
-                        attributeValue = new TrackedEntityAttributeValue();
-                        attributeValue.setEntityInstance( entityInstance );
-                        attributeValue.setAttribute( attribute );
-                        attributeValue.setValue( value.trim() );
-
-                        valuesForSave.add( attributeValue );
-                    }
-                    else
-                    {
-                        attributeValue.setValue( value.trim() );
-
-                        valuesForUpdate.add( attributeValue );
-                        valuesForDelete.remove( attributeValue );
-                    }
-                }
-            }
-        }
-
-        entityInstanceService.updateTrackedEntityInstance( entityInstance, representativeId, relationshipTypeId,
-            valuesForSave, valuesForUpdate, valuesForDelete );
-
-        return SUCCESS;
-    }
-
-    // -------------------------------------------------------------------------
-    // Getter/Setter
-    // -------------------------------------------------------------------------
-
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
-    public void setTrackedEntityId( Integer trackedEntityId )
-    {
-        this.trackedEntityId = trackedEntityId;
-    }
-
-    public void setTrackedEntityService( TrackedEntityService trackedEntityService )
-    {
-        this.trackedEntityService = trackedEntityService;
-    }
-
-    public void setentityInstanceService( TrackedEntityInstanceService entityInstanceService )
-    {
-        this.entityInstanceService = entityInstanceService;
-    }
-
-    public void setattributeService( TrackedEntityAttributeService attributeService )
-    {
-        this.attributeService = attributeService;
-    }
-
-    public void setattributeValueService( TrackedEntityAttributeValueService attributeValueService )
-    {
-        this.attributeValueService = attributeValueService;
-    }
-
-    public void setId( Integer id )
-    {
-        this.id = id;
-    }
-
-    public TrackedEntityInstance getEntityInstance()
-    {
-        return entityInstance;
-    }
-
-    public void setRepresentativeId( Integer representativeId )
-    {
-        this.representativeId = representativeId;
-    }
-
-    public void setRelationshipTypeId( Integer relationshipTypeId )
-    {
-        this.relationshipTypeId = relationshipTypeId;
-    }
+public class UpdateTrackedEntityInstanceAction implements Action {
+	// -------------------------------------------------------------------------
+	// Dependencies
+	// -------------------------------------------------------------------------
+
+	private TrackedEntityInstanceService entityInstanceService;
+
+	private TrackedEntityAttributeService attributeService;
+
+	private TrackedEntityAttributeValueService attributeValueService;
+
+	@Autowired
+	private TrackedEntityService trackedEntityService;
+
+	@Autowired
+	private ProgramService programService;
+
+	private I18nFormat format;
+
+	// -------------------------------------------------------------------------
+	// Input
+	// -------------------------------------------------------------------------
+
+	private Integer id;
+
+	private Integer representativeId;
+
+	private Integer relationshipTypeId;
+
+	private Integer trackedEntityId;
+
+	private String programId;
+
+	// -------------------------------------------------------------------------
+	// Output
+	// -------------------------------------------------------------------------
+
+	private TrackedEntityInstance entityInstance;
+
+	// -------------------------------------------------------------------------
+	// Action implementation
+	// -------------------------------------------------------------------------
+
+	public String execute() throws Exception {
+		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
+		// ---------------------------------------------------------------------
+
+		HttpServletRequest request = ServletActionContext.getRequest();
+
+		Collection<TrackedEntityAttribute> attributes = attributeService
+				.getAllTrackedEntityAttributes();
+
+		List<TrackedEntityAttributeValue> valuesForSave = new ArrayList<TrackedEntityAttributeValue>();
+		List<TrackedEntityAttributeValue> valuesForUpdate = new ArrayList<TrackedEntityAttributeValue>();
+		Collection<TrackedEntityAttributeValue> valuesForDelete = null;
+
+		TrackedEntityAttributeValue attributeValue = null;
+
+		if (attributes != null && attributes.size() > 0) {
+			valuesForDelete = attributeValueService
+					.getTrackedEntityAttributeValues(entityInstance);
+
+			for (TrackedEntityAttribute attribute : attributes) {
+				String value = request
+						.getParameter(AddTrackedEntityInstanceAction.PREFIX_ATTRIBUTE
+								+ attribute.getId());
+
+				if (StringUtils.isNotBlank(value)) {
+					if (attribute.getValueType().equals(
+							TrackedEntityAttribute.TYPE_AGE)) {
+						value = format.formatDate(TrackedEntityAttribute
+								.getDateFromAge(Integer.parseInt(value)));
+					}
+
+					attributeValue = attributeValueService
+							.getTrackedEntityAttributeValue(entityInstance,
+									attribute);
+
+					if (attributeValue == null) {
+						attributeValue = new TrackedEntityAttributeValue();
+						attributeValue.setEntityInstance(entityInstance);
+						attributeValue.setAttribute(attribute);
+						attributeValue.setValue(value.trim());
+
+						valuesForSave.add(attributeValue);
+					} else {
+						attributeValue.setValue(value.trim());
+
+						valuesForUpdate.add(attributeValue);
+						valuesForDelete.remove(attributeValue);
+					}
+				}
+			}
+		}
+
+		entityInstanceService.updateTrackedEntityInstance(entityInstance,
+				representativeId, relationshipTypeId, valuesForSave,
+				valuesForUpdate, valuesForDelete);
+
+		return SUCCESS;
+	}
+
+	// -------------------------------------------------------------------------
+	// Getter/Setter
+	// -------------------------------------------------------------------------
+
+	public void setFormat(I18nFormat format) {
+		this.format = format;
+	}
+
+	public void setTrackedEntityId(Integer trackedEntityId) {
+		this.trackedEntityId = trackedEntityId;
+	}
+
+	public void setTrackedEntityService(
+			TrackedEntityService trackedEntityService) {
+		this.trackedEntityService = trackedEntityService;
+	}
+
+	public void setentityInstanceService(
+			TrackedEntityInstanceService entityInstanceService) {
+		this.entityInstanceService = entityInstanceService;
+	}
+
+	public void setattributeService(
+			TrackedEntityAttributeService attributeService) {
+		this.attributeService = attributeService;
+	}
+
+	public void setattributeValueService(
+			TrackedEntityAttributeValueService attributeValueService) {
+		this.attributeValueService = attributeValueService;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public TrackedEntityInstance getEntityInstance() {
+		return entityInstance;
+	}
+
+	public void setRepresentativeId(Integer representativeId) {
+		this.representativeId = representativeId;
+	}
+
+	public void setRelationshipTypeId(Integer relationshipTypeId) {
+		this.relationshipTypeId = relationshipTypeId;
+	}
+
+	public void setProgramId(String programId) {
+		this.programId = programId;
+	}
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
@@ -88,7 +88,7 @@
 
     private Integer id;
 
-    private Integer programId;
+    private String programId;
 
     // -------------------------------------------------------------------------
     // Output
@@ -177,7 +177,7 @@
         this.programService = programService;
     }
 
-    public void setProgramId( Integer programId )
+    public void setProgramId( String programId )
     {
         this.programId = programId;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm	2014-04-06 15:48:31 +0000
@@ -46,7 +46,7 @@
 			<tr>
 				<td>$i18n.getString('program')</td>
 				<td>
-					<select id='programIdAddEntityInstance' name='programIdAddEntityInstance' class="{validate:{required:true}}" >
+					<select id='program' name='program' class="{validate:{required:true}}" >
 						#if($programs.size()==0)
 						<option value="">[$i18n.getString( "none_program" )]</option>
 						#elseif($programs.size()>1)

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addSingleEventRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addSingleEventRegistration.vm	2014-03-20 10:17:37 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addSingleEventRegistration.vm	2014-04-06 15:48:31 +0000
@@ -43,6 +43,6 @@
 <script>
 	var i18n_error_connect_to_server = '$encoder.jsEscape( $i18n.getString( "error_connect_to_server" ) , "'" )';
 	var i18n_add_person_successfully = '$encoder.jsEscape( $i18n.getString( "add_person_successfully" ) , "'" )';
-	setInnerHTML('entryName', jQuery('#programIdAddEntityInstance option:selected').text() );
-	setFieldValue("programStageId", getFieldValue("programIdAddEntityInstance"));
+	setInnerHTML('entryName', jQuery('#program option:selected').text() );
+	setFieldValue("programStageId", getFieldValue("program"));
 </script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addTrackedEntityInstanceForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addTrackedEntityInstanceForm.vm	2014-04-01 05:58:42 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addTrackedEntityInstanceForm.vm	2014-04-06 15:48:31 +0000
@@ -11,7 +11,7 @@
 							var programId = getFieldValue("relatedProgramId");
 							addTrackedEntityInstance( programId, true, isContinue);
 						#else
-							var programId = getFieldValue('programIdAddEntityInstance');
+							var programId = getFieldValue('program');
 							addTrackedEntityInstance(programId, false, isContinue);
 						#end
 					}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js	2014-04-06 15:48:31 +0000
@@ -38,7 +38,7 @@
 	hideById('listEntityInstanceDiv');
 	$('#contentDataRecord').html('');
 	var facilityLB = $('input[name=facilityLB]:checked').val();
-	var programId = getFieldValue('programIdAddEntityInstance');
+	var programId = getFieldValue('program');
     var searchTexts = "stat_" + programId
         + "_" + getFieldValue('startDueDate')
         + "_" + getFieldValue('endDueDate');
@@ -72,10 +72,10 @@
 function exportActitityList( type )
 {
     var facilityLB = $('input[name=facilityLB]:checked').val();
-    var params = "programId=" + getFieldValue('programIdAddEntityInstance');
+    var params = "programId=" + getFieldValue('program');
 
     params += "&type=xls";
-    params += "&searchTexts=stat_" + getFieldValue('programIdAddEntityInstance')
+    params += "&searchTexts=stat_" + getFieldValue('program')
         + "_" + getFieldValue('startDueDate')
         + "_" + getFieldValue('endDueDate');
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2014-04-04 17:58:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2014-04-06 15:48:31 +0000
@@ -143,36 +143,47 @@
 			var dateOperator = "";
 			var p = "";
 			jQuery(this).find(':input').each(
-					function(idx, item) {
-						if (item.type != "button") {
-							if (idx == 0) {
-								if (item.value == 'programDate') {
-									p += "&programDate=";
-								} else {
-									p += "&attribute=" + item.value + ":";
-								}
-							} else if (item.name == 'dateOperator') {
-								dateOperator = item.value;
-							} else if (item.name == 'searchText') {
-								if (item.value != '') {
-									if (dateOperator.length > 0) {
-										p += dateOperator + ":" + item.value.toLowerCase();
-									} else {
-										var keys = item.value.toLowerCase()
-												.replace(/^\s*/, "")
-												.replace(/\s*$/, "")
-												.replace(/ /g, ";");
-										p += "IN:" + keys;
-									}
-								} else {
-									p = "";
-								}
+				function(idx, item) {
+					if (item.type != "button") {
+						if (idx == 0) {
+							if (item.value == 'programDate') {
+								p += "&programDate=";
+							} else {
+								p += "&attribute=" + item.value;
+							}
+						} else if (item.name == 'dateOperator') {
+							dateOperator = item.value;
+						} else if (item.name == 'searchText') {
+							if (item.value != '') {
+								if (dateOperator.length > 0) {
+									p += dateOperator + ":" + item.value.toLowerCase();
+								} else {
+									var key = item.value.toLowerCase()
+											.replace(/^\s*/, "")
+											.replace(/\s*$/, "");
+									p += ":LIKE:" + key;
+								}
+							} else {
+								p = "";
 							}
 						}
-					});
+					}
+				});
 			params += p;
 		});
-			
+	
+	$('#advancedSearchTB tr').each(
+		function(i, row) {
+			jQuery(this).find(':input').each(
+				function(idx, item) {
+					if (item.type != "button" 
+						&& idx == 0 
+						&& $(item).find('option:selected').attr('displayed')=="true") {
+							params += "&query=" + item.value;
+					}
+				})
+			});
+		
 	params += '&ouMode=' + getFieldValue('ouMode');
 
 	return params;
@@ -348,14 +359,15 @@
 		clearListById('searchObjectId');
 		if (getFieldValue('program') != '') {
 			jQuery('#searchObjectId').append(
-					'<option value="programDate">' + i18n_enrollment_date
-							+ '</option>');
+				'<option value="programDate" displayed="true">' + i18n_enrollment_date
+					+ '</option>');
 		}
 
 		for ( var i in json.attributes) {
 			jQuery('#searchObjectId').append(
-					'<option value="' + json.attributes[i].id + '">'
-							+ json.attributes[i].name + '</option>');
+				'<option value="' + json.attributes[i].id 
+					+ '" displayed="' + json.attributes[i].displayed  + '">'
+					+ json.attributes[i].name + '</option>');
 		}
 
 		addAttributeOption();

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js	2014-04-06 15:48:31 +0000
@@ -80,8 +80,8 @@
 	showLoader();
 	jQuery('#contentDiv').load( 'listAllTrackedEntityInstances.action',{
 			listAll:false,
-			programId:	getFieldValue("programIdAddEntityInstance"),
-			searchTexts: "prg_" + getFieldValue("programIdAddEntityInstance"),
+			programId:	getFieldValue("program"),
+			searchTexts: "prg_" + getFieldValue("program"),
 			searchByUserOrgunits: false,
 			searchBySelectedOrgunit:true
 		},
@@ -137,7 +137,7 @@
 			hideById('contentDiv');
 			hideById('contentDiv');
 			hideById('mainLinkLbl');
-			setInnerHTML('singleProgramName',jQuery('#programIdAddEntityInstance option:selected').text());
+			setInnerHTML('singleProgramName',jQuery('#program option:selected').text());
 			loadProgramStages( entityInstanceId, programId );
 		});
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js	2014-04-06 15:48:31 +0000
@@ -4,14 +4,14 @@
     hideById('entityInstanceDashboard');
     showById('searchDiv');
     showById('mainLinkLbl');
-    var width = jQuery('#programIdAddEntityInstance').width();
-    jQuery('#programIdAddEntityInstance').width(width - 30);
+    var width = jQuery('#program').width();
+    jQuery('#program').width(width - 30);
     showById("programLoader");
-    disable('programIdAddEntityInstance');
+    disable('program');
     setFieldValue('orgunitName', orgUnitNames[0]);
     setFieldValue('orgunitId', orgUnits[0]);
     hideById("listEntityInstanceDiv");
-    clearListById('programIdAddEntityInstance');
+    clearListById('program');
     $('#contentDataRecord').html('');
 
     jQuery.get("getPrograms.action", {}, function( json ) {
@@ -20,20 +20,20 @@
         for( i in json.programs ) {
             if( json.programs[i].type == 1 ) {
                 count++;
-                jQuery('#programIdAddEntityInstance').append('<option value="' + json.programs[i].id + '" type="' + json.programs[i].type + '">' + json.programs[i].name + '</option>');
+                jQuery('#program').append('<option value="' + json.programs[i].id + '" type="' + json.programs[i].type + '">' + json.programs[i].name + '</option>');
             }
         }
 
         if( count == 0 ) {
-            jQuery('#programIdAddEntityInstance').prepend('<option value="" >' + i18n_none_program + '</option>');
+            jQuery('#program').prepend('<option value="" >' + i18n_none_program + '</option>');
         } else if( count > 1 ) {
-            jQuery('#programIdAddEntityInstance').prepend('<option value="" selected>' + i18n_please_select + '</option>');
+            jQuery('#program').prepend('<option value="" selected>' + i18n_please_select + '</option>');
         }
 
         enableBtn();
         hideById('programLoader');
-        jQuery('#programIdAddEntityInstance').width(width);
-        enable('programIdAddEntityInstance');
+        jQuery('#program').width(width);
+        enable('program');
     });
 }
 
@@ -51,7 +51,7 @@
         var y = date.getFullYear();
         var lastDays = jQuery.datepicker.formatDate(dateFormat, new Date(y, m, d - eval(scheduledVisitDays)));
 
-        var searchTexts = "stat_" + getFieldValue('programIdAddEntityInstance') + "_" + lastDays + "_" + today + "_"
+        var searchTexts = "stat_" + getFieldValue('program') + "_" + lastDays + "_" + today + "_"
             + getFieldValue('orgunitId') + "_false_" + getFieldValue('statusEvent');
 
         getTrackedEntityInstanceList(searchTexts);
@@ -63,7 +63,7 @@
 	hideById('listEntityInstanceDiv');
 	hideById('advanced-search');
 	hideById('contentDataRecord');
-    var programId = getFieldValue('programIdAddEntityInstance');
+    var programId = getFieldValue('program');
 
     var data = {};
     data.listAll = false;
@@ -92,7 +92,7 @@
     hideById('listEntityInstanceDiv');
     showLoader();
 
-    var programId = getFieldValue('programIdAddEntityInstance');
+    var programId = getFieldValue('program');
 
     if( !isNaN(programId) || programId == null) {
         params += "&programId=" + parseInt(programId);

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js	2014-03-20 10:17:37 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js	2014-04-06 15:48:31 +0000
@@ -3,35 +3,35 @@
 
 function orgunitSelected( orgUnits, orgUnitNames )
 {	
-	var width = jQuery('#programIdAddEntityInstance').width();
-	jQuery('#programIdAddEntityInstance').width(width-30);
+	var width = jQuery('#program').width();
+	jQuery('#program').width(width-30);
 	showById( "programLoader" );
-	disable('programIdAddEntityInstance');
+	disable('program');
 	hideById('addNewDiv');
 	organisationUnitSelected( orgUnits, orgUnitNames );
-	clearListById('programIdAddEntityInstance');
+	clearListById('program');
 	$.postJSON( 'singleEventPrograms.action', {}, function( json )
 		{
 			var count = 0;
 			for ( i in json.programs ) {
 				if( json.programs[i].type==2){
-					jQuery( '#programIdAddEntityInstance').append( '<option value="' + json.programs[i].id +'" programStageId="' + json.programs[i].programStageId + '" type="' + json.programs[i].type + '">' + json.programs[i].name + '</option>' );
+					jQuery( '#program').append( '<option value="' + json.programs[i].id +'" programStageId="' + json.programs[i].programStageId + '" type="' + json.programs[i].type + '">' + json.programs[i].name + '</option>' );
 					count++;
 				}
 			}
 			
 			if(count==0){
-				jQuery( '#programIdAddEntityInstance').prepend( '<option value="" >' + i18n_none_program + '</option>' );
+				jQuery( '#program').prepend( '<option value="" >' + i18n_none_program + '</option>' );
 			}
 			else if(count>1){
-				jQuery( '#programIdAddEntityInstance').prepend( '<option value="" selected>' + i18n_please_select + '</option>' );
+				jQuery( '#program').prepend( '<option value="" selected>' + i18n_please_select + '</option>' );
 				enable('addEntityInstanceBtn');
 			}
 			
 			enableBtn();
 			hideById('programLoader');
-			jQuery('#programIdAddEntityInstance').width(width);
-			enable('programIdAddEntityInstance');
+			jQuery('#program').width(width);
+			enable('program');
 		});
 }
 selection.setListenerFunction( orgunitSelected );
@@ -49,10 +49,10 @@
 	jQuery('#loaderDiv').show();
 	jQuery('#addNewDiv').load('showEventWithRegistrationForm.action',
 		{
-			programId: getFieldValue('programIdAddEntityInstance')
+			programId: getFieldValue('program')
 		}, function()
 		{
-			setInnerHTML('singleProgramName',jQuery('#programIdAddEntityInstance option:selected').text());	
+			setInnerHTML('singleProgramName',jQuery('#program option:selected').text());	
 			unSave = true;
 			showById('singleProgramName');
 			showById('addNewDiv');
@@ -65,11 +65,11 @@
 	hideById('dataEntryMenu');
 	showById('eventActionMenu');
 	hideById('nextEventLink');
-	setInnerHTML('singleProgramName',jQuery('#programIdAddEntityInstance option:selected').text());	
+	setInnerHTML('singleProgramName',jQuery('#program option:selected').text());	
 	showById('singleProgramName');
 	setInnerHTML('addNewDiv','');
 	unSave = false;
-	showSelectedDataRecoding(entityInstanceId, getFieldValue('programIdAddEntityInstance'));
+	showSelectedDataRecoding(entityInstanceId, getFieldValue('program'));
 }
 
 function addEventForEntityInstanceForm( divname )
@@ -81,7 +81,7 @@
 
 function validateData()
 {
-	var params = "programId=" + getFieldValue('programIdAddEntityInstance') + "&" + getParamsForDiv('entityInstanceForm');
+	var params = "programId=" + getFieldValue('program') + "&" + getParamsForDiv('entityInstanceForm');
 	$("#entityInstanceForm :input").attr("disabled", true);
 	$("#entryForm :input").attr("disabled", true);
 	$.ajax({
@@ -132,14 +132,14 @@
 		data: getParamsForDiv('entityInstanceForm'),
 		success: function(json) {
 			var entityInstanceId = json.message.split('_')[1];
-			addData( getFieldValue('programIdAddEntityInstance'), entityInstanceId );
+			addData( getFieldValue('program'), entityInstanceId );
 		}
      });
 }
 
 function addData( programId, entityInstanceId )
 {		
-	var params = "programId=" + getFieldValue('programIdAddEntityInstance');
+	var params = "programId=" + getFieldValue('program');
 		params += "&entityInstanceId=" + entityInstanceId;
 		params += "&" + getParamsForDiv('entryForm');
 		

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js	2014-04-06 15:48:31 +0000
@@ -3,10 +3,10 @@
 
 function orgunitSelected( orgUnits, orgUnitNames )
 {
-	var width = jQuery('#programIdAddEntityInstance').width();
-	jQuery('#programIdAddEntityInstance').width(width-30);
+	var width = jQuery('#program').width();
+	jQuery('#program').width(width-30);
 	showById( "programLoader" );
-	disable('programIdAddEntityInstance');
+	disable('program');
 	disable('listEntityInstanceBtn');
 	showById('mainLinkLbl');
 	showById('searchDiv');
@@ -22,7 +22,7 @@
 	hideById('addRelationshipDiv');
 	hideById('migrationEntityInstanceDiv');
 
-	clearListById('programIdAddEntityInstance');
+	clearListById('program');
 	$('#contentDataRecord').html('');
 	setFieldValue('orgunitName', orgUnitNames[0]);
 	setFieldValue('orgunitId', orgUnits[0]);
@@ -33,21 +33,21 @@
 			for ( i in json.programs ) {
 				if(json.programs[i].type==1){
 					count++;
-					jQuery( '#programIdAddEntityInstance').append( '<option value="' + json.programs[i].id +'" type="' + json.programs[i].type + '">' + json.programs[i].name + '</option>' );
+					jQuery( '#program').append( '<option value="' + json.programs[i].id +'" type="' + json.programs[i].type + '">' + json.programs[i].name + '</option>' );
 				}
 			}
 			if(count==0){
-				jQuery( '#programIdAddEntityInstance').prepend( '<option value="" selected>' + i18n_none_program + '</option>' );
+				jQuery( '#program').prepend( '<option value="" selected>' + i18n_none_program + '</option>' );
 			}
 			else if(count>1){
-				jQuery( '#programIdAddEntityInstance').prepend( '<option value="" selected>' + i18n_please_select + '</option>' );
+				jQuery( '#program').prepend( '<option value="" selected>' + i18n_please_select + '</option>' );
 				enable('listEntityInstanceBtn');
 			}
 			
 			enableBtn();
 			hideById('programLoader');
-			jQuery('#programIdAddEntityInstance').width(width);
-			enable('programIdAddEntityInstance');
+			jQuery('#program').width(width);
+			enable('program');
 		});
 }
 
@@ -74,7 +74,7 @@
 	var startDate = jQuery.datepicker.formatDate( dateFormat, new Date(y1, m, d) );
 	var endDate = jQuery.datepicker.formatDate( dateFormat, new Date(y2, m, d) );
 	
-	var programId = getFieldValue('programIdAddEntityInstance');
+	var programId = getFieldValue('program');
 	var searchTexts = "stat_" + programId + "_" 
 				+ startDate + "_" + endDate + "_" 
 				+ getFieldValue('orgunitId') + "_true_" 
@@ -114,7 +114,7 @@
 	$('#listEventDiv').html('');
 	hideById('listEventDiv');
 	showLoader();
-	params += "&programId=" + getFieldValue('programIdAddEntityInstance');
+	params += "&programId=" + getFieldValue('program');
 	generateResultParams = params;
 	
 	$.ajax({

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js	2014-04-04 17:58:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js	2014-04-06 15:48:31 +0000
@@ -1,3 +1,4 @@
+
 function organisationUnitSelected(orgUnits, orgUnitNames) {
 	showById('selectDiv');
 	showById('searchDiv');
@@ -412,9 +413,7 @@
 
 function addTrackedEntityInstance(programId, related, isContinue) {
 	var entityInstance = new TrackedEntityInstance();
-	var params = 'programId=' + programId + '&'
-			+ getParamsForDiv('entityInstanceForm');
-	entityInstance.add(programId, related, params, isContinue);
+	entityInstance.add(programId, related, getParamsForDiv('entityInstanceForm'), isContinue);
 	registrationProgress = true;
 	return false;
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm	2014-04-06 15:48:31 +0000
@@ -1,14 +1,14 @@
 <script>
     jQuery(document).ready(function() {
-        jQuery("#programIdAddEntityInstance option").each(function() {
+        jQuery("#program option").each(function() {
             var item = jQuery(this);
             if( item.attr('type') != 1 && item.val() != '' ) {
                 item.remove();
             }
         });
 
-        if( jQuery("#programIdAddEntityInstance option").length == 1 ) {
-            jQuery("#programIdAddEntityInstance [value=]").remove();
+        if( jQuery("#program option").length == 1 ) {
+            jQuery("#program [value=]").remove();
         }
 
         disable('scheduledVisitDays');

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingSelect.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingSelect.vm	2014-04-06 15:48:31 +0000
@@ -2,7 +2,7 @@
     jQuery(document).ready(function() {
         showById('programStageAddEntityInstanceTR');
         showById('sendSmsToListBtn');
-        jQuery("#programIdAddEntityInstance option").each(function() {
+        jQuery("#program option").each(function() {
             var item = jQuery(this);
             if( item.attr('type') != 1 && item.val() != '' ) {
                 item.remove();

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm	2014-03-25 09:41:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm	2014-04-06 15:48:31 +0000
@@ -1,16 +1,16 @@
 <script>
 	jQuery(document).ready(	function(){
-		jQuery("#programIdAddEntityInstance option").each(function() {
+		jQuery("#program option").each(function() {
             var item = jQuery(this);
             if( item.attr('type') != 2 ) {
                 item.remove();
             }
         });
-		jQuery("#programIdAddEntityInstance [value=]").remove();
+		jQuery("#program [value=]").remove();
 	
-		if(jQuery("#programIdAddEntityInstance option").length==0)
+		if(jQuery("#program option").length==0)
 		{
-			jQuery( '#programIdAddEntityInstance').append( '<option value="" type="">' + i18n_none_program + '</option>' );
+			jQuery( '#program').append( '<option value="" type="">' + i18n_none_program + '</option>' );
 			disable('listEntityInstanceBtn');
 			disable('addEntityInstanceBtn');
 		}