← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12044: Add functionality to Share of attributes across multiple programs; separate authorities for edit...

 

------------------------------------------------------------
revno: 12044
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-11 23:02:06 +0700
message:
  Add functionality to Share of attributes across multiple programs;  separate authorities for editing identifiers, attributes and fixed attributes.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.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/java/org/hisp/dhis/program/DefaultProgramService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties


--
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/ProgramService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java	2013-09-11 16:02:06 +0000
@@ -50,6 +50,8 @@
     Program getProgram( int id );
 
     Program getProgramByName( String name );
+    
+    Program getProgramByCode( String code );
 
     Collection<Program> getAllPrograms();
 

=== 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-11 04:12:50 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java	2013-09-11 16:02:06 +0000
@@ -126,6 +126,6 @@
     {
         Number rs = (Number) getCriteria( Restrictions.ilike( "identifier", identifier ) ).setProjection(
             Projections.rowCount() ).uniqueResult();
-        return rs != null ? true: false;
+        return ( rs != null & rs.intValue() > 0 )? true: false;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2013-09-11 16:02:06 +0000
@@ -69,7 +69,7 @@
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
-    
+
     @Override
     public int saveProgram( Program program )
     {
@@ -175,11 +175,16 @@
     {
         return i18n( i18nService, programStore.getByUid( uid ) );
     }
-    
+
     @Override
     public Collection<Program> getProgramsByDisplayOnAllOrgunit( boolean displayOnAllOrgunit, OrganisationUnit orgunit )
     {
-         return i18n( i18nService, programStore.getProgramsByDisplayOnAllOrgunit( displayOnAllOrgunit, orgunit ) );
-    }
-    
+        return i18n( i18nService, programStore.getProgramsByDisplayOnAllOrgunit( displayOnAllOrgunit, orgunit ) );
+    }
+
+    public Program getProgramByCode( String code )
+    {
+        return i18n( i18nService, programStore.getByCode( code ) );
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-09-03 06:39:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-09-11 16:02:06 +0000
@@ -81,8 +81,6 @@
 
     private PatientAttributeValueService patientAttributeValueService;
 
-    private PatientAttributeService patientAttributeService;
-
     private PatientIdentifierTypeService patientIdentifierTypeService;
 
     private RelationshipService relationshipService;
@@ -95,6 +93,8 @@
 
     private PatientAttributeGroupService attributeGroupService;
 
+    private PatientAttributeService attributeService;
+
     private I18n i18n;
 
     private I18nFormat format;
@@ -135,6 +135,8 @@
 
     private Integer programId;
 
+    private Map<String, List<PatientAttribute>> attributesMap = new HashMap<String, List<PatientAttribute>>();
+
     public void setProgramId( Integer programId )
     {
         this.programId = programId;
@@ -159,6 +161,16 @@
         this.programStageInstanceId = programStageInstanceId;
     }
 
+    public void setAttributeService( PatientAttributeService attributeService )
+    {
+        this.attributeService = attributeService;
+    }
+
+    public Map<String, List<PatientAttribute>> getAttributesMap()
+    {
+        return attributesMap;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -219,44 +231,45 @@
             }
         }
 
+        List<PatientAttribute> attributes = new ArrayList<PatientAttribute>();
+
         if ( customRegistrationForm == null )
         {
-            // -------------------------------------------------------------------------
-            // Get identifier-types && attributes
-            // -------------------------------------------------------------------------
-
-            programs = programService.getAllPrograms();
-
-            // -------------------------------------------------------------------------
-            // Get identifier-types && attributes
-            // -------------------------------------------------------------------------
-
-            identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
-            Collection<PatientAttribute> patientAttributesInProgram = new HashSet<PatientAttribute>();
-
-            noGroupAttributes = patientAttributeService.getPatientAttributesWithoutGroup();
-
-            Collection<Program> programs = programService.getAllPrograms();
-            programs.remove( program );
-
-            for ( Program _program : programs )
-            {
-                identifierTypes.removeAll( _program.getPatientIdentifierTypes() );
-                patientAttributesInProgram.removeAll( _program.getPatientAttributes() );
-                noGroupAttributes.removeAll( _program.getPatientAttributes() );
-            }
-
             attributeGroups = new ArrayList<PatientAttributeGroup>(
                 attributeGroupService.getAllPatientAttributeGroups() );
             Collections.sort( attributeGroups, new PatientAttributeGroupSortOrderComparator() );
-            for ( PatientAttributeGroup attributeGroup : attributeGroups )
-            {
-                List<PatientAttribute> attributes = attributeGroup.getAttributes();
-                attributes.removeAll( patientAttributesInProgram );
-
-                if ( attributes.size() > 0 )
-                {
-                    attributeGroupsMap.put( attributeGroup.getId(), attributes );
+
+            if ( program == null )
+            {
+                identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
+                attributes = new ArrayList<PatientAttribute>( attributeService.getAllPatientAttributes() );
+                Collection<Program> programs = programService.getAllPrograms();
+                for ( Program p : programs )
+                {
+                    identifierTypes.removeAll( p.getPatientIdentifierTypes() );
+                    attributes.removeAll( p.getPatientAttributes() );
+                }
+            }
+            else
+            {
+                identifierTypes = program.getPatientIdentifierTypes();
+                attributes = program.getPatientAttributes();
+            }
+
+            for ( PatientAttribute attribute : attributes )
+            {
+                PatientAttributeGroup patientAttributeGroup = attribute.getPatientAttributeGroup();
+                String groupName = (patientAttributeGroup == null) ? "" : patientAttributeGroup.getDisplayName();
+                if ( attributesMap.containsKey( groupName ) )
+                {
+                    List<PatientAttribute> attrs = attributesMap.get( groupName );
+                    attrs.add( attribute );
+                }
+                else
+                {
+                    List<PatientAttribute> attrs = new ArrayList<PatientAttribute>();
+                    attrs.add( attribute );
+                    attributesMap.put( groupName, attrs );
                 }
             }
 
@@ -389,11 +402,6 @@
         this.patientAttributeValueService = patientAttributeValueService;
     }
 
-    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
-    {
-        this.patientAttributeService = patientAttributeService;
-    }
-
     public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
     {
         this.patientIdentifierTypeService = patientIdentifierTypeService;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java	2013-09-05 17:59:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java	2013-09-11 16:02:06 +0000
@@ -32,7 +32,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -102,6 +101,13 @@
         this.attributeService = attributeService;
     }
 
+    private PatientService patientService;
+
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
     private PatientAttributeGroupService attributeGroupService;
 
     public void setAttributeGroupService( PatientAttributeGroupService attributeGroupService )
@@ -109,13 +115,6 @@
         this.attributeGroupService = attributeGroupService;
     }
 
-    private PatientService patientService;
-
-    public void setPatientService( PatientService patientService )
-    {
-        this.patientService = patientService;
-    }
-
     private I18n i18n;
 
     public void setI18n( I18n i18n )
@@ -167,13 +166,6 @@
         return healthWorkers;
     }
 
-    private Collection<PatientAttribute> noGroupAttributes = new HashSet<PatientAttribute>();
-
-    public Collection<PatientAttribute> getNoGroupAttributes()
-    {
-        return noGroupAttributes;
-    }
-
     private Collection<PatientIdentifierType> identifierTypes;
 
     public Collection<PatientIdentifierType> getIdentifierTypes()
@@ -181,6 +173,13 @@
         return identifierTypes;
     }
 
+    private Map<String, List<PatientAttribute>> attributesMap = new HashMap<String, List<PatientAttribute>>();
+
+    public Map<String, List<PatientAttribute>> getAttributesMap()
+    {
+        return attributesMap;
+    }
+
     private OrganisationUnit organisationUnit;
 
     public OrganisationUnit getOrganisationUnit()
@@ -270,36 +269,48 @@
             }
         }
 
+        List<PatientAttribute> attributes = new ArrayList<PatientAttribute>();
+
         if ( customRegistrationForm == null )
         {
-            identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
-
-            Collection<PatientAttribute> patientAttributesInProgram = new HashSet<PatientAttribute>();
-            Collection<Program> programs = programService.getAllPrograms();
-            programs.remove( program );
-
-            for ( Program _program : programs )
-            {
-                identifierTypes.removeAll( _program.getPatientIdentifierTypes() );
-                patientAttributesInProgram.addAll( _program.getPatientAttributes() );
-            }
-
             attributeGroups = new ArrayList<PatientAttributeGroup>(
                 attributeGroupService.getAllPatientAttributeGroups() );
             Collections.sort( attributeGroups, new PatientAttributeGroupSortOrderComparator() );
-            for ( PatientAttributeGroup attributeGroup : attributeGroups )
-            {
-                List<PatientAttribute> attributes = attributeGroup.getAttributes();
-                attributes.removeAll( patientAttributesInProgram );
-
-                if ( attributes.size() > 0 )
-                {
-                    attributeGroupsMap.put( attributeGroup.getId(), attributes );
-                }
-            }
-
-            noGroupAttributes = attributeService.getPatientAttributesWithoutGroup();
-            noGroupAttributes.removeAll( patientAttributesInProgram );
+
+            if ( program == null )
+            {
+                identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
+                attributes = new ArrayList<PatientAttribute>( attributeService.getAllPatientAttributes() );
+                Collection<Program> programs = programService.getAllPrograms();
+                for ( Program p : programs )
+                {
+                    identifierTypes.removeAll( p.getPatientIdentifierTypes() );
+                    attributes.removeAll( p.getPatientAttributes() );
+                }
+            }
+            else
+            {
+                identifierTypes = program.getPatientIdentifierTypes();
+                attributes = program.getPatientAttributes();
+            }
+
+            for ( PatientAttribute attribute : attributes )
+            {
+                PatientAttributeGroup patientAttributeGroup = attribute.getPatientAttributeGroup();
+                String groupName = (patientAttributeGroup == null) ? "" : patientAttributeGroup.getDisplayName();
+                if ( attributesMap.containsKey( groupName ) )
+                {
+                    List<PatientAttribute> attrs = attributesMap.get( groupName );
+                    attrs.add( attribute );
+                }
+                else
+                {
+                    List<PatientAttribute> attrs = new ArrayList<PatientAttribute>();
+                    attrs.add( attribute );
+                    attributesMap.put( groupName, attrs );
+                }
+            }
+
         }
 
         orgunitCountIdentifier = generateOrgunitIdentifier( organisationUnit );

=== 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 09:50:12 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-09-11 16:02:06 +0000
@@ -455,7 +455,7 @@
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="patientAttributeValueService"
 			ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
-		<property name="patientAttributeService">
+		<property name="attributeService">
 			<ref bean="org.hisp.dhis.patient.PatientAttributeService" />
 		</property>
 		<property name="patientIdentifierTypeService"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2013-09-06 15:53:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2013-09-11 16:02:06 +0000
@@ -1197,6 +1197,24 @@
 			</result>
 			<param name="requiredAuthorities">F_ACCESS_PATIENT_ATTRIBUTES</param>
 		</action>
+		
+		<action name="allowEditPatientFixedAttributes" class="org.hisp.dhis.caseentry.action.NoAction">
+			<result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+			<param name="requiredAuthorities">F_ALLOW_EDIT_PATIENT_PROPERTIES</param>
+		</action>
+		
+		<action name="allowEditPatientAttributes" class="org.hisp.dhis.caseentry.action.NoAction">
+			<result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+			<param name="requiredAuthorities">F_ALLOW_EDIT_PATIENT_ATTRIBUTES</param>
+		</action>
+		
+		<action name="allowEditPatientIdentifier" class="org.hisp.dhis.caseentry.action.NoAction">
+			<result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+			<param name="requiredAuthorities">F_ALLOW_EDIT_PATIENT_IDENTIFIERS</param>
+		</action>
 
 
 		<!-- Program-stage-completeness -->

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-09-09 18:00:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-09-11 16:02:06 +0000
@@ -16,7 +16,7 @@
 	  #end
 	#end
 	
-	<tr id='registrationDateTR'>
+	<tr id='registrationDateTR' name='propertiesField'>
 		<td class='text-column'><label for="registration_date">$i18n.getString( "registration_date" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td class="input-column" colspan='2'>
 			<input type="text" id="registrationDate" name="registrationDate" class="{validate:{required:true}}" value='$!format.formatDate($!patient.registrationDate)'/>
@@ -27,12 +27,12 @@
 		<th colspan="2" class="heading-column">$i18n.getString( "demographics" )</th>
 	</tr>
 
-	<tr>
+	<tr name='propertiesField'>
 		<td class='text-column'><label for="fullName">$i18n.getString( "full_name" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
 		<td class="input-column"><input type="text" id="fullName" name="fullName" value="$!patient.getFullName()" class="{validate:{required:true, rangelength:[3,50]}}"></td>
 	</tr>
 
-	<tr>
+	<tr name='propertiesField'>
 		<td class='text-column'><label for="gender">$i18n.getString( "gender" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
 		<td class="input-column">
 			<select id="gender" name="gender">
@@ -43,7 +43,7 @@
 		</td>					
 	</tr>
 
-	<tr>
+	<tr name='propertiesField'>
 		<td class='text-column' ><label for="birthDate">$i18n.getString( "date_of_birth" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td class="input-column">
 			<select id='dobType' name="dobType" style='width:120px' onchange='dobTypeOnChange("patientForm")' >
@@ -63,7 +63,7 @@
 		</td>
 	</tr>
 
-	<tr class='phoneNumberTR'>
+	<tr class='phoneNumberTR' name='propertiesField'>
 		<td class='text-column'><label for="phoneNumber">$i18n.getString( "phone_number" )</label></td>
 		<td class="input-column">
 			<input type="text" id="phoneNumber" name="phoneNumber" class="{validate:{phone:true}}"/>
@@ -71,7 +71,7 @@
 		</td>
 	</tr>
 
-	<tr>
+	<tr name='propertiesField'>
 		<td class='text-column'><label for="healthWorker">$i18n.getString( "health_worker" )</label></td>
 		<td class="input-column">
 			<select id="healthWorkerId" name="healthWorkerId">
@@ -87,7 +87,7 @@
 
 	#if($!patient.underAge)
 		#set( $representative = $!patient.representative ) 
-		<tr id="representativeFormDiv" name="representativeFormDiv">
+		<tr id="representativeFormDiv" name='propertiesField'>
 			<td class='text-column'>$i18n.getString("guardian")</td>
 			<td> 
 				$!patient.representative.getFullName() <img src="../images/information.png" alt="$i18n.getString( 'show_details' )" onclick='showRepresentativeInfo()' class='img-button'>
@@ -104,14 +104,14 @@
 
 	<!-- DEAD -->
 
-	<tr id="deathCheckboxTR">
+	<tr id="deathCheckboxTR" name='propertiesField'>
 		<td class='text-column'>$i18n.getString("is_dead")</td>
 		<td>
 			<input type="checkbox" name="isDead" id="isDead" value="true" #if($!patient.isDead) checked="checked" #end onchange='isDeathOnChange();'/>
 		</td>
 	</tr>
 
-	<tr id='deathDateTR' #if($!patient.isDead) #else class="hidden" #end>
+	<tr id='deathDateTR' #if($!patient.isDead) #else class="hidden" #end name='propertiesField'>
 		<td class='text-column'><label for="deathDate">$i18n.getString("death_date")</label></td>
 		<td class="input-column">
 			<input type="text" name="deathDate" id="deathDate" #if($!patient.deathDate) value="$format.formatDate( $!patient.deathDate )" #end>
@@ -137,7 +137,7 @@
 				#set( $identifier = $!orgunitCountIdentifier )
 			#end
 		
-			<tr> 
+			<tr name='idenFields'> 
 				<td class='text-column'><label>$encoder.htmlEncode($identifierType.displayName) #if($identifierType.mandatory) <em title="$i18n.getString( "required" )" class="required">*</em> #end</label></td>
 				<td class="input-column">
 					<input type="text" id="iden$identifierType.id" name="iden$identifierType.id" value="$!identifier" data="{related:$identifierType.related}" #if($identifierType.related && $!patient.underAge) disabled="disabled" #end 
@@ -152,16 +152,14 @@
 	<!-- ATTRIBUTES IN GROUPS -->
 	
 	#foreach ($attributeGroup in $attributeGroups )
-		#set($attributes = $attributeGroupsMap.get($attributeGroup.id))
-		#if($!attributes || $attributes.size() > 0)
-			<tr><td>&nbsp;</td></tr>
-			<tr><th colspan="2" class="heading-column">$attributeGroup.displayName</th></tr>
-		#end
+		#set($attributes = $attributesMap.get($attributeGroup.displayName))
+		<tr><td>&nbsp;</td></tr>
+		<tr><th colspan="2" class="heading-column">$attributeGroup.displayName</th></tr>
 		#foreach($attribute in $attributes )
 			#if( $attribute )
 				#set($value = "")
 				#set($value = $patientAttributeValueMap.get($attribute.id))
-				<tr>
+				<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="input-column">
 						#if( $attribute.valueType == "bool" )
@@ -196,18 +194,14 @@
 	<tr><td>&nbsp;</td></tr>
 
 	<!-- ATTRIBUTES NOT IN GROUPS -->
-
-	#if ( $noGroupAttributes && $noGroupAttributes.size() > 0) 
-		#if($!noGroupAttributes || $noGroupAttributes.size() > 0)
+	#set($attributes = $attributesMap.get(""))
+	#if ($!attributes) 
 		<tr><th colspan="2" class="heading-column">$i18n.getString( "other_details" )</th></tr>
-		#end
-		#foreach($attribute in $noGroupAttributes )
-		#if( $!attribute && $attribute.program )
-		#elseif( $!attribute )
+		#foreach($attribute in $attributes )
 			#set( $attributeValue = "" )
 			#set( $attributeValue = $!patientAttributeValueMap.get( $attribute.id ) )
 			#if( $attribute.valueType != 'calculated')
-			<tr>
+			<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="input-column">
 					#if( $attribute.valueType == "bool" )
@@ -236,7 +230,6 @@
 				</td>		
 			</tr>
 			#end
-			#end
 		#end
 	#end
 	
@@ -270,6 +263,33 @@
 #end
 
 <script>
+	var disableButtons = true;
+	
+	#if( $auth.hasAccess( "dhis-web-caseentry", "allowEditPatientFixedAttributes" ) )
+		disableButtons = false;
+	#else
+		jQuery('#patientForm [name=propertiesField] input').attr('disabled',true);
+		jQuery('#patientForm [name=propertiesField] select').attr('disabled',true);
+	#end
+	
+	#if( $auth.hasAccess( "dhis-web-caseentry", "allowEditPatientAttributes" ) )
+		disableButtons = false;
+	#else
+		jQuery('#patientForm [name=idenFields] input').attr('disabled',true);
+		jQuery('#patientForm [name=idenFields] select').attr('disabled',true);
+	#end
+
+	#if( $auth.hasAccess( "dhis-web-caseentry", "allowEditPatientIdentifier" ) )
+		disableButtons = false;
+	#else
+		jQuery('#patientForm [name=attributesFields] input').attr('disabled',true);
+		jQuery('#patientForm [name=attributesFields] select').attr('disabled',true);
+	#end
+	
+	if(disableButtons){
+		jQuery('#patientForm .button').attr('disabled',true);
+	}
+
 	if(getFieldValue('dobType')=='A'){
 		showById('age');
 		hideById('birthDate');

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2013-09-09 18:36:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2013-09-11 16:02:06 +0000
@@ -140,14 +140,4 @@
 	setFieldValue('endDueDate','');
 	jQuery('#emptyProgramOption').text('[' + '$i18n.getString("view_all")' + ']');
 	
-	$( "#orgUnitTree" ).one( "ouwtLoaded", function () {
-        var def = $.Deferred();
-        var promise = def.promise();
-        promise = promise.then( function () {
-            selection.setListenerFunction( organisationUnitSelected );
-        } );
-
-        def.resolve();
-    } );
-	
 </script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.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/dataentryform/ViewPatientRegistrationFormAction.java	2013-09-11 16:02:06 +0000
@@ -103,7 +103,7 @@
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
-    
+
     private Integer programId;
 
     public void setProgramId( Integer programId )
@@ -113,13 +113,13 @@
 
     private Collection<PatientAttribute> attributes = new HashSet<PatientAttribute>();
 
-    private Collection<PatientIdentifierType> identifierTypes = new HashSet<PatientIdentifierType>();
-
     public Collection<PatientAttribute> getAttributes()
     {
         return attributes;
     }
 
+    private Collection<PatientIdentifierType> identifierTypes = new HashSet<PatientIdentifierType>();
+
     public Collection<PatientIdentifierType> getIdentifierTypes()
     {
         return identifierTypes;
@@ -167,30 +167,23 @@
         if ( programId == null )
         {
             registrationForm = patientRegistrationFormService.getCommonPatientRegistrationForm();
+
+            identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
+            attributes = patientAttributeService.getAllPatientAttributes();
+            for ( Program p : programs )
+            {
+                identifierTypes.remove( p.getPatientIdentifierTypes() );
+                attributes.remove( p.getPatientAttributes() );
+            }
         }
         else
         {
             program = programService.getProgram( programId );
+            identifierTypes = program.getPatientIdentifierTypes();
+            attributes = program.getPatientAttributes();
             registrationForm = patientRegistrationFormService.getPatientRegistrationForm( program );
         }
-
-        // ---------------------------------------------------------------------
-        // Get dynamic attributes and identifier-types
-        // ---------------------------------------------------------------------
-
-        identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
-
-        attributes = patientAttributeService.getAllPatientAttributes();
-
-        for ( Program program : programs )
-        {
-            if ( programId == null || program.getId() != programId )
-            {
-                identifierTypes.removeAll( program.getPatientIdentifierTypes() );
-                attributes.removeAll( program.getPatientAttributes() );
-            }
-        }
-
+        
         // ---------------------------------------------------------------------
         // Get images
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-09-10 04:51:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-09-11 16:02:06 +0000
@@ -302,7 +302,7 @@
     {
         this.relationshipFromA = relationshipFromA;
     }
-
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -334,7 +334,7 @@
         program.setUseBirthDateAsEnrollmentDate( useBirthDateAsEnrollmentDate );
         program.setSelectEnrollmentDatesInFuture( selectEnrollmentDatesInFuture );
         program.setSelectIncidentDatesInFuture( selectIncidentDatesInFuture );
-
+        
         if ( type == Program.MULTIPLE_EVENTS_WITH_REGISTRATION )
         {
             program.setIgnoreOverdueEvents( ignoreOverdueEvents );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java	2013-09-05 17:59:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java	2013-09-11 16:02:06 +0000
@@ -31,6 +31,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
@@ -138,19 +139,20 @@
 
     public String execute()
     {
-        availableIdentifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
-
-        availableAttributes = patientAttributeService.getAllPatientAttributes();
 
         programs = new ArrayList<Program>( programService.getAllPrograms() );
         Collections.sort( programs, IdentifiableObjectNameComparator.INSTANCE );
-
-        for ( Program program : programs )
+       
+      
+        availableAttributes = patientAttributeService.getAllPatientAttributes();
+ 
+        availableIdentifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
+        for ( Program p : programs )
         {
-            availableIdentifierTypes.removeAll( program.getPatientIdentifierTypes() );
-            availableAttributes.removeAll( program.getPatientAttributes() );
+            availableIdentifierTypes
+                .removeAll( new HashSet<PatientIdentifierType>( p.getPatientIdentifierTypes() ) );
         }
-
+        
         userGroups = new ArrayList<UserGroup>( userGroupService.getAllUserGroups() );
         
         relationshipTypes = new ArrayList<RelationshipType>(relationshipTypeService.getAllRelationshipTypes());

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java	2013-09-05 17:59:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java	2013-09-11 16:02:06 +0000
@@ -204,14 +204,14 @@
         availableIdentifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes();
 
         availableAttributes = patientAttributeService.getAllPatientAttributes();
-
+        availableAttributes.removeAll( new HashSet<PatientAttribute>( program.getPatientAttributes() ) );
+        
         programs = new ArrayList<Program>( programService.getAllPrograms() );
 
-        for ( Program program : programs )
+        for ( Program p : programs )
         {
             availableIdentifierTypes
-                .removeAll( new HashSet<PatientIdentifierType>( program.getPatientIdentifierTypes() ) );
-            availableAttributes.removeAll( new HashSet<PatientAttribute>( program.getPatientAttributes() ) );
+                .removeAll( new HashSet<PatientIdentifierType>( p.getPatientIdentifierTypes() ) );
         }
 
         userGroups = new ArrayList<UserGroup>( userGroupService.getAllUserGroups() );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties	2013-09-08 08:36:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties	2013-09-11 16:02:06 +0000
@@ -121,7 +121,10 @@
 F_RELATIONSHIPTYPE_ADD=Add Relationship Type
 F_ORGANISATION_REGISTRATION=Organisation Unit Registration
 F_PATIENT_REMOVE_EMPTY_EVENTS=Remove Empty Person Events
-F_ACCESS_PATIENT_ATTRIBUTES = View and search Person identifiers
+F_ACCESS_PATIENT_ATTRIBUTES = View and Search Person identifiers
+F_ALLOW_EDIT_PATIENT_ATTRIBUTES = Add and Edit Patient Attributes
+F_ALLOW_EDIT_PATIENT_PROPERTIES = Add and Edit Patient Properties
+F_ALLOW_EDIT_PATIENT_IDENTIFIERS = Add and Edit Patient Identifiers
 F_PATIENTATTRIBUTE_ADD=Add/Update Person Attribute
 F_PATIENTATTRIBUTE_DELETE=Delete Person Attribute
 F_PATIENTATTRIBUTEVALUE_ADD=Add Person Attribute Value