← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7306: Load optionset values by ajax.

 

------------------------------------------------------------
revno: 7306
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-06-15 11:41:31 +0700
message:
  Load optionset values by ajax.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.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/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js


--
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/option/OptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2012-02-06 02:56:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2012-06-15 04:41:31 +0000
@@ -28,6 +28,7 @@
  */
 
 import java.util.Collection;
+import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -49,4 +50,6 @@
     void deleteOptionSet( OptionSet optionSet );
 
     Collection<OptionSet> getAllOptionSets();
+    
+    List<String> getOptions( OptionSet optionSet, String key  );
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java	2012-06-15 04:41:31 +0000
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004-2012, 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.option;
+
+import java.util.List;
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $OptionStore.java Jun 15, 2012 9:45:00 AM$
+ */
+public interface OptionStore extends GenericIdentifiableObjectStore<OptionSet>
+{
+    List<String> getOptions( OptionSet optionSet, String key  );
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2012-02-06 02:56:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2012-06-15 04:41:31 +0000
@@ -28,8 +28,8 @@
  */
 
 import java.util.Collection;
+import java.util.List;
 
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -39,45 +39,50 @@
 public class DefaultOptionService
     implements OptionService
 {
-    private GenericIdentifiableObjectStore<OptionSet> optionSetStore;
+    private OptionStore optionStore;
 
-    public void setOptionSetStore( GenericIdentifiableObjectStore<OptionSet> optionSetStore )
+    public void setOptionStore( OptionStore optionStore )
     {
-        this.optionSetStore = optionSetStore;
+        this.optionStore = optionStore;
     }
 
     public int saveOptionSet( OptionSet optionSet )
     {
-        return optionSetStore.save( optionSet );
+        return optionStore.save( optionSet );
     }
 
     public void updateOptionSet( OptionSet optionSet )
     {
-        optionSetStore.update( optionSet );
+        optionStore.update( optionSet );
     }
     
     public OptionSet getOptionSet( int id )
     {
-        return optionSetStore.get( id );
+        return optionStore.get( id );
     }
 
     public OptionSet getOptionSet( String uid )
     {
-        return optionSetStore.getByUid( uid );
+        return optionStore.getByUid( uid );
     }
     
     public OptionSet getOptionSetByName( String name )
     {
-        return optionSetStore.getByName( name );
+        return optionStore.getByName( name );
     }
 
     public void deleteOptionSet( OptionSet optionSet )
     {
-        optionSetStore.delete( optionSet );
+        optionStore.delete( optionSet );
     }
 
     public Collection<OptionSet> getAllOptionSets()
     {
-        return optionSetStore.getAll();
+        return optionStore.getAll();
+    }
+    
+    public List<String> getOptions( OptionSet optionSet, String key  )
+    {
+        return optionStore.getOptions( optionSet, key );
     }
 }

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java	2012-06-15 04:41:31 +0000
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2004-2012, 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.option;
+
+import java.util.List;
+
+import org.hibernate.Query;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $HibernateOptionStore.java Jun 15, 2012 9:45:48 AM$
+ */
+public class HibernateOptionStore
+    extends HibernateIdentifiableObjectStore<OptionSet>
+    implements OptionStore
+{
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public List<String> getOptions( OptionSet optionSet, String key )
+    {
+        String hql = "select option from OptionSet as optionset inner join optionset.options as option where optionset.id = :optionSetId and lower(option) like lower('%" + key + "%') ";
+
+        Query query = getQuery( hql );
+        query.setInteger( "optionSetId", optionSet.getId() );
+        
+        return query.list();
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-06-13 08:44:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-06-15 04:41:31 +0000
@@ -275,10 +275,9 @@
     <property name="cacheable" value="true" />
   </bean>
 
-  <bean id="org.hisp.dhis.option.OptionSetStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+  <bean id="org.hisp.dhis.option.OptionStore" class="org.hisp.dhis.option.HibernateOptionStore">
     <property name="clazz" value="org.hisp.dhis.option.OptionSet" />
     <property name="sessionFactory" ref="sessionFactory" />
-    <property name="cacheable" value="true" />
   </bean>
 
   <!-- Service definitions -->
@@ -506,7 +505,7 @@
   </bean>
   
   <bean id="org.hisp.dhis.option.OptionService" class="org.hisp.dhis.option.DefaultOptionService">
-	<property name="optionSetStore" ref="org.hisp.dhis.option.OptionSetStore"/>
+	<property name="optionStore" ref="org.hisp.dhis.option.OptionStore"/>
   </bean>
 
   <bean id="org.hisp.dhis.setting.SystemSettingManager" class="org.hisp.dhis.setting.DefaultSystemSettingManager">

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-06-04 10:03:56 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-06-15 04:41:31 +0000
@@ -555,8 +555,7 @@
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
-        final String jsCodeForOptions = " $DISABLED options='$OPTIONS' dataElementId=\"$DATAELEMENTID\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
+        final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" options='$OPTIONS' style=\" text-align:center;\"  ";
 
         StringBuffer sb = new StringBuffer();
 
@@ -700,16 +699,10 @@
                     appendCode += "value=\"" + dataElementValue + "\"";
                 }
 
-                if ( dataElement.getOptionSet() != null )
-                {
-                    appendCode += jsCodeForOptions;
-
-                    appendCode = appendCode.replace( "$OPTIONS", dataElement.getOptionSet().getOptions().toString() );
-                }
-                else
-                {
-                    appendCode += jsCodeForInputs;
-                }
+                appendCode += jsCodeForInputs;
+                
+                Boolean hasOptionSet = ( dataElement.getOptionSet() != null );
+                appendCode = appendCode.replace( "$OPTIONS", hasOptionSet.toString() );
 
                 appendCode += " />";
 

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java	2012-06-15 04:41:31 +0000
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2004-2012, 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.caseentry.action.caseentry;
+
+import java.util.List;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.option.OptionService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $GetOptionsByDataElementAction.java Jun 15, 2012 10:36:29 AM$
+ */
+public class GetOptionsByDataElementAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DataElementService dataElementService;
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    private OptionService optionService;
+
+    public void setOptionService( OptionService optionService )
+    {
+        this.optionService = optionService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private String key;
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private List<String> options;
+
+    public List<String> getOptions()
+    {
+        return options;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        DataElement dataElement = dataElementService.getDataElement( id );
+
+        options = optionService.getOptions( dataElement.getOptionSet(), key );
+
+        return SUCCESS;
+    }
+}

=== 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	2012-06-14 13:07:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-06-15 04:41:31 +0000
@@ -136,6 +136,16 @@
 		<property name="selectedStateManager"
 			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 	</bean>
+	
+	<bean
+		id="org.hisp.dhis.caseentry.action.caseentry.GetOptionsByDataElementAction"
+		class="org.hisp.dhis.caseentry.action.caseentry.GetOptionsByDataElementAction"
+		scope="prototype">
+		<property name="dataElementService"
+			ref="org.hisp.dhis.dataelement.DataElementService" />
+		<property name="optionService"
+			ref="org.hisp.dhis.option.OptionService" />
+	</bean>
 
 	<!-- Multi DataEntry -->
 

=== 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	2012-06-07 13:09:16 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2012-06-15 04:41:31 +0000
@@ -148,6 +148,10 @@
 			<param name="page">/dhis-web-caseentry/validationResult.vm</param>
 		</action>
 		
+		<action name="getOptions" class="org.hisp.dhis.caseentry.action.caseentry.GetOptionsByDataElementAction">
+	      <result name="success" type="velocity-json">/dhis-web-caseentry/jsonOptions.vm</result>
+	    </action>
+		
 		<!-- save value -->
 
 		<action name="saveValue"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-06-14 06:23:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-06-15 04:41:31 +0000
@@ -70,9 +70,12 @@
 				<td class='input-column'>   
 					#set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val' )
 					#if( $!programStageDataElement.dataElement.optionSet )
-						#set( $optionId = $id + '-options')
-						<input style='width: 250px;' type='text' class='optionset' name="entryselect" options='$programStageDataElement.dataElement.optionSet.options' id='$id' value='$!patientDataValue.value' data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" id="$id-options" dataElementId="$programStageDataElement.dataElement.id" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" />
-					#elseif( $programStageDataElement.dataElement.type == "bool" )
+						#set( $hasOptionSet = 'true')
+					#else
+						#set( $hasOptionSet = 'true')
+					#end
+
+					#if( $programStageDataElement.dataElement.type == "bool" )
 						<select style='width: 256px;' name="entryselect" data="{compulsory: $programStageDataElement.compulsory }" id="$id" onchange="saveOpt( $programStageDataElement.dataElement.id )" tabindex="$tabIndex">
 							<option value="">[$i18n.getString( "select_value" )]</option>
 							<option value="true" #if( $patientDataValue.value == "true" ) selected="selected" #end>$i18n.getString( "yes" )</option>
@@ -84,7 +87,7 @@
 							datePicker($programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val', false);
 						</script> 
 					#else
-						<input name="entryfield" data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" id="$id" type="text" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveVal( $programStageDataElement.dataElement.id )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex">
+						<input name="entryfield" options='$hasOptionSet' #if($hasOptionSet == 'true') class='optionset' #end dataElementId='$programStageDataElement.dataElement.id' data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" id="$id" type="text" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveVal( $programStageDataElement.dataElement.id )" 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	2012-06-13 08:22:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-06-15 04:41:31 +0000
@@ -824,71 +824,30 @@
 {
 	var input = jQuery( "#" +  idField )
 	var dataElementId = input.attr( 'dataElementId' );
-	var options = new Array();
-	options = input.attr('options').replace('[', '').replace(']', '').split(', ');
-	options.push(" ");
-
+	
 	input.autocomplete({
 			delay: 0,
 			minLength: 0,
-			source: options,
+			source: function( request, response ){
+                $.ajax({
+                    url: "getOptions.action?id=" + dataElementId + "&key=" + input.val(),
+                    dataType: "json",
+                    success: function(data) {
+						response($.map(data.options, function(item) {
+							return {
+								label: item,
+								id: item
+							};
+                        }));
+                    }
+                });
+            },
+			minLength: 2,
 			select: function( event, ui ) {
 				input.val(ui.item.value);
 				saveVal( dataElementId );
 				input.autocomplete( "close" );
-			},
-			change: function( event, ui ) {
-				if ( !ui.item ) {
-					var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
-						valid = false;
-					for (var i = 0; i < options.length; i++)
-					{
-						if (options[i].match( matcher ) ) {
-							this.selected = valid = true;
-							break;
-						}
-					}
-					if ( !valid ) {
-						// remove invalid value, as it didn't match anything
-						$( this ).val( "" );
-						input.data( "autocomplete" ).term = "";
-						return false;
-					}
-				}
-				saveVal( dataElementId );
 			}
 		})
 		.addClass( "ui-widget" );
-
-	this.button = $( "<button type='button'>&nbsp;</button>" )
-		.attr( "tabIndex", -1 )
-		.attr( "title", i18n_show_all_items )
-		.insertAfter( input )
-		.button({
-			icons: {
-				primary: "ui-icon-triangle-1-s"
-			},
-			text: false
-		})
-		.addClass( "optionset-small-button" )
-		.click(function() {
-			// close if already visible
-			if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
-				input.autocomplete( "close" );
-				return;
-			}
-
-			// work around a bug (likely same cause as #5265)
-			$( this ).blur();
-
-			// pass empty string as value to search for, displaying all results
-			input.autocomplete( "search", "" );
-			input.focus();
-		});
 }
-
-/* function hexToR(h) {
-	return parseInt((cutHex(h)).substring(0,2),16) + 
-	parseInt((cutHex(h)).substring(2,4),16);
-	parseInt((cutHex(h)).substring(2,4),16);
-} */

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm	2012-06-15 04:41:31 +0000
@@ -0,0 +1,7 @@
+{ "options": [
+  #foreach( $option in $options )
+	"$option",
+  #end
+   ""
+  ]
+}
\ No newline at end of file