← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14306: Move the mandatory property from TrackedEntityAttribute to ProgramTrackedEntityAttribute.

 

------------------------------------------------------------
revno: 14306
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-03-20 12:43:18 +0700
message:
  Move the mandatory property from TrackedEntityAttribute to ProgramTrackedEntityAttribute.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramTrackedEntityAttributeService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramTrackedEntityAttributeStore.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityFormService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAttributeStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramTrackedEntityAttribute.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAttribute.hbm.xml
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStoreTest.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.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/ShowAddTrackedEntityInstanceFormAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntityAttribute.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewTrackedEntityFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/program.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewTrackedEntityForm.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/ProgramTrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttribute.java	2014-03-20 05:43:18 +0000
@@ -33,6 +33,7 @@
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.view.DetailedView;
@@ -60,6 +61,8 @@
 
     private boolean displayedInList;
 
+    private Boolean mandatory;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -75,6 +78,15 @@
         this.displayedInList = displayedInList;
     }
 
+    public ProgramTrackedEntityAttribute( TrackedEntityAttribute attribute, Integer sortOrder, boolean displayedInList,
+        Boolean mandatory )
+    {
+        this.attribute = attribute;
+        this.sortOrder = sortOrder;
+        this.displayedInList = displayedInList;
+        this.mandatory = mandatory;
+    }
+
     // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------
@@ -124,6 +136,19 @@
     }
 
     @JsonProperty
+    @JsonView( { DetailedView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Boolean getMandatory()
+    {
+        return mandatory;
+    }
+
+    public void setMandatory( Boolean mandatory )
+    {
+        this.mandatory = mandatory;
+    }
+
+    @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class, WithoutOrganisationUnitsView.class } )
     @JacksonXmlProperty( localName = "personAttribute", namespace = DxfNamespaces.DXF_2_0 )

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeService.java	2014-03-20 05:43:18 +0000
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program;
+
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ProgramTrackedEntityAttributeService.java Mar 19, 2014 2:53:34 PM
+ *          $
+ */
+public interface ProgramTrackedEntityAttributeService
+{
+    /**
+     * Get ProgramTrackedEntityAttribute by Program and TrackedEntityAttribute
+     * 
+     * @param program Program
+     * @param attribute TrackedEntityAttribute
+     * 
+     * @return ProgramTrackedEntityAttribute
+     */
+    ProgramTrackedEntityAttribute getProgramTrackedEntityAttribute( Program program, TrackedEntityAttribute attribute );
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramTrackedEntityAttributeStore.java	2014-03-20 05:43:18 +0000
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program;
+
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ProgramTrackedEntityAttributeStore.java Mar 19, 2014 2:54:23 PM $
+ */
+public interface ProgramTrackedEntityAttributeStore
+{
+    /**
+     * Get ProgramTrackedEntityAttribute by Program and TrackedEntityAttribute
+     * @param program Program
+     * @param attribute TrackedEntityAttribute
+     * 
+     * @return ProgramTrackedEntityAttribute
+     */
+    ProgramTrackedEntityAttribute get( Program program, TrackedEntityAttribute attribute );
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2014-03-20 05:43:18 +0000
@@ -86,8 +86,6 @@
 
     private String valueType;
 
-    private boolean mandatory;
-
     private Boolean inherit = false;
 
     private Boolean groupBy = false;
@@ -125,13 +123,12 @@
         setAutoFields();
     }
 
-    public TrackedEntityAttribute( String name, String description, String valueType, boolean mandatory,
+    public TrackedEntityAttribute( String name, String description, String valueType, 
         Boolean inherit, Boolean displayOnVisitSchedule )
     {
         this.name = name;
         this.description = description;
         this.valueType = valueType;
-        this.mandatory = mandatory;
         this.inherit = inherit;
         this.displayOnVisitSchedule = displayOnVisitSchedule;
 
@@ -179,20 +176,7 @@
     {
         this.groupBy = groupBy;
     }
-
-    @JsonProperty
-    @JsonView( { DetailedView.class } )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public boolean isMandatory()
-    {
-        return mandatory;
-    }
-
-    public void setMandatory( boolean mandatory )
-    {
-        this.mandatory = mandatory;
-    }
-
+    
     @JsonProperty
     @JsonView( { DetailedView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -416,7 +400,6 @@
 
             description = trackedEntityAttribute.getDescription();
             valueType = trackedEntityAttribute.getValueType();
-            mandatory = trackedEntityAttribute.isMandatory();
             inherit = trackedEntityAttribute.getInherit();
             groupBy = trackedEntityAttribute.getGroupBy();
             attributeGroup = trackedEntityAttribute.getAttributeGroup();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java	2014-03-20 05:43:18 +0000
@@ -108,19 +108,12 @@
     Collection<TrackedEntityAttribute> getTrackedEntityAttributesByValueType( String valueType );
 
     /**
-     * Get mandatory attributes without groups
+     * Get attributes without groups
      * 
      * @return List of attributes
      */
     Collection<TrackedEntityAttribute> getOptionalAttributesWithoutGroup();
-
-    /**
-     * Get attributes by mandatory option
-     * 
-     * @param mandatory True/False value
-     */
-    Collection<TrackedEntityAttribute> getTrackedEntityAttributesByMandatory( boolean mandatory );
-
+    
     /**
      * Get attributes by groupBy option
      * 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStore.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStore.java	2014-03-20 05:43:18 +0000
@@ -50,21 +50,12 @@
     Collection<TrackedEntityAttribute> getByValueType( String valueType );
 
     /**
-     * Get mandatory attributes without groups
+     * Get attributes without groups
      * 
      * @return List of attributes
      */
     Collection<TrackedEntityAttribute> getOptionalAttributesWithoutGroup();
-
-    /**
-     * Get attributes by mandatory option
-     * 
-     * @param mandatory True/False value
-     * 
-     * @return List of attributes
-     */
-    Collection<TrackedEntityAttribute> getByMandatory( boolean mandatory );
-
+    
     /**
      * Get {@link TrackedEntityAttribute} without any group
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2014-03-19 10:55:15 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2014-03-20 05:43:18 +0000
@@ -432,7 +432,7 @@
         for ( ProgramTrackedEntityAttribute programTrackedEntityAttribute : program.getAttributes() )
         {
             // TODO this will be replaced with programTrackedEntityAttribute.isMandatory when added to the model
-            mandatoryMap.put( programTrackedEntityAttribute.getAttribute(), programTrackedEntityAttribute.getAttribute().isMandatory() );
+            mandatoryMap.put( programTrackedEntityAttribute.getAttribute(), programTrackedEntityAttribute.getMandatory() );
         }
 
         for ( TrackedEntityAttributeValue value : trackedEntityInstance.getAttributeValues() )

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-03-20 05:43:18 +0000
@@ -1399,8 +1399,7 @@
 
         for ( TrackedEntityAttribute patientAtt : getPatientAtts( null ) )
         {
-            list.add( new PatientAttribute( patientAtt.getName(), null, patientAtt.getValueType(), patientAtt
-                .isMandatory(), new ArrayList<String>() ) );
+            list.add( new PatientAttribute( patientAtt.getName(), null, patientAtt.getValueType(), false, new ArrayList<String>() ) );
         }
 
         return list;

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java	2014-03-20 05:43:18 +0000
@@ -294,7 +294,6 @@
 
         org.hisp.dhis.api.mobile.model.PatientAttribute mobileAttribute = new org.hisp.dhis.api.mobile.model.PatientAttribute();
         mobileAttribute.setName( pa.getName() );
-        mobileAttribute.setMandatory( pa.isMandatory() );
         mobileAttribute.setType( pa.getValueType() );
         mobileAttribute.setValue( "" );
         if ( ppa.getDisplayedInList() )

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramTrackedEntityAttributeService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramTrackedEntityAttributeService.java	2014-03-20 05:43:18 +0000
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program;
+
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ DefaultProgramTrackedEntityAttributeService.java Mar 19, 2014
+ *          2:55:57 PM $
+ */
+public class DefaultProgramTrackedEntityAttributeService
+    implements ProgramTrackedEntityAttributeService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private ProgramTrackedEntityAttributeStore programAttributeStore;
+
+    // -------------------------------------------------------------------------
+    // Implementation methods
+    // -------------------------------------------------------------------------
+
+    @Override
+    public ProgramTrackedEntityAttribute getProgramTrackedEntityAttribute( Program program,
+        TrackedEntityAttribute atribute )
+    {
+        return programAttributeStore.get( program, atribute );
+    }
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramTrackedEntityAttributeStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramTrackedEntityAttributeStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramTrackedEntityAttributeStore.java	2014-03-20 05:43:18 +0000
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program.hibernate;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
+import org.hisp.dhis.program.ProgramTrackedEntityAttributeStore;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ HibernateProgramTrackedEntityAttributeStore.java Mar 19, 2014
+ *          2:58:05 PM $
+ */
+public class HibernateProgramTrackedEntityAttributeStore
+    implements ProgramTrackedEntityAttributeStore
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SessionFactory sessionFactory;
+
+    public void setSessionFactory( SessionFactory sessionFactory )
+    {
+        this.sessionFactory = sessionFactory;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implemented methods
+    // -------------------------------------------------------------------------
+
+    @Override
+    public ProgramTrackedEntityAttribute get( Program program, TrackedEntityAttribute attribute )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( ProgramStageDataElement.class );
+        criteria.add( Restrictions.eq( "program", program ) );
+        criteria.add( Restrictions.eq( "attribute", attribute ) );
+
+        return (ProgramTrackedEntityAttribute) criteria.uniqueResult();
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2014-03-20 05:43:18 +0000
@@ -109,11 +109,6 @@
         return attributeStore.getOptionalAttributesWithoutGroup();
     }
 
-    public Collection<TrackedEntityAttribute> getTrackedEntityAttributesByMandatory( boolean mandatory )
-    {
-        return attributeStore.getByMandatory( mandatory );
-    }
-
     public Collection<TrackedEntityAttribute> getTrackedEntityAttributesWithoutGroup()
     {
         return attributeStore.getWithoutGroup();

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityFormService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityFormService.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityFormService.java	2014-03-20 05:43:18 +0000
@@ -37,9 +37,11 @@
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramTrackedEntityAttributeService;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
 import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -86,6 +88,9 @@
         this.attributeValueService = attributeValueService;
     }
 
+    @Autowired
+    private ProgramTrackedEntityAttributeService programAttributeService;
+    
     // -------------------------------------------------------------------------
     // TrackedEntityForm implementation
     // -------------------------------------------------------------------------
@@ -195,7 +200,7 @@
                         }
                     }
 
-                    inputHtml = getAttributeField( inputHtml, attribute, value, i18n, index, hidden, style );
+                    inputHtml = getAttributeField( inputHtml, attribute, program, value, i18n, index, hidden, style );
 
                 }
 
@@ -272,13 +277,20 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private String getAttributeField( String inputHtml, TrackedEntityAttribute attribute, String value, I18n i18n,
+    private String getAttributeField( String inputHtml, TrackedEntityAttribute attribute, Program program, String value, I18n i18n,
         int index, String hidden, String style )
     {
+        boolean madatory = false;
+        
+        if( program!= null)
+        {
+            madatory = programAttributeService.getProgramTrackedEntityAttribute( program, attribute ).getMandatory();
+        }
+        
         inputHtml = TAG_OPEN + "input id=\"attr" + attribute.getId() + "\" name=\"attr" + attribute.getId()
             + "\" tabindex=\"" + index + "\" style=\"" + style + "\"";
 
-        inputHtml += "\" class=\"" + hidden + " {validate:{required:" + attribute.isMandatory();
+        inputHtml += "\" class=\"" + hidden + " {validate:{required:" + madatory;
         if ( TrackedEntityAttribute.TYPE_INT.equals( attribute.getValueType() ) )
         {
             inputHtml += ",number:true";

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAttributeStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAttributeStore.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAttributeStore.java	2014-03-20 05:43:18 +0000
@@ -55,17 +55,9 @@
 
     @Override
     @SuppressWarnings( "unchecked" )
-    public Collection<TrackedEntityAttribute> getByMandatory( boolean mandatory )
-    {
-        return getCriteria( Restrictions.eq( "mandatory", mandatory ) ).list();
-    }
-
-    @Override
-    @SuppressWarnings( "unchecked" )
     public Collection<TrackedEntityAttribute> getOptionalAttributesWithoutGroup()
     {
-        return getCriteria( Restrictions.isNull( "attributeGroup" ) ).add( Restrictions.eq( "mandatory", false ) )
-            .list();
+        return getCriteria( Restrictions.isNull( "attributeGroup" ) ).list();
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-03-19 07:31:33 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-03-20 05:43:18 +0000
@@ -280,6 +280,12 @@
 
         executeSql( "ALTER TABLE trackedentityattributevalue DROP COLUMN trackedentityattributeoptionid" );
         executeSql( "DROP TABLE trackedentityattributeoption" );
+
+        executeSql( "UPDATE program_attributes SET mandatory = trackedentityattribute.mandatory "
+            + "FROM program_attributes pa " + "INNER JOIN trackedentityattribute  "
+            + "ON pa.trackedentityattributeid=trackedentityattribute.trackedentityattributeid  "
+            + "where trackedentityattribute.mandatory is not null" );
+        executeSql( "ALTER TABLE trackedentityattribute DROP COLUMN mandatory" );
     }
 
     // -------------------------------------------------------------------------
@@ -424,17 +430,18 @@
 
     private void createPersonTrackedEntity()
     {
-        int exist = jdbcTemplate.queryForObject( "SELECT count(*) FROM trackedentity where name='Person'", Integer.class );
+        int exist = jdbcTemplate.queryForObject( "SELECT count(*) FROM trackedentity where name='Person'",
+            Integer.class );
         if ( exist == 0 )
         {
             String id = statementBuilder.getAutoIncrementValue();
-            
+
             jdbcTemplate.execute( "INSERT INTO trackedentity(trackedentityid,uid, name, description) values(" + id
                 + ",'" + CodeGenerator.generateCode() + "','Person','Person')" );
-            
+
             jdbcTemplate.execute( "UPDATE program SET trackedentityid="
                 + "  (SELECT trackedentityid FROM trackedentity where name='Person') where trackedentityid is null" );
-            
+
             jdbcTemplate.execute( "UPDATE trackedentityinstance SET trackedentityid="
                 + "  (SELECT trackedentityid FROM trackedentity where name='Person') where trackedentityid is null" );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-03-20 05:43:18 +0000
@@ -131,6 +131,11 @@
 		<property name="clazz" value="org.hisp.dhis.trackedentity.TrackedEntity" />
 		<property name="sessionFactory" ref="sessionFactory" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.program.ProgramTrackedEntityAttributeStore"
+		class="org.hisp.dhis.program.hibernate.HibernateProgramTrackedEntityAttributeStore">
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
 
 	<!-- Service definitions -->
 
@@ -292,6 +297,11 @@
 		<property name="trackedEntityStore"
 			ref="org.hisp.dhis.trackedentity.TrackedEntityStore" />
 	</bean>
+	
+		<bean id="org.hisp.dhis.program.ProgramTrackedEntityAttributeService"
+		class="org.hisp.dhis.program.DefaultProgramTrackedEntityAttributeService">
+	</bean>
+	
 
 	<!-- TrackedEntityComment -->
 

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramTrackedEntityAttribute.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramTrackedEntityAttribute.hbm.xml	2014-02-10 05:42:16 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramTrackedEntityAttribute.hbm.xml	2014-03-20 05:43:18 +0000
@@ -4,18 +4,22 @@
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
 
 <hibernate-mapping>
-  <class name="org.hisp.dhis.program.ProgramTrackedEntityAttribute" table="program_attributes">
-
-    <id name="id" column="programtrackedentityattributeid">
-        <generator class="native" />
-    </id>
-    
-    <many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute" 
-        column="trackedentityattributeid" foreign-key="fk_program_attributeid" />
-
-    <property name="sortOrder" column="sort_order" />
-    
-	<property name="displayedInList" column="displayinlist" />
-	
-  </class>
+	<class name="org.hisp.dhis.program.ProgramTrackedEntityAttribute"
+		table="program_attributes">
+
+		<id name="id" column="programtrackedentityattributeid">
+			<generator class="native" />
+		</id>
+
+		<many-to-one name="attribute"
+			class="org.hisp.dhis.trackedentity.TrackedEntityAttribute" column="trackedentityattributeid"
+			foreign-key="fk_program_attributeid" />
+
+		<property name="sortOrder" column="sort_order" />
+
+		<property name="displayedInList" column="displayinlist" />
+
+		<property name="mandatory" column="mandatory" />
+
+	</class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAttribute.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAttribute.hbm.xml	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAttribute.hbm.xml	2014-03-20 05:43:18 +0000
@@ -19,8 +19,6 @@
 
     <property name="valueType" column="valuetype" not-null="true" />
 
-    <property name="mandatory" column="mandatory" />
-
     <property name="groupBy" column="groupby" />
 
     <many-to-one name="attributeGroup" column="trackedentityattributegroupid" class="org.hisp.dhis.trackedentity.TrackedEntityAttributeGroup"

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeServiceTest.java	2014-03-20 05:43:18 +0000
@@ -93,23 +93,6 @@
     }
 
     @Test
-    public void testGetTrackedEntityAttributesByMandatory()
-    {
-        attributeA.setMandatory( true );
-        attributeB.setMandatory( true );
-        attributeC.setMandatory( false );
-
-        attributeStore.save( attributeA );
-        attributeStore.save( attributeB );
-        attributeStore.save( attributeC );
-
-        Collection<TrackedEntityAttribute> attributes = attributeStore.getByMandatory( true );
-        assertEquals( 2, attributes.size() );
-        assertTrue( attributes.contains( attributeA ) );
-        assertTrue( attributes.contains( attributeB ) );
-    }
-
-    @Test
     public void testGetTrackedEntityAttributeByGroupBy()
     {
         attributeA.setGroupBy( true );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStoreTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeStoreTest.java	2014-03-20 05:43:18 +0000
@@ -176,23 +176,6 @@
     }
 
     @Test
-    public void testGetTrackedEntityAttributesByMandatory()
-    {
-        attributeA.setMandatory( true );
-        attributeB.setMandatory( true );
-        attributeC.setMandatory( false );
-
-        attributeService.addTrackedEntityAttribute( attributeA );
-        attributeService.addTrackedEntityAttribute( attributeB );
-        attributeService.addTrackedEntityAttribute( attributeC );
-
-        Collection<TrackedEntityAttribute> attributes = attributeService.getTrackedEntityAttributesByMandatory( true );
-        assertEquals( 2, attributes.size() );
-        assertTrue( attributes.contains( attributeA ) );
-        assertTrue( attributes.contains( attributeB ) );
-    }
-
-    @Test
     public void testGetTrackedEntityAttributeByGroupBy()
     {
         attributeA.setGroupBy( true );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java	2014-03-20 05:43:18 +0000
@@ -38,7 +38,6 @@
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
-import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
@@ -87,7 +86,7 @@
         this.entityInstanceId = entityInstanceId;
     }
 
-    private List<TrackedEntityAttribute> attributes;
+    private List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
 
     public List<TrackedEntityAttribute> getAttributes()
     {
@@ -112,10 +111,7 @@
         if ( id != null )
         {
             Program program = programService.getProgram( id );
-            for ( ProgramTrackedEntityAttribute programAttribute :  program.getAttributes() )
-            {
-                attributes.add(programAttribute.getAttribute() );
-            }
+            attributes.addAll( program.getTrackedEntityAttributes() );
         }
         else
         {

=== 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-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java	2014-03-20 05:43:18 +0000
@@ -115,12 +115,6 @@
 
     private List<TrackedEntityAttributeGroup> attributeGroups;
 
-    private Map<Integer, String> identiferMap;
-
-    private String childContactName;
-
-    private String childContactType;
-
     private Relationship relationship;
 
     private Map<Integer, Collection<TrackedEntityAttribute>> attributeGroupsMap = new HashMap<Integer, Collection<TrackedEntityAttribute>>();
@@ -179,6 +173,13 @@
         return trackedEntities;
     }
 
+    private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
+
+    public Map<Integer, Boolean> getMandatoryMap()
+    {
+        return mandatoryMap;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -246,12 +247,17 @@
                         }
                     }
                 }
+                
+
+                for( TrackedEntityAttribute attribute : attributes){
+                    mandatoryMap.put( attribute.getId(), false );
+                }
             }
             else
             {
-                for ( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() )
-                {
-                    attributes.add( programAttribute.getAttribute() );
+                attributes = program.getTrackedEntityAttributes();
+                for( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() ){
+                    mandatoryMap.put( programAttribute.getAttribute().getId(), programAttribute.getMandatory() );
                 }
             }
 
@@ -362,21 +368,6 @@
         return attributeGroups;
     }
 
-    public Map<Integer, String> getIdentiferMap()
-    {
-        return identiferMap;
-    }
-
-    public String getChildContactName()
-    {
-        return childContactName;
-    }
-
-    public String getChildContactType()
-    {
-        return childContactType;
-    }
-
     public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
     {
         this.entityInstanceService = entityInstanceService;

=== 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-18 14:54:13 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ShowAddTrackedEntityInstanceFormAction.java	2014-03-20 05:43:18 +0000
@@ -42,6 +42,7 @@
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.trackedentity.TrackedEntity;
@@ -178,13 +179,6 @@
         return healthWorkers;
     }
 
-    private List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
-
-    public List<TrackedEntityAttribute> getAttributes()
-    {
-        return attributes;
-    }
-
     private Map<String, List<TrackedEntityAttribute>> attributesMap = new HashMap<String, List<TrackedEntityAttribute>>();
 
     public Map<String, List<TrackedEntityAttribute>> getAttributesMap()
@@ -276,6 +270,13 @@
         return trackedEntityAttributeValueMap;
     }
 
+    private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
+
+    public Map<Integer, Boolean> getMandatoryMap()
+    {
+        return mandatoryMap;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -341,6 +342,8 @@
             }
         }
 
+        List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
+
         if ( customRegistrationForm == null )
         {
             attributeGroups = new ArrayList<TrackedEntityAttributeGroup>(
@@ -349,23 +352,28 @@
 
             if ( program == null )
             {
-                attributes = new ArrayList<TrackedEntityAttribute>( attributeService.getAllTrackedEntityAttributes() );
+                attributes = new ArrayList<TrackedEntityAttribute>( attributeService.getTrackedEntityAttributesDisplayedInList( true ) );
                 Collection<Program> programs = programService.getAllPrograms();
 
                 for ( Program p : programs )
                 {
                     attributes.removeAll( p.getAttributes() );
                 }
+                
+                for ( TrackedEntityAttribute attribute : attributes )
+                {
+                    mandatoryMap.put( attribute.getId(), false );
+                }
             }
             else
             {
                 attributes = program.getTrackedEntityAttributes();
+                for ( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() )
+                {
+                    mandatoryMap.put( programAttribute.getAttribute().getId(), programAttribute.getMandatory() );
+                }
             }
 
-            Collection<TrackedEntityAttribute> attributesInList = attributeService.getTrackedEntityAttributesDisplayedInList( true );
-            attributes.removeAll( attributesInList );
-            attributes.addAll( attributesInList );
-
             for ( TrackedEntityAttribute attribute : attributes )
             {
                 TrackedEntityAttributeGroup attributeGroup = attribute.getAttributeGroup();

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/trackedEntityInstanceForm.vm	2014-03-20 05:43:18 +0000
@@ -1,4 +1,3 @@
-
 #if( $entityInstance )
 	#set($trackedEntityId=$entityInstance.trackedEntity.id)
 #elseif( $program )
@@ -45,39 +44,41 @@
 					 #if( $attribute )
 							 #set($value = "")
 							 #set($value = $attributeValueMap.get($attribute.id))
+							 #set($mandatory = $mandatoryMap.get($attribute.id))
+							 #if( $mandatory ) #else  #set($mandatory=false) #end
 							 <tr name='attributesFields'>
-									 <td class='text-column'><label>$encoder.htmlEncode($attribute.displayName) #if($attribute.mandatory) <em title="$i18n.getString( 'required' )" class="required">*</em> #end</label></td>
+									 <td class='text-column'><label>$encoder.htmlEncode($attribute.displayName) #if($mandatory ) <em title="$i18n.getString( 'required' )" class="required">*</em> #end</label></td>
 									 <td class="input-column">
 											 #if( $attribute.valueType == "bool" )
-													 <select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$attribute.mandatory}}" > 
+													 <select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$mandatory }}" > 
 															 <option value="" selected="selected">[$i18n.getString( "please_select" )]</option>
 															 <option value="true" #if($value=='true') selected #end>$i18n.getString( "yes" )</option>
 															 <option value="false" #if($value=='false') selected #end>$i18n.getString( "no" )</option>
 													 </select>                
 											 #elseif( $attribute.valueType == "trueOnly" )
-													 <input type='checkbox' value="true" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" #if($value=='true') checked #end class="{validate:{required:$attribute.mandatory}}" > 
+													 <input type='checkbox' value="true" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" #if($value=='true') checked #end class="{validate:{required:$mandatory }}" > 
 											 #elseif( $attribute.valueType == "date" )
-													 <input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class="{validate:{required:$attribute.mandatory}}" />
+													 <input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class="{validate:{required:$mandatory }}" />
 													 <script type="text/javascript">
 															 datePickerValid( 'attr$attribute.id', false, false );
 													 </script>                    
 											 #elseif( $attribute.valueType == "combo" )  
-													 <select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$attribute.mandatory}}" >
+													 <select id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$mandatory }}" >
 															 <option value="">[$i18n.getString( "please_select" )]</option>
 															 #foreach ($option in $attribute.optionSet.options )
 																	 <option value="$option" #if("$value"=="$option") selected #end>$option</option>
 															 #end
 													 </select>
 											 #elseif( $attribute.valueType == "phoneNumber" ) 
-													 <input type='text' value='$value' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{phone:true,required:$attribute.mandatory}}"/>
+													 <input type='text' value='$value' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{phone:true,required:$mandatory }}"/>
 											 #elseif( $attribute.valueType == "trackerAssociate" ) 
 													 <input type="checkbox" value='true' id="attr$attribute.id" name="attr$attribute.id" 
 															 inherit="$!attribute.inherit" #if($value=='true') checked #end
 															 onclick="toggleUnderAge(this);" class='underAge' />
 											 #elseif( $attribute.valueType == "age" || $attribute.valueType == "number" ) 
-													 <input type='text' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$attribute.mandatory,number:true}}"/>
+													 <input type='text' id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" class="{validate:{required:$mandatory ,number:true}}"/>
 											 #else 
-													 <input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class="{validate:{required:$attribute.mandatory #if($attribute.valueType=='NUMBER'),number:true #end }}" />
+													 <input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value='$value' class="{validate:{required:$mandatory  #if($attribute.valueType=='NUMBER'),number:true #end }}" />
 											 #end
 									 </td>           
 							 </tr>
@@ -93,9 +94,11 @@
 		#foreach($attribute in $attributes )
 			#set( $attributeValue = "" )
 			#set( $attributeValue = $!attributeValueMap.get( $attribute.id ) )
+			#set($mandatory = $mandatoryMap.get($attribute.id))
+			#if( $mandatory ) #else  #set($mandatory=false) #end
 			#if( $attribute.valueType != 'calculated')
 			<tr name='attributesFields'>
-				<td class='text-column'><label>$encoder.htmlEncode($attribute.displayName) #if($attribute.mandatory) <em title="$i18n.getString( "required" )" class="required">*</em> #end</label></td>
+				<td class='text-column'><label>$encoder.htmlEncode($attribute.displayName) #if($mandatory ) <em title="$i18n.getString( "required" )" class="required">*</em> #end</label></td>
 				<td class="input-column">
 					#if( $attribute.valueType == "bool" )
 						<select id="attr$attribute.id"  name="attr$attribute.id" inherit="$!attribute.inherit">              
@@ -106,19 +109,19 @@
 					#elseif( $attribute.valueType == "trueOnly" )
 						<input type='checkbox' value="true" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" #if($value=='true') checked #end> 
 					#elseif( $attribute.valueType == "date" )
-						<input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value="$!attributeValue" class=' #validate( "default"  $attribute.mandatory )'>
+						<input type="text" id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value="$!attributeValue" class=' #validate( "default"  $mandatory  )'>
 						<script type="text/javascript">
 							datePickerValid( 'attr$attribute.id', false, false );
 						</script>                    
 					#elseif( $attribute.valueType == "combo" )
-						<select  id="attr$attribute.id"  name="attr$attribute.id" inherit="$!attribute.inherit" class=' #validate( "default"  $attribute.mandatory )' >
+						<select  id="attr$attribute.id"  name="attr$attribute.id" inherit="$!attribute.inherit" class=' #validate( "default"  $mandatory  )' >
 							 <option value="">[$i18n.getString( "please_select" )]</option>
 						#foreach ($option in $attribute.optionSet.options )
 							<option value="$option" #if($attributeValue == $option) selected="selected" #end>$option</option>
 						#end
 						</select>
 					#elseif( $attribute.valueType == "users" )
-						<select inherit="$!attribute.inherit" class=' #validate( "default"  $attribute.mandatory )' >
+						<select inherit="$!attribute.inherit" class=' #validate( "default"  $mandatory  )' >
 							<option value="">[$i18n.getString("please_select")]</option>
 							#foreach( $user in $healthWorkers)
 								<option value="$user.id" #if($attributeValue == $user.id) selected="selected" #end >$user.name</option>
@@ -131,7 +134,7 @@
 							inherit="$!attribute.inherit" #if($value=='true') checked #end
 							onclick="toggleUnderAge(this);" class='underAge' />
 					#else  
-						<input type="text"  id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value="$!attributeValue" class="{validate:{required:$attribute.mandatory #if($!attribute.noChars),maxlength:$attribute.noChars #end #if($attribute.valueType=='NUMBER'),number:true #end }}" >
+						<input type="text"  id="attr$attribute.id" name="attr$attribute.id" inherit="$!attribute.inherit" value="$!attributeValue" class="{validate:{required:$mandatory  #if($!attribute.noChars),maxlength:$attribute.noChars #end #if($attribute.valueType=='NUMBER'),number:true #end }}" >
 					#end
 				</td>		
 			</tr>

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntityAttribute.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntityAttribute.vm	2014-02-07 20:25:49 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonTrackedEntityAttribute.vm	2014-03-20 05:43:18 +0000
@@ -4,10 +4,10 @@
 	"name": "$!encoder.jsonEncode( ${attribute.name} )",
 	"code": "$!encoder.jsonEncode( ${attribute.code} )",
 	"description": "$!encoder.jsonEncode( ${attribute.description} )",
-	"mandatory":  "$!{attribute.mandatory}",
 	"unique":  "$!{attribute.unique}",
 	"valueType": "$!attribute.valueType",
 	"displayInListNoProgram": "$!attribute.displayInListNoProgram",
-	"inherit": "$!attribute.inherit"
+	"inherit": "$!attribute.inherit",
+	"optionSet": "$!attribute.optionSet.name"
   }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewTrackedEntityFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewTrackedEntityFormAction.java	2014-03-18 14:54:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/dataentryform/ViewTrackedEntityFormAction.java	2014-03-20 05:43:18 +0000
@@ -35,6 +35,7 @@
 
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
@@ -109,6 +110,13 @@
         return attributes;
     }
 
+    private Collection<ProgramTrackedEntityAttribute> programAttributes = new ArrayList<ProgramTrackedEntityAttribute>();
+
+    public Collection<ProgramTrackedEntityAttribute> getProgramAttributes()
+    {
+        return programAttributes;
+    }
+
     private TrackedEntityForm registrationForm;
 
     public TrackedEntityForm getRegistrationForm()
@@ -162,7 +170,7 @@
         else
         {
             program = programService.getProgram( programId );
-            attributes = program.getTrackedEntityAttributes();
+            programAttributes = program.getAttributes();
             registrationForm = formService.getTrackedEntityForm( program );
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/AddProgramAction.java	2014-03-20 05:43:18 +0000
@@ -100,9 +100,9 @@
         this.relationshipTypeService = relationshipTypeService;
     }
 
-    @Autowired 
+    @Autowired
     private TrackedEntityService trackedEntityService;
-    
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -163,6 +163,13 @@
         this.personDisplayNames = personDisplayNames;
     }
 
+    private List<Boolean> mandatory = new ArrayList<Boolean>();
+
+    public void setMandatory( List<Boolean> mandatory )
+    {
+        this.mandatory = mandatory;
+    }
+
     private Boolean ignoreOverdueEvents;
 
     public void setIgnoreOverdueEvents( Boolean ignoreOverdueEvents )
@@ -293,7 +300,7 @@
         program.setRelationshipFromA( relationshipFromA );
         program.setRelationshipText( relationshipText );
 
-        if( trackedEntityId!=null)
+        if ( trackedEntityId != null )
         {
             TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
             program.setTrackedEntity( trackedEntity );
@@ -311,7 +318,7 @@
                     .parseInt( ids[1] ) );
 
                 ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute( attribute,
-                    index + 1, personDisplayNames.get( index ) );
+                    index + 1, personDisplayNames.get( index ), mandatory.get( index ) );
 
                 program.getAttributes().add( programAttribute );
             }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/UpdateProgramAction.java	2014-03-20 05:43:18 +0000
@@ -166,6 +166,13 @@
         this.personDisplayNames = personDisplayNames;
     }
 
+    private List<Boolean> mandatory = new ArrayList<Boolean>();
+
+    public void setMandatory( List<Boolean> mandatory )
+    {
+        this.mandatory = mandatory;
+    }
+
     private Boolean generateBydEnrollmentDate;
 
     public void setGeneratedByEnrollmentDate( Boolean generateBydEnrollmentDate )
@@ -346,7 +353,7 @@
                 TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( Integer
                     .parseInt( ids[1] ) );
                 ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute( attribute,
-                    index + 1, personDisplayNames.get( index ) );
+                    index + 1, personDisplayNames.get( index ), mandatory.get( index ) );
                 program.getAttributes().add( programAttribute );
             }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java	2014-03-20 05:43:18 +0000
@@ -94,13 +94,6 @@
         this.valueType = valueType;
     }
 
-    private Boolean mandatory;
-
-    public void setMandatory( Boolean mandatory )
-    {
-        this.mandatory = mandatory;
-    }
-    
     private Boolean inherit;
 
     public void setInherit( Boolean inherit )
@@ -167,10 +160,7 @@
         attribute.setValueType( valueType );
         attribute.setExpression( expression );
         attribute.setDisplayOnVisitSchedule( false );
-
-        mandatory = (mandatory == null) ? false : true;
-        attribute.setMandatory( mandatory );
-
+        
         unique = (unique == null) ? false : true;
         attribute.setUnique( unique );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java	2014-03-20 05:43:18 +0000
@@ -103,13 +103,6 @@
         this.valueType = valueType;
     }
 
-    private Boolean mandatory;
-
-    public void setMandatory( Boolean mandatory )
-    {
-        this.mandatory = mandatory;
-    }
-
     private Boolean unique;
 
     public void setUnique( Boolean unique )
@@ -177,9 +170,6 @@
         attribute.setExpression( expression );
         attribute.setDisplayOnVisitSchedule( false );
 
-        mandatory = (mandatory == null) ? false : true;
-        attribute.setMandatory( mandatory );
-
         unique = (unique == null) ? false : true;
         attribute.setUnique( unique );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm	2014-03-20 05:43:18 +0000
@@ -25,14 +25,6 @@
         <td><input type="text" id="description" name="description" class="{validate:{required:true,minlength:2}}"/></td>
         <td></td>
     </tr>
-    
-	<tr>
-		<td><label for="mandatory">$i18n.getString( "mandatory" )</label></td>
-		<td>
-			<input type='checkbox' id="mandatory" name="mandatory" value='true'>
-		</td>		
-		<td></td>				
-	</tr>
 	
     <tr>
 		<td><label for="unique">$i18n.getString( "unique" )</label></td>
@@ -70,7 +62,7 @@
         </td>
         <td></td>
     </tr>  
-	<tr id="optionSetRow"> 
+	<tr id="optionSetRow" class="hidden"> 
 		<td><label>$i18n.getString( "option_set" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td><select id="optionSetId" name="optionSetId" class="{validate:{required:true}}">
 				#foreach($optionSet in $optionSets)

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm	2014-02-17 16:09:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramForm.vm	2014-03-20 05:43:18 +0000
@@ -14,6 +14,8 @@
 		personDisplayNames.empty();
 		var compulsaryIdentifier = jQuery( "#compulsaryIdentifier" );
 		compulsaryIdentifier.empty();
+		var mandatorySelector = jQuery( "#mandatory" );
+		mandatorySelector.empty();
 		
         if( getFieldValue('type') != 3 ){
 			
@@ -26,6 +28,11 @@
 				if( checked ){
 					isDisplayed = true
 				}
+				
+				// mandatory
+				var mandatory = jQuery( item ).find( "input[name='mandatory']:first");
+				checked = mandatory.attr('checked') ? true : false;
+				mandatorySelector.append( "<option value='" + checked + "' selected='true'>" + checked + "</option>" );
 			});
 			if( jQuery("#selectedList").find("tr").length > 0 && isDisplayed ){
 				compulsaryIdentifier.append( "<option value='0' selected='true'></option>");
@@ -224,6 +231,7 @@
 		<th>$i18n.getString( "select_attributes" )
 			<select style='display:none;' multiple id="selectedPropertyIds" name="selectedPropertyIds" ></select>
 			<select style='display:none;' multiple id="personDisplayNames" name="personDisplayNames" ></select>
+			<select style='display:none;' multiple id="mandatory" name="mandatory" ></select>
 			<select id='compulsaryIdentifier' name="compulsaryIdentifier" multiple="multiple" class="hidden {validate:{required:true}}"></select>
 		</th>
 	  </tr>
@@ -253,6 +261,7 @@
 						<tr>
                             <th style="width:180px;">$i18n.getString( "name" )</th>
                             <th style="width:20px;">$i18n.getString( "displayed_in_list" )</th>
+                            <th style="width:20px;">$i18n.getString( "mandatory" )</th>
                         </tr>
 					</thead>
 					<tbody id="selectedList"></tbody>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm	2014-03-03 08:32:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/attribute.vm	2014-03-20 05:43:18 +0000
@@ -51,11 +51,12 @@
 				</div>
         <p><label class="bold">$i18n.getString( "name" ):</label><br><span id="nameField"></span></p>
         <p><label class="bold">$i18n.getString( "description" ):</label><br><span id="descriptionField"></span></p>
-        <p><label class="bold">$i18n.getString( "mandatory" ):</label><br><span id="mandatoryField"></span></p>
         <p><label class="bold">$i18n.getString( "unique" ):</label><br><span id="uniqueField"></span></p>
         <p><label class="bold">$i18n.getString( "inherit" ):</label><br><span id="inheritField"></span></p>
-				<p><label class="bold">$i18n.getString( "value_type" ):</label><br><span id="valueTypeField"></span></p>
-			</div>
+		<p><label class="bold">$i18n.getString( "value_type" ):</label><br><span id="valueTypeField"></span></p>
+		<p><label class="bold">$i18n.getString( "option_set" ):</label><br><span id="optionSetField"></span></p>
+       	
+		</div>
 
 		</td>
   </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js	2014-03-20 05:43:18 +0000
@@ -19,9 +19,7 @@
 		function ( json ) {
 			setInnerHTML( 'nameField', json.attribute.name );	
 			setInnerHTML( 'descriptionField', json.attribute.description );
-			
-			var mandatory = ( json.attribute.mandatory == 'true') ? i18n_yes : i18n_no;
-			setInnerHTML( 'mandatoryField', mandatory );
+			setInnerHTML( 'optionSetField', json.attribute.optionSet );
 			
 			var unique = ( json.attribute.unique == 'true') ? i18n_yes : i18n_no;
 			setInnerHTML( 'uniqueField', unique );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/program.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/program.js	2014-02-26 15:09:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/program.js	2014-03-20 05:43:18 +0000
@@ -161,9 +161,10 @@
   var selectedList = jQuery("#selectedList");
   jQuery("#availablePropertyIds").children().each(function( i, item ) {
     if( item.selected ) {
-      html = "<tr class='selected' id='" + item.value + "' ondblclick='unSelectProperties( this )'><td onmousedown='select(event,this)'>" + item.text + "</td>";
+      html  = "<tr class='selected' id='" + item.value + "' ondblclick='unSelectProperties( this )'><td onmousedown='select(event,this)'>" + item.text + "</td>";
       html += "<td align='center'><input type='checkbox' name='displayed' value='" + item.value + "'";
-      html += "></td></tr>";
+      html += "></td>"
+	  html += "<td align='center'><input type='checkbox' name='mandatory'></tr>";
       selectedList.append(html);
       jQuery(item).remove();
     }
@@ -179,11 +180,9 @@
   jQuery("#availablePropertyIds").children().each(function( i, item ) {
     html = "<tr class='selected' id='" + item.value + "' ondblclick='unSelectDataElement( this )'><td onmousedown='select(this)'>" + item.text + "</td>";
     html += "<td align='center'><input type='checkbox' name='displayed' value='" + item.value + "'";
-    if( item.value.match("^attr_") == "attr_" ) {
-      html += " style='display:none' ";
-    }
-    html += "'></td></tr>";
-    selectedList.append(html);
+    html += "><td align='center'><input type='checkbox' name='mandatory'></td></tr>";
+    
+	selectedList.append(html);
     jQuery(item).remove();
   });
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm	2014-03-19 06:44:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm	2014-03-20 05:43:18 +0000
@@ -28,14 +28,6 @@
         <td><input type="text" id="description" name="description" value="$encoder.htmlEncode( $attribute.description )" class="{validate:{required:true,minlength:2}}"></td>
       </tr>
       
-      <tr>
-		<td><label for="mandatory">$i18n.getString( "mandatory" )</label></td>
-		<td>
-			<input type='checkbox' id="mandatory" name="mandatory" value='true' #if( $attribute.mandatory ) checked #end>
-		</td>		
-		<td></td>				
-	</tr>
-	
     <tr>
 		<td><label for="unique">$i18n.getString( "unique" )</label></td>
 		<td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm	2014-02-17 16:09:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramForm.vm	2014-03-20 05:43:18 +0000
@@ -12,7 +12,9 @@
 			personDisplayNames.empty();
 			var compulsaryIdentifier = jQuery( "#compulsaryIdentifier" );
 			compulsaryIdentifier.empty();
-			
+			var mandatorySelector = jQuery( "#mandatory" );
+			mandatorySelector.empty();
+		
 			if( getFieldValue('type') != 3 ){
 				var isDisplayed = false;
 				jQuery("#selectedList").find("tr").each( function( i, item ){
@@ -23,6 +25,12 @@
 						isDisplayed = true
 					}
 					personDisplayNames.append( "<option value='" + checked + "' selected='true'>" + checked + "</option>" );
+					
+					// mandatory
+					var mandatory = jQuery( item ).find( "input[name='mandatory']:first");
+					checked = mandatory.attr('checked') ? true : false;
+					mandatorySelector.append( "<option value='" + checked + "' selected='true'>" + checked + "</option>" );
+					
 				});
 				if( jQuery("#selectedList").find("tr").length > 0 && isDisplayed ){
 					compulsaryIdentifier.append( "<option value='0' selected='true'></option>");
@@ -233,6 +241,7 @@
 			<th>$i18n.getString( "select_attributes" )
 				<select style='display:none;' multiple id="selectedPropertyIds" name="selectedPropertyIds" ></select>
 				<select style='display:none;' multiple id="personDisplayNames" name="personDisplayNames" ></select>
+				<select style='display:none;' multiple id="mandatory" name="mandatory" ></select>
 				<select id='compulsaryIdentifier' name="compulsaryIdentifier" multiple="multiple" class="hidden {validate:{required:true}}"></select>
 			</th>
 		  </tr>
@@ -263,6 +272,7 @@
 							<tr>
 								<th style="width:180px;">$i18n.getString( "name" )</th>
 								<th style="width:20px;">$i18n.getString( "displayed_in_list" )</th>
+								<th style="width:20px;">$i18n.getString( "mandatory" )</th>
                             </tr>
 						</thead>
 						<tbody id="selectedList" #if($program.type==3) style="display:none;" #end>
@@ -271,6 +281,7 @@
 								<tr ondblclick="unSelectProperties( this )" id="attr_$programAttribute.attribute.id">
 									<td onmousedown="select(event, this)">$encoder.htmlEncode( $attribute.name )</td>
 									<td align="center"><input type="checkbox" name="displayed" value="attr_$programAttribute.attribute.id" #if($programAttribute.displayedInList == true ) checked #end #if($program.type==3) disabled #end  /></td>
+									<td align="center"><input type="checkbox" name="mandatory" #if($programAttribute.mandatory == "true" ) checked #end #if($program.type==3) disabled #end  /></td>
 								</tr>
 							#end
 						</tbody>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewTrackedEntityForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewTrackedEntityForm.vm	2014-02-26 15:09:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/viewTrackedEntityForm.vm	2014-03-20 05:43:18 +0000
@@ -122,7 +122,10 @@
    			<td>
    				<select id="attributesSelector" multiple="multiple" style="width:450px;height:270px" ondblclick="insertElement( 'attr' )">
    				#foreach( $attribute in $attributes )
-   					<option value="$attribute.uid" mandatory='$attribute.mandatory'>$encoder.htmlEncode($attribute.displayName) #if($attribute.mandatory=='true') * #end</option>
+   					<option value="$attribute.uid" mandatory='false'>$encoder.htmlEncode($attribute.displayName)</option>
+   				#end
+				#foreach( $programAttribute in $programAttributes )
+   					<option value="$programAttribute.attribute.uid" mandatory='programAttribute.mandatory'>$encoder.htmlEncode($programAttribute.attribute.displayName) #if($programAttribute.mandatory=='true') * #end</option>
    				#end
    				</select>
    			</td>