← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11301: Allow to set default values for fixed attributes and hidden them when to define custom registrati...

 

------------------------------------------------------------
revno: 11301
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-07-02 09:25:30 +0700
message:
  Allow to set default values for fixed attributes and hidden them when to define custom registration form.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationFormService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.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/PatientRegistrationFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationFormService.java	2013-02-02 10:34:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationFormService.java	2013-07-02 02:25:30 +0000
@@ -58,6 +58,10 @@
 
     final Pattern TITLE_TAG_PATTERN = Pattern.compile( "title=\"(.*?)\"", Pattern.DOTALL );
 
+    final Pattern SUGGESTED_VALUE_PATTERN = Pattern.compile( "suggested='(\\w*)'" );
+    
+    final Pattern CLASS_PATTERN = Pattern.compile( "class='(\\w*)'" );
+
     // --------------------------------------------------------------------------
     // ProgramDataEntryService
     // --------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java	2013-06-20 09:05:11 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientRegistrationFormService.java	2013-07-02 02:25:30 +0000
@@ -148,7 +148,7 @@
         StringBuffer sb = new StringBuffer();
 
         Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode );
-
+        
         while ( inputMatcher.find() )
         {
             // -----------------------------------------------------------------
@@ -160,6 +160,9 @@
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
             Matcher dynamicAttrMatcher = DYNAMIC_ATTRIBUTE_PATTERN.matcher( inputHtml );
             Matcher programMatcher = PROGRAM_PATTERN.matcher( inputHtml );
+            Matcher suggestedMarcher = SUGGESTED_VALUE_PATTERN.matcher( inputHtml );
+            Matcher classMarcher = CLASS_PATTERN.matcher( inputHtml );
+            
             index++;
 
             if ( fixedAttrMatcher.find() && fixedAttrMatcher.groupCount() > 0 )
@@ -168,6 +171,7 @@
 
                 // Get value
                 String value = "";
+                String hidden = "";
                 if ( patient != null )
                 {
                     Object object = getValueFromPatient( StringUtils.capitalize( fixedAttr ), patient );
@@ -187,8 +191,17 @@
                         }
                     }
                 }
-
-                inputHtml = getFixedAttributeField( inputHtml, fixedAttr, value.toString(), healthWorkers, i18n, index );
+                else if( suggestedMarcher.find())
+                {
+                    value = suggestedMarcher.group( 1 );
+                }
+                
+                if( classMarcher.find() )
+                {
+                    hidden = classMarcher.group( 1 );
+                }
+                
+                inputHtml = getFixedAttributeField( inputHtml, fixedAttr, value.toString(), hidden, healthWorkers, i18n, index );
             }
             else if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
@@ -365,7 +378,7 @@
         return inputHtml;
     }
 
-    private String getFixedAttributeField( String inputHtml, String fixedAttr, String value,
+    private String getFixedAttributeField( String inputHtml, String fixedAttr, String value, String hidden,
         Collection<User> healthWorkers, I18n i18n, int index )
     {
         inputHtml = TAG_OPEN + "input id=\"" + fixedAttr + "\" name=\"" + fixedAttr + "\" tabindex=\"" + index
@@ -374,19 +387,19 @@
         // Fullname fields
         if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_FULLNAME ) )
         {
-            inputHtml += " class=\"{validate:{required:true, rangelength:[3,50]}}\" " + TAG_CLOSE;
+            inputHtml += " class=\"{validate:{required:true, rangelength:[3,50]}}\" " + hidden + " " + TAG_CLOSE;
         }
 
         // Phone number fields
         else if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_PHONE_NUMBER ) )
         {
-            inputHtml += " class=\"{validate:{phone:true}}\" " + TAG_CLOSE;
+            inputHtml += " class=\"{validate:{phone:true}}\" " + hidden + " " + TAG_CLOSE;
         }
 
         // Gender selector
         if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_GENDER ) )
         {
-            inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">";
+            inputHtml = inputHtml.replaceFirst( "input", "select" ) + " class='" + hidden + "' >";
 
             if ( value.equals( "" ) || value.equals( Patient.FEMALE ) )
             {
@@ -414,7 +427,7 @@
             || fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_DEATH_DATE )
             || fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_REGISTRATION_DATE ) )
         {
-            inputHtml += TAG_CLOSE;
+            inputHtml += " class='" + hidden + "' "+ TAG_CLOSE;
             if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_BIRTHDATE )
                 || fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_REGISTRATION_DATE ) )
             {
@@ -429,7 +442,7 @@
         // DobType field
         else if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_DOB_TYPE ) )
         {
-            inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">";
+            inputHtml = inputHtml.replaceFirst( "input", "select" ) + " class='" + hidden + "' >" ;
 
             if ( value.equals( "" ) || value.equals( Patient.DOB_TYPE_VERIFIED + "" ) )
             {
@@ -456,7 +469,7 @@
         // Health-worker field
         else if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_HEALTH_WORKER ) )
         {
-            inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">";
+            inputHtml = inputHtml.replaceFirst( "input", "select" ) + " class='" + hidden + "' >";
             inputHtml += "<option value=\"\" selected >" + i18n.getString( "please_select" ) + "</option>";
 
             for ( User healthWorker : healthWorkers )
@@ -474,7 +487,7 @@
         // IsDead field
         else if ( fixedAttr.equals( PatientRegistrationForm.FIXED_ATTRIBUTE_IS_DEAD ) )
         {
-            inputHtml += " type='checkbox' ";
+            inputHtml += " type='checkbox' class='" + hidden + "' ";
 
             if ( value.equals( "true" ) )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-05-21 04:18:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-07-02 02:25:30 +0000
@@ -291,8 +291,7 @@
 	
 	if( type == 'fixedAttr' ){
 		var element = jQuery('#fixedAttrSelector option:selected');
-		if( element.length == 0 ) return;
-		
+		if( element.length == 0 ) return;		
 		id = 'fixedattributeid="' + element.attr('value') + '"';
 		value = element.text();
 	}
@@ -318,7 +317,30 @@
 		value = element.text();
 	}
 	
-	var htmlCode = "<input " + id + " value=\"[" + value + "]\" title=\"" + value + "\">";
+	var htmlCode = "<input " + id + " value=\"[" + value + "]\" title=\"" + value + "\" ";
+	
+	var suggestedValue = getFieldValue('genderSelector');
+	if( jQuery('#genderSelector').is(":visible") )
+	{
+		htmlCode += " suggested='" + suggestedValue + "' ";
+	}
+	suggestedValue = getFieldValue('dobTypeSelector');
+	if( jQuery('#dobTypeSelector').is(":visible") )
+	{
+		htmlCode += " suggested='" + suggestedValue + "' ";
+	}
+	suggestedValue = getFieldValue('suggestedField');
+	if( jQuery('#suggestedField').is(":visible") )
+	{
+		htmlCode += " suggested='" + suggestedValue + "' ";
+	}
+	
+	var isHidden = jQuery('#hiddenField').attr('checked');
+	if(isHidden)
+	{
+		htmlCode += " class='hidden' ";
+	}
+	htmlCode += " >";
 	
 	if( checkExisted( id ) ){		
 		setMessage( "<span class='bold'>" + i18n_property_is_inserted + "</span>" );
@@ -435,3 +457,19 @@
 		window.location.href = 'delRegistrationEntryFormAction.action?id=' + getFieldValue('id');
 	}
 }
+
+function suggestionSelectorToggle()
+{
+	hideById('genderSelector');
+	hideById('dobTypeSelector');
+	showById('suggestedField');
+	if( getFieldValue('fixedAttrSelector')=='gender' ){
+		hideById('suggestedField');
+		showById('genderSelector');
+	}
+	else if(getFieldValue('fixedAttrSelector')=='dobType'){
+		hideById('suggestedField');
+		showById('dobTypeSelector');
+	}
+}
+

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-06-21 13:11:06 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-07-02 02:25:30 +0000
@@ -125,7 +125,7 @@
 		</tr>
 		<tr>
 			<td>
-				<select id="fixedAttrSelector" multiple="multiple" style="width:450px;height:270px" ondblclick="insertElement( 'fixedAttr' )">
+				<select id="fixedAttrSelector" multiple="multiple" style="width:450px;height:270px" onclick='suggestionSelectorToggle()' ondblclick="insertElement( 'fixedAttr' )">
 					<option value="registrationDate">$i18n.getString('registration_date') #if($disableRegistrationFields=='false')*#end</option>
 					<option value="fullName">$i18n.getString('full_name') #if($disableRegistrationFields=='false')*#end</option>
 					<option value="gender">$i18n.getString('gender') #if($disableRegistrationFields=='false')*#end</option>
@@ -138,6 +138,24 @@
 				</select>
 			</td>
 		</tr>
+		<tr>
+			<td>
+				<input type='text' id='suggestedField' style='width:350px;'>
+				<select style='width:350px;display:none;' id='genderSelector'>
+					<option value="">[$i18n.getString( "please_select" )]</option>
+					<option value="M">$i18n.getString( "male" )</option>
+					<option value="F">$i18n.getString( "female" )</option>
+					<option value="T">$i18n.getString( "transgender" )</option>
+				</select>
+				<select style='width:350px;display:none;' id='dobTypeSelector'>
+					<option value="">[$i18n.getString( "please_select" )]</option>
+					<option value="V">$i18n.getString( "verified" )</option>
+					<option value="D">$i18n.getString( "declared" )</option>
+					<option value="A">$i18n.getString( "approximated" )</option>
+				</select>
+				<input type='checkbox' id='hiddenField'/>$i18n.getString("is_hidden")
+			</td>
+		</tr>
 	</table>
 	
 	<table id="identifierTypeTab" class='hidden'>