← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12107: Add function to support for uniqueness scope in identifiers based on orgunit, program, and period...

 

------------------------------------------------------------
revno: 12107
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-17 13:08:16 +0700
message:
  Add function to support for uniqueness scope in identifiers based on orgunit, program, and period type.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowAddPatientIdentifierTypeFormAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientIdentifierType.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/AddPatientIdentifierTypeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowUpdatePatientIdentifierTypeForm.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java	2013-09-17 06:08:16 +0000
@@ -30,6 +30,10 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.program.Program;
+
 /**
  * @author Abyot Asalefew Gizaw
  * @version $Id$
@@ -73,5 +77,6 @@
     Collection<PatientIdentifier> getPatientIdentifiers( Collection<PatientIdentifierType> identifierTypes,
         Patient patient );
 
-    boolean checkDuplicateIdentifier( Integer patientId, String identifier );
+    boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier,
+        OrganisationUnit orgunit, Program program, PeriodType periodType );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java	2013-09-17 06:08:16 +0000
@@ -30,6 +30,8 @@
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.program.Program;
 
 import java.util.Collection;
 
@@ -48,7 +50,10 @@
 
     PatientIdentifier get( PatientIdentifierType type, String identifier );
 
-    /* We need this since we have allowed identifiers with duplicate values in the past. This returns a list instead. */
+    /*
+     * We need this since we have allowed identifiers with duplicate values in
+     * the past. This returns a list instead.
+     */
     Collection<PatientIdentifier> getAll( PatientIdentifierType type, String identifier );
 
     Collection<PatientIdentifier> getByIdentifier( String identifier );
@@ -69,6 +74,7 @@
 
     Collection<PatientIdentifier> get( Collection<PatientIdentifierType> identifierTypes, Patient patient );
 
-    boolean checkDuplicateIdentifier( Integer patientId, String identifier );
+    boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier,
+        OrganisationUnit orgunit, Program program, PeriodType periodType );
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java	2013-09-11 15:26:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java	2013-09-17 06:08:16 +0000
@@ -30,13 +30,14 @@
 
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.period.PeriodType;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlRootElement;
 
-@XmlRootElement(name = "patientIdentifierType", namespace = DxfNamespaces.DXF_2_0)
-@XmlAccessorType(value = XmlAccessType.NONE)
+@XmlRootElement( name = "patientIdentifierType", namespace = DxfNamespaces.DXF_2_0 )
+@XmlAccessorType( value = XmlAccessType.NONE )
 public class PatientIdentifierType
     extends BaseIdentifiableObject
 {
@@ -52,8 +53,8 @@
     public static final String VALUE_TYPE_NUMBER = "number";
 
     public static final String VALUE_TYPE_LETTER = "letter";
-    
-    public static final String VALUE_TYPE_ORGUNIT_COUNT = "orgunitCount";
+
+    public static final String VALUE_TYPE_LOCAL_ID = "localId";
 
     private String description;
 
@@ -67,6 +68,14 @@
 
     private Boolean personDisplayName;
 
+    // For Local ID type
+
+    private Boolean orgunitScope;
+
+    private Boolean programScope;
+
+    private PeriodType periodType;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -165,4 +174,34 @@
         this.personDisplayName = personDisplayName;
     }
 
+    public Boolean getOrgunitScope()
+    {
+        return orgunitScope;
+    }
+
+    public void setOrgunitScope( Boolean orgunitScope )
+    {
+        this.orgunitScope = orgunitScope;
+    }
+
+    public Boolean getProgramScope()
+    {
+        return programScope;
+    }
+
+    public void setProgramScope( Boolean programScope )
+    {
+        this.programScope = programScope;
+    }
+
+    public PeriodType getPeriodType()
+    {
+        return periodType;
+    }
+
+    public void setPeriodType( PeriodType periodType )
+    {
+        this.periodType = periodType;
+    }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java	2013-09-17 06:08:16 +0000
@@ -28,6 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.program.Program;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Collection;
@@ -142,8 +145,9 @@
     }
 
     @Override
-    public boolean checkDuplicateIdentifier( Integer patientId, String identifier )
+    public boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier,
+        OrganisationUnit orgunit, Program program, PeriodType periodType )
     {
-        return patientIdentifierStore.checkDuplicateIdentifier( patientId, identifier );
+        return patientIdentifierStore.checkDuplicateIdentifier( patientIdentifierType, identifier, orgunit, program, periodType );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java	2013-09-17 06:08:16 +0000
@@ -33,6 +33,8 @@
 import java.util.Collection;
 
 import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -54,6 +56,13 @@
         this.patientIdentifierTypeStore = patientIdentifierTypeStore;
     }
 
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
     private I18nService i18nService;
 
     public void setI18nService( I18nService service )
@@ -82,11 +91,25 @@
 
     public int savePatientIdentifierType( PatientIdentifierType patientIdentifierType )
     {
+        if ( patientIdentifierType.getPeriodType() != null )
+        {
+            PeriodType periodType = periodService.reloadPeriodType( patientIdentifierType.getPeriodType() );
+
+            patientIdentifierType.setPeriodType( periodType );
+        }
+        
         return patientIdentifierTypeStore.save( patientIdentifierType );
     }
 
     public void updatePatientIdentifierType( PatientIdentifierType patientIdentifierType )
     {
+        if ( patientIdentifierType.getPeriodType() != null )
+        {
+            PeriodType periodType = periodService.reloadPeriodType( patientIdentifierType.getPeriodType() );
+
+            patientIdentifierType.setPeriodType( periodType );
+        }
+
         patientIdentifierTypeStore.update( patientIdentifierType );
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java	2013-09-17 06:08:16 +0000
@@ -29,6 +29,7 @@
  */
 
 import java.util.Collection;
+import java.util.Date;
 
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
@@ -38,6 +39,11 @@
 import org.hisp.dhis.patient.PatientIdentifier;
 import org.hisp.dhis.patient.PatientIdentifierStore;
 import org.hisp.dhis.patient.PatientIdentifierType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.system.util.DateUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
 
 /**
  * @author Abyot Asalefew Gizaw
@@ -47,6 +53,21 @@
     extends HibernateGenericStore<PatientIdentifier>
     implements PatientIdentifierStore
 {
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation methods
+    // -------------------------------------------------------------------------
+
     public PatientIdentifier get( Patient patient )
     {
         return (PatientIdentifier) getCriteria( Restrictions.eq( "patient", patient ) ).uniqueResult();
@@ -67,8 +88,8 @@
     @SuppressWarnings( "unchecked" )
     public Collection<PatientIdentifier> getAll( PatientIdentifierType type, String identifier )
     {
-        return getCriteria( Restrictions.eq( "identifierType", type ),
-            Restrictions.eq( "identifier", identifier ) ).list();
+        return getCriteria( Restrictions.eq( "identifierType", type ), Restrictions.eq( "identifier", identifier ) )
+            .list();
     }
 
     @SuppressWarnings( "unchecked" )
@@ -129,10 +150,31 @@
             .list();
     }
 
-    public boolean checkDuplicateIdentifier( Integer patientId, String identifier )
+    @SuppressWarnings( "deprecation" )
+    public boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier,
+        OrganisationUnit orgunit, Program program, PeriodType periodType )
     {
-        Number rs = (Number) getCriteria( Restrictions.eq( "patient.id", patientId ) , Restrictions.ilike( "identifier", identifier ) ).setProjection(
-            Projections.rowCount() ).uniqueResult();
-        return ( rs != null & rs.intValue() > 0 )? true: false;
+        String sql = "select count(*) from patientidentifier pi inner join patient p on pi.patientid=p.patientid "
+            + "inner join programinstance pis on pis.patientid=pi.patientid where pi.patientidentifiertypeid="
+            + patientIdentifierType.getId() + " and pi.identifier='" + identifier + "' ";
+        if ( orgunit != null )
+        {
+            sql += " and p.organisationunitid=" + orgunit.getId();
+        }
+
+        if ( program != null )
+        {
+            sql += " and pis.programid=" + program.getId();
+        }
+
+        if ( periodType != null )
+        {
+            Date currentDate = new Date();
+            Period period = periodType.createPeriod( currentDate );
+            sql += " and pis.enrollmentdate >='" + period.getStartDateString() + "' and pis.enrollmentdate <='"
+                + DateUtils.getMediumDateString( period.getEndDate() )  + "'";
+        }
+
+        return jdbcTemplate.queryForInt( sql ) == 0 ? false : true;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-10 04:51:49 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-17 06:08:16 +0000
@@ -89,6 +89,7 @@
 		class="org.hisp.dhis.patient.hibernate.HibernatePatientIdentifierStore">
 		<property name="clazz" value="org.hisp.dhis.patient.PatientIdentifier" />
 		<property name="sessionFactory" ref="sessionFactory" />
+		<property name="jdbcTemplate" ref="jdbcTemplate" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientIdentifierTypeStore"
@@ -261,6 +262,7 @@
 		<property name="patientIdentifierTypeStore"
 			ref="org.hisp.dhis.patient.PatientIdentifierTypeStore" />
 		<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientAttributeService" class="org.hisp.dhis.patient.DefaultPatientAttributeService">

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientIdentifierType.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientIdentifierType.hbm.xml	2013-02-07 10:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/PatientIdentifierType.hbm.xml	2013-09-17 06:08:16 +0000
@@ -8,7 +8,7 @@
 <hibernate-mapping>
   <class name="org.hisp.dhis.patient.PatientIdentifierType" table="patientidentifiertype">
 
-    <id name="id" column="patientidentifiertypeid">
+   <id name="id" column="patientidentifiertypeid">
       <generator class="native" />
     </id>
     &identifiableProperties;
@@ -27,5 +27,12 @@
 
     <property name="personDisplayName" />
 
+    <property name="orgunitScope" />
+
+    <property name="programScope" />
+    
+    <many-to-one name="periodType" class="org.hisp.dhis.period.PeriodType" column="periodtypeid"
+      	foreign-key="fk_patientidentifiertype_periodtypeid" />
+	
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2013-09-17 06:08:16 +0000
@@ -29,10 +29,13 @@
  */
 
 import com.opensymphony.xwork2.Action;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientIdentifier;
 import org.hisp.dhis.patient.PatientIdentifierService;
@@ -46,6 +49,7 @@
 import org.hisp.dhis.validation.ValidationCriteria;
 
 import javax.servlet.http.HttpServletRequest;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -74,6 +78,8 @@
 
     private ProgramService programService;
 
+    private OrganisationUnitSelectionManager selectionManager;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -191,11 +197,30 @@
 
                     if ( StringUtils.isNotBlank( value ) )
                     {
-                        boolean isDuplicate = patientIdentifierService.checkDuplicateIdentifier( id, value );
+                        boolean isDuplicate = false;
+
+                        if ( idType.getType().equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) )
+                        {
+                            OrganisationUnit orgunit = (idType.getOrgunitScope()) ? selectionManager
+                                .getSelectedOrganisationUnit() : null;
+
+                            Program program = (idType.getProgramScope()) ? programService.getProgram( programId )
+                                : null;
+                            isDuplicate = patientIdentifierService.checkDuplicateIdentifier( idType, value, orgunit,
+                                program, idType.getPeriodType() );
+                        }
+                        else
+                        {
+                            PatientIdentifier identifier = patientIdentifierService.get( idType, value );
+                            if ( identifier != null && (id == null || identifier.getPatient().getId() != id) )
+                            {
+                                idDuplicate += idType.getName() + ", ";
+                            }
+                        }
 
                         if ( isDuplicate )
                         {
-                            idDuplicate += value + ", ";
+                            idDuplicate += idType.getName() + ", ";
                         }
                     }
                 }
@@ -291,6 +316,11 @@
         this.patientService = patientService;
     }
 
+    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
+    {
+        this.selectionManager = selectionManager;
+    }
+
     public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
     {
         this.patientAttributeValueService = patientAttributeValueService;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-09-11 16:02:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-09-17 06:08:16 +0000
@@ -560,6 +560,9 @@
 		<property name="identifierTypeService">
 			<ref bean="org.hisp.dhis.patient.PatientIdentifierTypeService" />
 		</property>
+		<property name="selectionManager">
+			<ref bean="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
+		</property>
 	</bean>
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2013-09-09 18:36:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2013-09-17 06:08:16 +0000
@@ -79,25 +79,7 @@
 				var patientId = json.message.split('_')[0];
 				var	dateOfIncident = jQuery('#patientForm [id=dateOfIncident]').val();
 				var enrollmentDate = jQuery('#patientForm [id=enrollmentDate]').val();
-					
-				var originalPatientId = getFieldValue('patientId');
-				var relatedPatientId = patientId;
-				if(getFieldValue('relationshipFromA')=='false')
-				{
-					originalPatientId = patientId;
-					relatedPatientId = getFieldValue('patientId');
-				}
-				var relatedPatientId = 
-				jQuery.postJSON( "saveProgramEnrollment.action",
-				{
-					originalPatientId: originalPatientId,
-					relationshipTypeId: getFieldValue('relationshipTypeId'),
-					relatedPatientId: relatedPatientId
-				}, 
-				function( json ) 
-				{
-				});
-					
+				
 				if( programId !='' && enrollmentDate != '')
 				{
 					jQuery.postJSON( "saveProgramEnrollment.action",

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/AddPatientIdentifierTypeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/AddPatientIdentifierTypeAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/AddPatientIdentifierTypeAction.java	2013-09-17 06:08:16 +0000
@@ -30,6 +30,8 @@
 
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
 
 import com.opensymphony.xwork2.Action;
 
@@ -45,7 +47,19 @@
     // -------------------------------------------------------------------------
 
     private PatientIdentifierTypeService patientIdentifierTypeService;
-    
+
+    public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
+    {
+        this.patientIdentifierTypeService = patientIdentifierTypeService;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -62,6 +76,14 @@
 
     private String type;
 
+    // For Local ID type
+
+    private Boolean orgunitScope;
+
+    private Boolean programScope;
+
+    private String periodTypeName;
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
@@ -86,11 +108,6 @@
         this.description = description;
     }
 
-    public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
-    {
-        this.patientIdentifierTypeService = patientIdentifierTypeService;
-    }
-
     public void setMandatory( Boolean mandatory )
     {
         this.mandatory = mandatory;
@@ -101,6 +118,26 @@
         this.related = related;
     }
 
+    public Boolean getOrgunitScope()
+    {
+        return orgunitScope;
+    }
+
+    public void setProgramScope( Boolean programScope )
+    {
+        this.programScope = programScope;
+    }
+
+    public void setOrgunitScope( Boolean orgunitScope )
+    {
+        this.orgunitScope = orgunitScope;
+    }
+
+    public void setPeriodTypeName( String periodTypeName )
+    {
+        this.periodTypeName = periodTypeName;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -111,16 +148,27 @@
         PatientIdentifierType identifierType = new PatientIdentifierType();
         identifierType.setName( name );
         identifierType.setDescription( description );
-        
+
         related = (related == null) ? false : true;
         identifierType.setRelated( related );
-        
+
         mandatory = (mandatory == null) ? false : true;
         identifierType.setMandatory( mandatory );
-        
+
         identifierType.setNoChars( noChars );
         identifierType.setType( type );
 
+        if ( type.equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) )
+        {
+            orgunitScope = (orgunitScope == null) ? false : orgunitScope;
+            programScope = (programScope == null) ? false : programScope;
+            PeriodType periodType = (periodTypeName == null) ? null : periodService
+                .getPeriodTypeByName( periodTypeName );
+
+            identifierType.setOrgunitScope( orgunitScope );
+            identifierType.setProgramScope( programScope );
+            identifierType.setPeriodType( periodType );
+        }
         patientIdentifierTypeService.savePatientIdentifierType( identifierType );
 
         return SUCCESS;

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowAddPatientIdentifierTypeFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowAddPatientIdentifierTypeFormAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowAddPatientIdentifierTypeFormAction.java	2013-09-17 06:08:16 +0000
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient.action.patientidentifiertype;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ShowAddPatientIdentifierTypeFormAction.java Sep 16, 2013 9:26:58
+ *          PM $
+ */
+public class ShowAddPatientIdentifierTypeFormAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private List<PeriodType> periodTypes = new ArrayList<PeriodType>();
+
+    public List<PeriodType> getPeriodTypes()
+    {
+        return periodTypes;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters && Setters
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        periodTypes = periodService.getAllPeriodTypes();
+        
+        return SUCCESS;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowUpdatePatientIdentifierTypeForm.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowUpdatePatientIdentifierTypeForm.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/ShowUpdatePatientIdentifierTypeForm.java	2013-09-17 06:08:16 +0000
@@ -28,10 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 
@@ -53,6 +57,8 @@
 
     private ProgramService programService;
 
+    private PeriodService periodService;
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -63,6 +69,8 @@
 
     private Collection<Program> programs;
 
+    private List<PeriodType> periodTypes = new ArrayList<PeriodType>();
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
@@ -72,6 +80,11 @@
         return patientIdentifierType;
     }
 
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
     public Collection<Program> getPrograms()
     {
         return programs;
@@ -97,6 +110,11 @@
         this.patientIdentifierTypeService = patientIdentifierTypeService;
     }
 
+    public List<PeriodType> getPeriodTypes()
+    {
+        return periodTypes;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -105,6 +123,8 @@
         throws Exception
     {
         patientIdentifierType = patientIdentifierTypeService.getPatientIdentifierType( id );
+        
+        periodTypes = periodService.getAllPeriodTypes();
 
         programs = programService.getAllPrograms();
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java	2013-09-17 06:08:16 +0000
@@ -30,6 +30,8 @@
 
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
 
 import com.opensymphony.xwork2.Action;
 
@@ -46,6 +48,18 @@
 
     private PatientIdentifierTypeService patientIdentifierTypeService;
 
+    public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
+    {
+        this.patientIdentifierTypeService = patientIdentifierTypeService;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -64,6 +78,14 @@
 
     private String type;
 
+    // For Local ID type
+
+    private Boolean orgunitScope;
+
+    private Boolean programScope;
+
+    private String periodTypeName;
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
@@ -88,11 +110,6 @@
         this.name = name;
     }
 
-    public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
-    {
-        this.patientIdentifierTypeService = patientIdentifierTypeService;
-    }
-
     public void setId( Integer id )
     {
         this.id = id;
@@ -107,7 +124,22 @@
     {
         this.related = related;
     }
-    
+
+    public void setOrgunitScope( Boolean orgunitScope )
+    {
+        this.orgunitScope = orgunitScope;
+    }
+
+    public void setProgramScope( Boolean programScope )
+    {
+        this.programScope = programScope;
+    }
+
+    public void setPeriodTypeName( String periodTypeName )
+    {
+        this.periodTypeName = periodTypeName;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -120,16 +152,27 @@
         {
             identifierType.setName( name );
             identifierType.setDescription( description );
-            
+
             related = (related == null) ? false : true;
             identifierType.setRelated( related );
-            
+
             mandatory = (mandatory == null) ? false : true;
             identifierType.setMandatory( mandatory );
-            
+
             identifierType.setNoChars( noChars );
             identifierType.setType( type );
 
+            if ( type.equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) )
+            {
+                orgunitScope = (orgunitScope == null) ? false : orgunitScope;
+                programScope = (programScope == null) ? false : programScope;
+                PeriodType periodType = periodService.getPeriodTypeByName( periodTypeName );
+
+                identifierType.setOrgunitScope( orgunitScope );
+                identifierType.setProgramScope( programScope );
+                identifierType.setPeriodType( periodType );
+            }
+
             patientIdentifierTypeService.updatePatientIdentifierType( identifierType );
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-05 17:59:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-17 06:08:16 +0000
@@ -159,7 +159,7 @@
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.patient.action.patientattribute.SavePatientAttributeVisitScheduleAction"
 		class="org.hisp.dhis.patient.action.patientattribute.SavePatientAttributeVisitScheduleAction"
@@ -167,7 +167,7 @@
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 	</bean>
-	
+
 	<!-- Program -->
 
 	<bean id="org.hisp.dhis.patient.action.program.AddProgramAction"
@@ -179,9 +179,8 @@
 			ref="org.hisp.dhis.patient.PatientIdentifierTypeService" />
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
-		<property name="userGroupService" 
-			ref="org.hisp.dhis.user.UserGroupService" />	
-		<property name="relationshipTypeService" 
+		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+		<property name="relationshipTypeService"
 			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 
@@ -224,7 +223,7 @@
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
-		<property name="relationshipTypeService" 
+		<property name="relationshipTypeService"
 			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 
@@ -238,7 +237,7 @@
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
-		<property name="relationshipTypeService" 
+		<property name="relationshipTypeService"
 			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 	<bean id="org.hisp.dhis.patient.action.program.UpdateProgramAction"
@@ -249,9 +248,8 @@
 			ref="org.hisp.dhis.patient.PatientIdentifierTypeService" />
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
-		<property name="userGroupService"
-			ref="org.hisp.dhis.user.UserGroupService" />
-		<property name="relationshipTypeService" 
+		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+		<property name="relationshipTypeService"
 			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 
@@ -340,8 +338,7 @@
 		<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
 		<property name="programStageDataElementService"
 			ref="org.hisp.dhis.program.ProgramStageDataElementService" />
-		<property name="userGroupService"
-			ref="org.hisp.dhis.user.UserGroupService" />
+		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
 	</bean>
 
 	<bean
@@ -573,7 +570,7 @@
 			<ref bean="org.hisp.dhis.patient.PatientRegistrationFormService" />
 		</property>
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.patient.action.dataentryform.ShowDefaultPatientRegistrationFormAction"
 		class="org.hisp.dhis.patient.action.dataentryform.ShowDefaultPatientRegistrationFormAction"
@@ -591,7 +588,7 @@
 			<ref bean="org.hisp.dhis.patient.PatientIdentifierTypeService" />
 		</property>
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.patient.action.dataentryform.SaveDefaultPatientRegistrationFormAcion"
 		class="org.hisp.dhis.patient.action.dataentryform.SaveDefaultPatientRegistrationFormAcion"
@@ -717,12 +714,20 @@
 	<!-- Patient Identifier Type -->
 
 	<bean
+		id="org.hisp.dhis.patient.action.patientidentifiertype.ShowAddPatientIdentifierTypeFormAction"
+		class="org.hisp.dhis.patient.action.patientidentifiertype.ShowAddPatientIdentifierTypeFormAction"
+		scope="prototype">
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+	</bean>
+
+	<bean
 		id="org.hisp.dhis.patient.action.patientidentifiertype.AddPatientIdentifierTypeAction"
 		class="org.hisp.dhis.patient.action.patientidentifiertype.AddPatientIdentifierTypeAction"
 		scope="prototype">
 		<property name="patientIdentifierTypeService">
 			<ref bean="org.hisp.dhis.patient.PatientIdentifierTypeService" />
 		</property>
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
 	</bean>
 
 	<bean
@@ -778,6 +783,9 @@
 		<property name="programService">
 			<ref bean="org.hisp.dhis.program.ProgramService" />
 		</property>
+		<property name="periodService">
+			<ref bean="org.hisp.dhis.period.PeriodService" />
+		</property>
 	</bean>
 
 	<!-- Case Aggregation Mapping -->
@@ -1197,7 +1205,7 @@
 			<ref bean="org.hisp.dhis.program.ProgramIndicatorService" />
 		</property>
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.patient.action.programtindicator.GetProgramIndicatorDescripttionAction"
 		class="org.hisp.dhis.patient.action.programtindicator.GetProgramIndicatorDescripttionAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-09-17 06:08:16 +0000
@@ -472,4 +472,6 @@
 both = Both
 direct_sms = Direct SMS
 remind_creating_next_event_on_this_event_completed = Remind creating next event on this event completed
-data_entry_method = Data entry method
\ No newline at end of file
+data_entry_method = Data entry method
+local_identifier = Local Identifier
+scope = Scope
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2013-07-30 09:28:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2013-09-17 06:08:16 +0000
@@ -731,7 +731,7 @@
 		<!-- Patient Identifier Type -->
 
 		<action name="showAddPatientIdentifierTypeForm"
-			class="org.hisp.dhis.patient.action.program.GetUnAnonymousProgramAction">
+			class="org.hisp.dhis.patient.action.patientidentifiertype.ShowAddPatientIdentifierTypeFormAction">
 			<result name="success" type="velocity">/main.vm</result>
 			<param name="page">
 				/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm</param>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm	2013-07-04 06:47:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientIdentifierTypeForm.vm	2013-09-17 06:08:16 +0000
@@ -42,7 +42,7 @@
 		<tr>
 			<td><label for="noChar">$i18n.getString( "no_of_char" )</label></td>
 			<td>
-				<input style="width: 330px;" type="text" name="noChars" id="noChars" class="{validate:{required:false, number:true}}" />
+				<input style="width: 330px;" type="text" name="noChars" id="noChars" class="{validate:{number:true}}" />
 			</td>
 			<td></td>
 		</tr>
@@ -54,7 +54,40 @@
 					<option value="string" selected="selected">$i18n.getString( "text" )</option>
 					<option value="number">$i18n.getString( "number" )</option>
 					<option value="letter">$i18n.getString( "letter_only" )</option>
-					<option value="orgunitCount">$i18n.getString( "orgunit_count" )</option>
+					<option value="localId">$i18n.getString( "local_identifier" )</option>
+				</select>
+			</td>
+			<td></td>
+		</tr>
+		
+		<tr name='localIdField' style='display:none;'>
+			<th colspan='2'><label for="type">$i18n.getString( "scope" )</label></th>
+		</tr>
+			
+		<tr name='localIdField' style='display:none;'>
+			<td><label for="type">$i18n.getString( "orgunit" )</label></td>
+			<td>
+				<input type='checkbox' id="orgunitScope" name="orgunitScope" value='true' >
+			</td>
+			<td></td>
+		</tr>
+		
+		<tr name='localIdField' style='display:none;'>
+			<td><label for="type">$i18n.getString( "program" )</label></td>
+			<td>
+				<input type='checkbox' id="programScope" name="programScope" value='true' >
+			</td>
+			<td></td>
+		</tr>
+		
+		<tr name='localIdField' style='display:none;'>
+			<td><label for="type">$i18n.getString( "period_type" )</label></td>
+			<td>
+				<select type='checkbox' id="periodTypeName" name="periodTypeName" >
+					<option value="">[$i18n.getString( "please_select" )]</option>
+					#foreach ( $periodType in $periodTypes )
+					<option value="$periodType.name">$i18n.getString( $periodType.name )</option>
+					#end
 				</select>
 			</td>
 			<td></td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm	2013-09-17 06:08:16 +0000
@@ -128,7 +128,7 @@
 		</tr>
 		
 		<tr>
-			<td><label>$i18n.getString( "default_data_entry_method" ) </label></td>
+			<td><label>$i18n.getString( "data_entry_method" ) </label></td>
 			<td>
 				<input type='checkbox' id='dataEntryMethod' name='dataEntryMethod' value='true' >
 			</td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js	2013-07-17 08:40:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientIdentifierType.js	2013-09-17 06:08:16 +0000
@@ -37,12 +37,12 @@
 function typeOnChange()
 {
 	var type = getFieldValue('type');
-	if(type=='orgunitCount')
+	if(type=='localId')
 	{
-		disable('noChars');
+		jQuery('[name=localIdField]').show();
 	}
 	else
 	{
-		enable('noChars');
+		jQuery('[name=localIdField]').hide();
 	}
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm	2013-07-04 09:32:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientIdentifierType.vm	2013-09-17 06:08:16 +0000
@@ -43,7 +43,7 @@
 		<tr>
 			<td><label for="noChars">$i18n.getString( "no_of_char" )</label></td>
 			<td>
-				<input style="width: 330px;" type="text" name="noChars" id="noChars" #if( $patientIdentifierType.type=='orgunitCount' ) disabled #end value="$!patientIdentifierType.noChars" class="{validate:{required:false, number:true}}" />
+				<input style="width: 330px;" type="text" name="noChars" id="noChars" value="$!patientIdentifierType.noChars" class="{validate:{number:true}}" />
 			</td>		
 			<td></td>				
 		</tr> 	
@@ -55,12 +55,44 @@
 					<option value="string" #if( $patientIdentifierType.type=='string' ) selected="selected" #end>$i18n.getString( "text" )</option>
 					<option value="number" #if( $patientIdentifierType.type=='number' ) selected="selected" #end>$i18n.getString( "number" )</option>
 					<option value="letter" #if( $patientIdentifierType.type=='letter' ) selected="selected" #end>$i18n.getString( "letter_only" )</option>
-					<option value="orgunitCount" #if( $patientIdentifierType.type=='orgunitCount' ) selected="selected" #end>$i18n.getString( "orgunit_count" )</option>
+					<option value="localId" #if( $patientIdentifierType.type=='localId' ) selected="selected" #end>$i18n.getString( "local_identifier" )</option>
 				</select>
 			</td>		
 			<td></td>				
 		</tr>
 		
+		<tr name='localIdField' #if($patientIdentifierType.type!='localId' ) style='display:none;' #end >
+			<th colspan='2'><label for="type">$i18n.getString( "scope" )</label></th>
+		</tr>
+			
+		<tr name='localIdField' #if($patientIdentifierType.type!='localId' ) style='display:none;' #end >
+			<td><label for="type">$i18n.getString( "orgunit" )</label></td>
+			<td>
+				<input type='checkbox' id="orgunitScope" name="orgunitScope" value='true' #if( $patientIdentifierType.orgunitScope=='true' ) checked #end >
+			</td>
+			<td></td>
+		</tr>
+		
+		<tr name='localIdField' #if($patientIdentifierType.type!='localId' ) style='display:none;' #end>
+			<td><label for="type">$i18n.getString( "program" )</label></td>
+			<td>
+				<input type='checkbox' id="programScope" name="programScope" value='true'  #if( $patientIdentifierType.programScope=='true' ) checked #end >
+			</td>
+			<td></td>
+		</tr>
+		
+		<tr name='localIdField' #if($patientIdentifierType.type!='localId' ) style='display:none;' #end>
+			<td><label for="type">$i18n.getString( "period_type" )</label></td>
+			<td>
+				<select type='checkbox' id="periodTypeName" name="periodTypeName" >
+					<option value="">[$i18n.getString( "please_select" )]</option>
+					#foreach ( $periodType in $periodTypes )
+					<option value="$periodType.name" #if( $patientIdentifierType.periodType.name==$periodType.name ) selected #end>$i18n.getString( $periodType.name )</option>
+					#end
+				</select>
+			</td>
+			<td></td>
+		</tr>
 	</tbody>
 	<tr>
 		<td></td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm	2013-09-16 09:47:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm	2013-09-17 06:08:16 +0000
@@ -82,7 +82,7 @@
 });
 
 </script>
-
+$program.dataEntryMethod
 <h3>$i18n.getString( "edit_program" )</h3>
 
 <form id="updateProgramForm" name="updateProgramForm" action="updateProgram.action" method="post" onsubmit="selectAllById('selectedPropertyIds');" >
@@ -127,9 +127,9 @@
 		</tr>
 		
 		<tr>
-			<td><label>$i18n.getString( "default_data_entry_method" ) </label></td>
+			<td><label>$i18n.getString( "data_entry_method" ) </label></td>
 			<td>
-				<input type='checkbox' id='dataEntryMethod' name='dataEntryMethod' value='true' #if( $program.dataEntryMethod=='true' ) selected #end >
+				<input type='checkbox' id='dataEntryMethod' name='dataEntryMethod' value='true' #if( $program.dataEntryMethod=='true' ) checked #end >
 			</td>
 			<td></td>
 		</tr>