← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16316: Save codes of option in optionset instead of saving names of options in case entry form.

 

------------------------------------------------------------
revno: 16316
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-08-05 12:57:06 +0700
message:
  Save codes of option in optionset instead of saving names of options in case entry form.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java	2014-07-29 17:14:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java	2014-08-05 05:57:06 +0000
@@ -37,6 +37,8 @@
 
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.option.Option;
+import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -54,6 +56,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -110,6 +113,9 @@
         this.organisationUnitService = organisationUnitService;
     }
 
+    @Autowired
+    private OptionService optionService;
+
     // -------------------------------------------------------------------------
     // Input && Output
     // -------------------------------------------------------------------------
@@ -257,7 +263,7 @@
     {
         return displayOptionSetAsRadioButton;
     }
-
+    
     // -------------------------------------------------------------------------
     // Implementation Action
     // -------------------------------------------------------------------------
@@ -310,7 +316,7 @@
             // ---------------------------------------------------------------------
             // Get program indicators
             // ---------------------------------------------------------------------
-            
+
             programIndicatorsMap.putAll( programIndicatorService.getProgramIndicatorValues( programStageInstance
                 .getProgramInstance() ) );
 
@@ -364,7 +370,19 @@
         for ( TrackedEntityDataValue entityInstanceDataValue : entityInstanceDataValues )
         {
             int key = entityInstanceDataValue.getDataElement().getId();
-            entityInstanceDataValueMap.put( key, entityInstanceDataValue );
+            if ( entityInstanceDataValue.getDataElement().getOptionSet() != null )
+            {
+                String value = entityInstanceDataValue.getValue();
+                Option option = optionService.getOptionByCode( value );
+                
+                TrackedEntityDataValue instanceDataValue = new TrackedEntityDataValue(entityInstanceDataValue.getProgramStageInstance(), entityInstanceDataValue.getDataElement());
+                instanceDataValue.setValue( option.getName() );
+                entityInstanceDataValueMap.put( key, instanceDataValue );
+            }
+            else
+            {
+                entityInstanceDataValueMap.put( key, entityInstanceDataValue );
+            }
         }
 
         return entityInstanceDataValues;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm	2014-08-04 15:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm	2014-08-05 05:57:06 +0000
@@ -27,9 +27,9 @@
 #foreach( $programStageDataElement in $programStageDataElements )
 	#set( $dataElementRowCount = $dataElementRowCount + 1 )    
 	#set( $mark = !$mark )
-	#set( $dataValue = false )
 	#set( $key = $programStageDataElement.dataElement.id )
-	#set( $dataValue = $dataValueMap.get( $key ) )    
+	#set( $dataValue = '')
+	#set( $dataValue = $entityInstanceDataValueMap.get( $key ) )    
 	<tr #alternate( $mark )>
 		##data element name
 		<td class='text-column' align='center'>
@@ -51,7 +51,7 @@
 				#set( $hasOptionSet = 'false')
 			#end
 			#if( $programStageDataElement.dataElement.textType == "longText" )
-				<textarea name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory }" id="$id" name="entryfield" onchange="saveVal( '$programStageDataElement.dataElement.uid' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" maxlength=255 >$!encoder.htmlEncode( $dataValue.value )</textarea>
+				<textarea name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory }" id="$id" name="entryfield" onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" maxlength=255 >$!encoder.htmlEncode( $dataValue.value )</textarea>
 			#elseif( $programStageDataElement.dataElement.type == "bool" )
 				<select name="entryfield" data="{compulsory: $programStageDataElement.compulsory }" id="$id" onchange="saveOpt( '$programStageDataElement.dataElement.uid' )" tabindex="$tabIndex">
 					<option value="">[$i18n.getString( "select_value" )]</option>
@@ -59,9 +59,9 @@
 					<option value="false" #if( $dataValue.value == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
 				</select>
 			#elseif( $programStageDataElement.dataElement.type == "trueOnly" )
-				<input name="entryfield" type="checkbox" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()'}" id="$id" name="entryfield" #if($dataValue.value=="true") checked #end onchange="saveVal( '$programStageDataElement.dataElement.uid' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
+				<input name="entryfield" type="checkbox" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()'}" id="$id" name="entryfield" #if($dataValue.value=="true") checked #end onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
 			#elseif( $programStageDataElement.dataElement.type == "date" )
-				<input name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()' }" id="$id" name="entryfield" value="$!encoder.htmlEncode( $dataValue.value )" onchange="saveVal( '$programStageDataElement.dataElement.uid' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" class="date-field datefield" />
+				<input name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()' }" id="$id" name="entryfield" value="$!encoder.htmlEncode( $dataValue.value )" onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" class="date-field datefield" />
 				<script type="text/javascript">
 					#if($programStageDataElement.allowFutureDate=='true')
 						datePicker( '$programStageDataElement.programStage.uid'+ '-' + '$programStageDataElement.dataElement.uid' + '-val', false, false);
@@ -76,7 +76,7 @@
 							<td>
 							<input id='$id' class='$id' name="$id" type='radio' options='no' optionset='$programStageDataElement.dataElement.optionSet.uid'
 								data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }"
-								#if( $dataValue.value == "$option.code") checked #end
+								#if( $dataValue.value == "$option.name") checked #end
 								onclick="saveRadio( '$programStageDataElement.dataElement.uid', '' )" tabindex="$tabIndex" />$i18n.getString("non_value")
 						</td>
 					#set($index=1)
@@ -88,7 +88,7 @@
 						<td>
 						<input id='$id' class='$id' name="$id" type='radio' options='no' optionset='$programStageDataElement.dataElement.optionSet.uid'
 							data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" 
-						#if( $dataValue.value == "$option.code") checked #end value="$encoder.htmlEncode($option.name)"
+						#if( $dataValue.value == "$option.name") checked #end value="$encoder.htmlEncode($option.name)"
 						onclick="saveRadio( '$programStageDataElement.dataElement.uid', '$option.code' )" tabindex="$tabIndex" />$encoder.htmlEncode($option.name)
 						</td>
 						#set($index=$index + 1)
@@ -103,7 +103,7 @@
 				<input name="entryfield"  
 					data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" onkeypress="return keyPress(event, this)" tabindex="$tabIndex"
 					id="$id" type="text" value="$!encoder.htmlEncode( $dataValue.value )" 
-					onchange="saveVal( '$programStageDataElement.dataElement.uid' )" 
+					onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" 
 					onkeypress="return keyPress(event, this)" tabindex="$tabIndex"/>
 			#end
 		</td> 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2014-08-04 15:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2014-08-05 05:57:06 +0000
@@ -5,7 +5,7 @@
 // Save value
 //------------------------------------------------------------------------------
 
-function saveVal( dataElementUid )
+function saveVal( dataElementUid, fieldValue )
 {
     var programStageUid = getProgramStageUid();
     var fieldId = programStageUid + '-' + dataElementUid + '-val';
@@ -13,7 +13,6 @@
 
     if( field == null) return;
 
-    var fieldValue = jQuery.trim( field.value );
     var arrData = jQuery( "#" + fieldId ).attr( 'data' ).replace( '{', '' ).replace( '}', '' ).replace( /'/g, "" ).split( ',' );
     var data = [];
 
@@ -257,7 +256,7 @@
 			params += byId( providedElsewhereId ).checked;
 		
 		params += '&value=';
-
+		
         if ( value != '' )
             params += htmlEncode( value );
 
@@ -1059,6 +1058,10 @@
 		minLength: 0,
 		select: function( event, ui ) {
 			var fieldValue = ui.item.value;
+			var fieldCode = "";
+			if(ui.item.id!=null){
+				fieldCode = ui.item.id; 
+			}
 
 			if ( !dhis2.trigger.invoke( "caseentry-value-selected", [dataElementUid, fieldValue] ) ) {
 				input.val( "" );
@@ -1067,7 +1070,7 @@
 
 			input.val( fieldValue );
 			if ( !unSave ) {
-				saveVal( dataElementUid );
+				saveVal( dataElementUid, fieldCode );
 			}
 			input.autocomplete( "close" );
 		},
@@ -1077,8 +1080,10 @@
 					valid = false;
 				if ( !valid ) {
 					$( this ).val( "" );
-					if(!unSave)
-						saveVal( dataElementUid );
+					if(!unSave){
+						var fieldCode = ui.item.id;
+						saveVal( dataElementUid, fieldCode );
+					}
 					input.data( "uiAutocomplete" ).term = "";
 					return false;
 				}
@@ -1194,7 +1199,7 @@
 			
 			input.val( fieldValue );			
 			if ( !unSave ) {
-				saveVal( dataElementUid );
+				saveVal( dataElementUid, fieldValue );
 			}
 			input.autocomplete( "close" );
 		},
@@ -1205,7 +1210,7 @@
 				if ( !valid ) {
 					$( this ).val( "" );
 					if(!unSave)
-						saveVal( dataElementUid );
+						saveVal( dataElementUid, fieldValue );
 					input.data( "uiAutocomplete" ).term = "";
 					return false;
 				}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm	2014-08-04 15:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm	2014-08-05 05:57:06 +0000
@@ -62,7 +62,7 @@
 									#set( $hasOptionSet = 'false')
 								#end
 								#if( $programStageDataElement.dataElement.textType == "longText" )
-									<textarea name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory }" id="$id" name="entryfield" onchange="saveVal( '$programStageDataElement.dataElement.uid' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" maxlength=255 >$!encoder.htmlEncode( $dataValue.value )</textarea>
+									<textarea name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory }" id="$id" name="entryfield" onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" maxlength=255 >$!encoder.htmlEncode( $dataValue.value )</textarea>
 								#elseif( $programStageDataElement.dataElement.type == "bool" )
 									<select name="entryfield" data="{compulsory: $programStageDataElement.compulsory }" id="$id" onchange="saveOpt( '$programStageDataElement.dataElement.uid' )" tabindex="$tabIndex">
 										<option value="">[$i18n.getString( "select_value" )]</option>
@@ -70,9 +70,9 @@
 										<option value="false" #if( $dataValue.value == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
 									</select>
 								#elseif( $programStageDataElement.dataElement.type == "trueOnly" )
-									<input name="entryfield" type="checkbox" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()'}" id="$id" name="entryfield" #if($dataValue.value=="true") checked #end onchange="saveVal( '$programStageDataElement.dataElement.uid' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
+									<input name="entryfield" type="checkbox" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()'}" id="$id" name="entryfield" #if($dataValue.value=="true") checked #end onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
 								#elseif( $programStageDataElement.dataElement.type == "date" )
-									<input name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()'}" id="$id" name="entryfield" value="$!encoder.htmlEncode( $dataValue.value )" onchange="saveVal( '$programStageDataElement.dataElement.uid' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" class="date-field datefield" >
+									<input name="entryfield" type="text" data="{compulsory: $programStageDataElement.compulsory, deType:'$programStageDataElement.dataElement.getType()'}" id="$id" name="entryfield" value="$!encoder.htmlEncode( $dataValue.value )" onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" class="date-field datefield" >
 									<script type="text/javascript">
 										#if($programStageDataElement.allowFutureDate=='true')
 											datePicker( '$programStageDataElement.programStage.uid'+ '-' + '$programStageDataElement.dataElement.uid' + '-val', false, false);
@@ -88,7 +88,7 @@
 												<td>
 													<input id='$id' name="$id" type='radio' options='no' optionset="$programStageDataElement.dataElement.optionSet.uid"
 														data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" 
-														#if( $dataValue.value == "$option.code") checked #end
+														#if( $dataValue.value == "$option.name") checked #end
 														onclick="saveRadio( '$programStageDataElement.dataElement.uid', '$option.code' )" tabindex="$tabIndex" />$i18n.getString("non_value")
 											</td>
 										#set($index=1)
@@ -100,7 +100,7 @@
 											<td>
 											<input id='$id' name="$id" type='radio' options='no'
 											data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" 
-											#if( $dataValue.value == "$option.code") checked #end
+											#if( $dataValue.value == "$option.name") checked #end
 											onclick="saveRadio( '$programStageDataElement.dataElement.uid', '$option.code' )" tabindex="$tabIndex" />$encoder.htmlEncode($option.name)
 											</td>
 											#set($index=$index + 1)
@@ -116,7 +116,7 @@
 									<input name="entryfield" 
 										data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" onkeypress="return keyPress(event, this)" tabindex="$tabIndex"
 										id="$id" type="text" value="$!encoder.htmlEncode( $dataValue.value )" 
-										onchange="saveVal( '$programStageDataElement.dataElement.uid' )" 
+										onchange="saveVal( '$programStageDataElement.dataElement.uid', this.value )" 
 										onkeypress="return keyPress(event, this)" tabindex="$tabIndex"/>
 								#end
 							</td>