← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7997: local vn - Showed ICD form by manual. Improved the performance in loading and inserting value int...

 

------------------------------------------------------------
revno: 7997
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-09-04 15:23:52 +0700
message:
  local vn - Showed ICD form by manual. Improved the performance in loading and inserting value into form.
added:
  local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/LoadICDFormAction.java
  local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/defaultICDForm.vm
modified:
  local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java
  local/vn/dhis-web-dataentry-hospital/src/main/resources/META-INF/dhis/beans.xml
  local/vn/dhis-web-dataentry-hospital/src/main/resources/struts.xml
  local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/javascript/form.js
  local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/select.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 'local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java'
--- local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java	2012-05-03 02:23:12 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java	2012-09-04 08:23:52 +0000
@@ -27,7 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.LocalDataElementService;
 import org.hisp.dhis.dataset.CompleteDataSetRegistration;
 import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSet;
@@ -40,9 +48,11 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.reportsheet.AttributeValueGroupOrder;
+import org.hisp.dhis.reportsheet.AttributeValueGroupOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.Collection;
-import java.util.Date;
+import com.opensymphony.xwork2.Action;
 
 /**
  * @author Lars Helge Overland
@@ -89,6 +99,12 @@
         this.organisationUnitService = organisationUnitService;
     }
 
+    @Autowired
+    private LocalDataElementService localDataElementService;
+
+    @Autowired
+    private AttributeValueGroupOrderService attributeValueGroupOrderService;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -114,6 +130,13 @@
         this.organisationUnitId = organisationUnitId;
     }
 
+    private Integer chapterId;
+
+    public void setChapterId( Integer chapterId )
+    {
+        this.chapterId = chapterId;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -160,6 +183,8 @@
         return storedBy;
     }
 
+    private List<String> values = new ArrayList<String>();
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -174,13 +199,35 @@
         // Data values
         // ---------------------------------------------------------------------
 
-        dataValues = dataValueService.getDataValues( organisationUnit, period, dataSet.getDataElements() );
+        AttributeValueGroupOrder group = attributeValueGroupOrderService.getAttributeValueGroupOrder( chapterId );
+
+        if ( group != null )
+        {
+            values = group.getAttributeValues();
+        }
+
+        if ( values != null && !values.isEmpty() )
+        {
+            Collection<DataElement> dataElements = new HashSet<DataElement>();
+
+            for ( String value : values )
+            {
+                dataElements.addAll( localDataElementService.getDataElements( dataSet, value ) );
+            }
+
+            dataValues = dataValueService.getDataValues( organisationUnit, period, dataElements );
+        }
+        else
+        {
+            dataValues = dataValueService.getDataValues( organisationUnit, period, dataSet.getDataElements() );
+        }
 
         // ---------------------------------------------------------------------
         // Min-max data elements
         // ---------------------------------------------------------------------
 
-        minMaxDataElements = minMaxDataElementService.getMinMaxDataElements( organisationUnit, dataSet.getDataElements() );
+        minMaxDataElements = minMaxDataElementService.getMinMaxDataElements( organisationUnit, dataSet
+            .getDataElements() );
 
         // ---------------------------------------------------------------------
         // Data set completeness info
@@ -188,14 +235,15 @@
 
         if ( dataSet != null && period != null && organisationUnit != null )
         {
-            CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period, organisationUnit );
+            CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet,
+                period, organisationUnit );
 
             if ( registration != null )
             {
                 complete = true;
                 date = registration.getDate();
                 storedBy = registration.getStoredBy();
-            }            
+            }
 
             locked = dataSetService.isLocked( dataSet, period, organisationUnit, null );
         }

=== added file 'local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/LoadICDFormAction.java'
--- local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/LoadICDFormAction.java	1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/java/org/hisp/dhis/de/action/LoadICDFormAction.java	2012-09-04 08:23:52 +0000
@@ -0,0 +1,133 @@
+package org.hisp.dhis.de.action;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.LocalDataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.reportsheet.AttributeValueGroupOrder;
+import org.hisp.dhis.reportsheet.AttributeValueGroupOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class LoadICDFormAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private DataSetService dataSetService;
+
+    @Autowired
+    private LocalDataElementService localDataElementService;
+
+    @Autowired
+    private AttributeValueGroupOrderService attributeValueGroupOrderService;
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer dataSetId;
+
+    public void setDataSetId( Integer dataSetId )
+    {
+        this.dataSetId = dataSetId;
+    }
+
+    private Integer chapterId;
+
+    public void setChapterId( Integer chapterId )
+    {
+        this.chapterId = chapterId;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Map<String, Collection<DataElement>> orderedDiseaseDataElements = new HashMap<String, Collection<DataElement>>();
+
+    public Map<String, Collection<DataElement>> getOrderedDiseaseDataElements()
+    {
+        return orderedDiseaseDataElements;
+    }
+
+    private List<String> values = new ArrayList<String>();
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        DataSet dataSet = dataSetService.getDataSet( dataSetId, true, false, false );
+
+        AttributeValueGroupOrder group = attributeValueGroupOrderService.getAttributeValueGroupOrder( chapterId );
+
+        if ( group != null )
+        {
+            values = group.getAttributeValues();
+        }
+
+        Collections.sort( values );
+
+        for ( String value : values )
+        {
+            if ( value != null && !value.trim().isEmpty() )
+            {
+                List<DataElement> dataElements = new ArrayList<DataElement>( localDataElementService.getDataElements(
+                    dataSet, value ) );
+
+                orderedDiseaseDataElements.put( value, dataElements );
+            }
+        }
+
+        return DataSet.TYPE_DEFAULT;
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+}

=== modified file 'local/vn/dhis-web-dataentry-hospital/src/main/resources/META-INF/dhis/beans.xml'
--- local/vn/dhis-web-dataentry-hospital/src/main/resources/META-INF/dhis/beans.xml	2012-08-06 17:06:50 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/resources/META-INF/dhis/beans.xml	2012-09-04 08:23:52 +0000
@@ -39,6 +39,8 @@
     <property name="localDataElementService" ref="org.hisp.dhis.dataelement.LocalDataElementService" />
   </bean>
 
+  <bean id="org.hisp.dhis.de.action.LoadICDFormAction" class="org.hisp.dhis.de.action.LoadICDFormAction" scope="prototype" />
+
   <bean id="org.hisp.dhis.de.action.SaveValueAction" class="org.hisp.dhis.de.action.SaveValueAction" scope="prototype">
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />

=== modified file 'local/vn/dhis-web-dataentry-hospital/src/main/resources/struts.xml'
--- local/vn/dhis-web-dataentry-hospital/src/main/resources/struts.xml	2012-06-28 08:17:52 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/resources/struts.xml	2012-09-04 08:23:52 +0000
@@ -36,6 +36,10 @@
       <result name="input" type="velocity">/dhis-web-dataentry-hospital/responseVoid.vm</result>
     </action>
 
+    <action name="loadICDForm" class="org.hisp.dhis.de.action.LoadICDFormAction">
+      <result name="default" type="velocity">/dhis-web-dataentry-hospital/defaultICDForm.vm</result>
+    </action>
+
     <action name="saveValue" class="org.hisp.dhis.de.action.SaveValueAction">
       <result name="success" type="velocity-json">/dhis-web-dataentry-hospital/status.vm</result>
       <param name="onExceptionReturn">plainTextError</param>

=== added file 'local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/defaultICDForm.vm'
--- local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/defaultICDForm.vm	1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/defaultICDForm.vm	2012-09-04 08:23:52 +0000
@@ -0,0 +1,51 @@
+<script type="text/javascript">
+	jQuery(document).ready( function() {
+		setTableStyles();
+	});
+</script>
+
+#set( $tabIndex = 1 )
+#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry-hospital", "saveValue" ) )
+
+<table class="listTable" id="listTable" cellspacing="0">
+	<thead>
+	<tr><td></td>
+		<th>$i18n.getString( "icd_element_1" )</th>
+		<th>$i18n.getString( "icd_element_2" )</th>
+		<th>$i18n.getString( "icd_element_3" )</th>
+		<th>$i18n.getString( "icd_element_4" )</th>
+		<th>$i18n.getString( "icd_element_5" )</th>
+		<th>$i18n.getString( "icd_element_6" )</th>
+		<th>$i18n.getString( "icd_element_7" )</th>
+		<th>$i18n.getString( "icd_element_8" )</th>
+		<th>$i18n.getString( "icd_element_9" )</th>
+		<th>$i18n.getString( "icd_element_10" )</th>
+		<th>$i18n.getString( "icd_element_11" )</th>
+		<th>$i18n.getString( "icd_element_12" )</th>
+	</tr>
+	</thead>
+
+	<tbody id="list">
+	#foreach( $key in $!orderedDiseaseDataElements.keySet() )
+	<tr>
+		<td>${encoder.htmlEncode( $key )}</td>
+		#foreach( $dataElement in $!orderedDiseaseDataElements.get( $key ) )
+		#set( $dataEntryId = "${dataElement.id}-15-val" )
+		<span id="${dataElement.id}-dataelement" style="display:none">${encoder.htmlEncode( $dataElement.getFormNameFallback() )}</span>
+		<td id="${dataElement.id}-cell">
+			#if( $dataElement.type == "bool" )
+			<select name="entryselect" id="$dataEntryId" #if( !$hasAccess ) disabled="disabled" #end tabindex="$tabIndex">
+				<option value="">[ $i18n.getString( "no_value" ) ]</option>
+				<option value="true">$i18n.getString( "yes" )</option>
+				<option value="false">$i18n.getString( "no" )</option>
+			</select>
+			#else
+			<input name="entryfield" id="$dataEntryId" type="text" #if( !$hasAccess ) disabled="disabled" #end tabindex="$tabIndex"/>
+			#end
+		</td>
+		#set( $tabIndex = $tabIndex + 1 )
+		#end
+	</tr>
+	#end
+	</tbody>
+</table>
\ No newline at end of file

=== modified file 'local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/javascript/form.js'
--- local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/javascript/form.js	2012-08-15 18:21:22 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/javascript/form.js	2012-09-04 08:23:52 +0000
@@ -35,6 +35,9 @@
 var currentOrganisationUnitName = "";
 
 // Currently selected data set identifier
+var currentChapterId = null;
+
+// Currently selected data set identifier
 var currentDataSetId = null;
 
 // Currently selected period type name
@@ -89,8 +92,6 @@
  
 function organisationUnitSelectedHospitals( orgUnits, orgUnitNames )
 {
-	clearEntryForm();
-
     currentOrganisationUnitId = orgUnits[0];
     currentOrganisationUnitName = orgUnitNames[0];
 
@@ -136,16 +137,14 @@
 					enable( 'selectedDataSetId' );
 
 					var periodId = $( '#selectedPeriodId option:selected' ).val();
-					var periodType = "";
+					var dataSetId = $( '#selectedDataSetId option:selected' ).val();
+					var chapterId = $( '#chapterId option:selected' ).val();
 					
-					if ( periodId && periodId != -1 )
-					{
-						periodType = periodId.split( '_' )[0];
-					}
-
-					if ( currentPeriodType && currentPeriodType != -1 && currentPeriodType == periodType )
-					{
-						loadForm( currentDataSetId, getFieldValue( 'valueInput' ) );
+					if ( (dataSetId && dataSetId != -1) && (currentDataSetId && currentDataSetId != -1) && (dataSetId = currentDataSetId) && (periodId && periodId != -1) )
+					{
+						loadDataValues( dataSetId, chapterId );
+					} else {
+						clearEntryForm();
 					}
 				} else {
 					resetCriteriaDiv();
@@ -220,62 +219,6 @@
     } );
 }
 
-function resetCriteriaDiv()
-{
-	currentDataSetId = null;
-	currentPeriodType = null;
-	
-	clearListById( 'selectedPeriodId' );
-	
-	hideById( 'chapterTR' );
-	hideById( 'attributeTR' );
-	
-	byId( 'inputCriteria' ).style.width = '504px';
-	byId( 'inputCriteria' ).style.height = '80px';
-
-    $( '#currentPeriod' ).html( i18n_no_period_selected );
-    $( '#currentDataElement' ).html( i18n_no_dataelement_selected );
-	
-    clearEntryForm();
-}
-
-function clearEntryForm()
-{
-    $( '#contentDiv' ).html( '' );
-
-    currentPeriodOffset = 0;
-
-    dataEntryFormIsLoaded = false;
-
-    $( '#completenessDiv' ).hide();
-    $( '#infoDiv' ).hide();
-}
-
-function loadForm( dataSetId, value )
-{
-	showLoader();
-
-    $( '#currentDataElement' ).html( i18n_no_dataelement_selected );
-
-	$( '#contentDiv' ).load( 'loadForm.action',
-	{
-		dataSetId : dataSetId,
-		value: value
-	}, 
-	function ( responseText, textStatus, req )
-	{
-		if ( textStatus == "error" ) {
-			hideLoader();
-			hideById( 'showReportButton' );
-			hideById( 'ICDButtonDiv' );
-			clearEntryForm();
-			setHeaderDelayMessage( i18n_disconnect_server );
-			return;
-        }
-		loadDataValues( dataSetId );
-	} );
-}
-
 function getDataElementType( dataElementId )
 {
 	if ( dataElements[dataElementId] != null )
@@ -382,13 +325,11 @@
     $( '#currentDataElement' ).html( i18n_no_dataelement_selected );
 
 	clearListById( 'selectedPeriodId' );
-	hideById('attributeDiv');
 	
 	$( '#selectedPeriodId' ).unbind( 'change' );
 	$( '#selectedPeriodId' ).removeAttr( 'disabled' );
     $( '#prevButton' ).removeAttr( 'disabled' );
     $( '#nextButton' ).removeAttr( 'disabled' );
-	$( '#valueInput' ).val('');
 
     var dataSetId = $( '#selectedDataSetId option:selected' ).val();
     var periodId = $( '#selectedPeriodId option:selected' ).val();
@@ -416,8 +357,8 @@
 
         currentDataSetId = dataSetId;
 		currentPeriodType = periodType;
-		
-		//loadSubDataSets( dataSetId );
+
+		showById( 'chapterTR' );
 		loadAttributeValues( dataSetId );
     }
 }
@@ -471,28 +412,12 @@
 	}
 	, function( json )
 	{
-		clearListById( 'value' );
-	
 		if ( json.attributeValues.length > 0 )
 		{
-			arrAttributeValues = [];
-		
-			jQuery.each( json.attributeValues, function( i, item )
-			{
-				arrAttributeValues.push( item );
-				jQuery( '#value' ).append( '<option value="' + item + '">' + item + '</option>' );
-			} );
-
-			autoCompletedField();
-
 			byId( 'inputCriteria' ).style.width = '504px';
 			byId( 'inputCriteria' ).style.height = '130px';
 
-			//hideById( 'departmentTitleDiv' );
-			//hideById( 'departmentDiv' );
-
 			showById( 'chapterTR' );
-			showById( 'attributeTR' );
 		}
 		else
 		{
@@ -500,7 +425,6 @@
 			byId( 'inputCriteria' ).style.height = '80px';
 			
 			hideById( 'chapterTR' );
-			hideById( 'attributeTR' );
 		}
 		
 		jQuery( '#selectedPeriodId' ).bind( 'change', periodSelected );
@@ -555,6 +479,131 @@
 // Period Selection
 // -----------------------------------------------------------------------------
 
+function periodSelected()
+{
+	var periodName = $( '#selectedPeriodId option:selected' ).text();
+	var dataSetId = $( '#selectedDataSetId option:selected' ).val();
+	var formLoaded = (getInnerHTML('contentDiv') != '');
+
+	if ( dataSetId && dataSetId != -1 )
+	{
+		$( '#currentPeriod' ).html( periodName );
+
+		var periodId = getFieldValue( 'selectedPeriodId' );
+		var chapterId = getFieldValue( 'chapterId' );
+
+		if ( periodId && periodId != -1 )
+		{
+			if ( currentDataSetId && currentDataSetId == dataSetId )
+			{
+				if ( formLoaded )
+				{
+					loadDataValues( dataSetId, chapterId );
+				} else {
+					loadForm( dataSetId, "" );
+				}
+			} else {
+				loadForm( dataSetId, "" );
+			}
+		}
+		else {
+			clearEntryForm();
+		}
+	} else {
+		setHeaderDelayMessage( i18n_please_select_data_set );
+	}
+}
+
+// -----------------------------------------------------------------------------
+// Form
+// -----------------------------------------------------------------------------
+
+function resetCriteriaDiv()
+{
+	currentDataSetId = null;
+	currentPeriodType = null;
+	currentChapterId = null;
+	
+	clearListById( 'selectedPeriodId' );
+	
+	hideById( 'chapterTR' );
+	
+	byId( 'inputCriteria' ).style.width = '504px';
+	byId( 'inputCriteria' ).style.height = '80px';
+
+    $( '#currentPeriod' ).html( i18n_no_period_selected );
+    $( '#currentDataElement' ).html( i18n_no_dataelement_selected );
+	
+    clearEntryForm();
+}
+
+function clearEntryForm()
+{
+    $( '#contentDiv' ).html( '' );
+
+    currentPeriodOffset = 0;
+
+    dataEntryFormIsLoaded = false;
+
+    $( '#completenessDiv' ).hide();
+    $( '#infoDiv' ).hide();
+}
+
+function loadForm( dataSetId, value )
+{
+	showLoader();
+
+    $( '#currentDataElement' ).html( i18n_no_dataelement_selected );
+
+	var chapterId = getFieldValue( 'chapterId' );
+	var	url = ( chapterId && chapterId != -1 ? 'loadICDForm.action' : 'loadForm.action' );
+	
+	if ( chapterId )
+	{
+	}
+
+	$( '#contentDiv' ).load( url,
+	{
+		dataSetId : dataSetId,
+		chapterId: chapterId,
+		value: value
+	}, 
+	function ( responseText, textStatus, req )
+	{
+		if ( textStatus == "error" ) {
+			hideLoader();
+			hideById( 'showReportButton' );
+			hideById( 'ICDButtonDiv' );
+			clearEntryForm();
+			setHeaderDelayMessage( i18n_disconnect_server );
+			return;
+        }
+		loadDataValues( dataSetId, chapterId );
+	} );
+}
+
+function loadFormByChapter( chapterId )
+{
+	var periodId = getFieldValue( 'selectedPeriodId' );
+	var dataSetId = getFieldValue( 'selectedDataSetId' );
+
+	if ( dataSetId == null || dataSetId == -1 )
+	{
+		setHeaderDelayMessage( i18n_please_select_data_set );
+		return;
+	}
+	
+	if ( periodId == null || periodId == -1 )
+	{
+		setHeaderDelayMessage( i18n_please_select_period );
+		return;
+	}
+	
+	loadForm( dataSetId );
+
+	currentChapterId = chapterId;
+}
+
 function loadDepartmentFormSelected()
 {
     var periodName = $( '#selectedPeriodId option:selected' ).text();
@@ -575,56 +624,18 @@
 	}
 }
 
-function periodSelected()
-{
-	var periodName = $( '#selectedPeriodId option:selected' ).text();
-	var dataSetId = $( '#selectedDataSetId option:selected' ).val();
-
-	if ( dataSetId && dataSetId != -1 )
-	{
-		$( '#currentPeriod' ).html( periodName );
-
-		var periodId = getFieldValue( 'selectedPeriodId' );
-
-		if ( periodId && periodId != -1 )
-		{
-			if ( hasElements( 'subDataSetId' ) && getFieldValue( 'subDataSetId' ) == null )
-			{
-				return;
-			}
-			else if ( getFieldValue( 'subDataSetId' ) )
-			{
-				dataSetId = $( '#subDataSetId option:selected' ).val();
-			}
-
-			showLoader();
-			loadForm( dataSetId, getFieldValue( 'valueInput' ) );
-		}
-		else
-		{
-			clearEntryForm();
-		}
-	} else {
-		setHeaderDelayMessage( i18n_please_select_data_set );
-	}
-}
-
-// -----------------------------------------------------------------------------
-// Form
-// -----------------------------------------------------------------------------
-
-function loadDataValues( dataSetId )
+function loadDataValues( dataSetId, chapterId )
 {
     $( '#completeButton' ).removeAttr( 'disabled' );
     $( '#undoButton' ).attr( 'disabled', 'disabled' );
     $( '#infoDiv' ).css( 'display', 'none' );
 	showById( 'showReportButton' );
 
-    insertDataValues( dataSetId );
+    insertDataValues( dataSetId, chapterId );
     displayEntryFormCompleted();
 }
 
-function insertDataValues( dataSetId )
+function insertDataValues( dataSetId, chapterId )
 {
     var dataValueMap = [];
 	currentMinMaxValueMap = []; // Reset
@@ -650,6 +661,7 @@
 	    {
 	        periodId : periodId,
 	        dataSetId : dataSetId,
+			chapterId: chapterId,
 			attributeId: getFieldValue( 'attributeId' ),
 			value: getFieldValue( 'valueInput' ),
 	        organisationUnitId : currentOrganisationUnitId
@@ -918,7 +930,6 @@
                     disableUndoButton();
 	                //storageManager.clearCompleteDataSet( params );
                 }
-
 	        },
 	        error: function()
 	        {

=== modified file 'local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/select.vm'
--- local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/select.vm	2012-08-15 18:34:33 +0000
+++ local/vn/dhis-web-dataentry-hospital/src/main/webapp/dhis-web-dataentry-hospital/select.vm	2012-09-04 08:23:52 +0000
@@ -53,10 +53,10 @@
 	
 	<tr id='chapterTR' style='display:none;'>
 		<td><label class='bold' for="chapterId">$i18n.getString( "chapter" )</label></td>
-		<td><select id='chapterId' name='chapterId' style="width:370px" onchange="loadAttributeValuesByChapter( this.value );"></select></td>
+		<td><select id='chapterId' name='chapterId' style="width:370px" onchange="loadFormByChapter( this.value );"></select></td>
 	</tr>
 
-	<tr id='attributeTR' style='display:none;'>
+	<!--tr id='attributeTR' style='display:none;'>
 		<td>
 			<label class='bold' for="attributeId">$i18n.getString( "disease" )</label>
 		</td>
@@ -66,8 +66,7 @@
 			<button type='button' id='valueButton' class='small-button' >&nbsp;</button>
 			<input type="button" id="showReportButton" value="$i18n.getString( 'show_icd_report' )" style="display:none;width:120px" onclick="showICDReport();"/>
 		</td>
-	</tr>
-	
+	</tr-->
 
 </table>
 </div>
@@ -127,8 +126,6 @@
 
 <script type="text/javascript">
 
-//leftBar.hideAnimated();
-
 var openICD = true;
 
 var i18n_select_data_set = '$encoder.jsEscape( $i18n.getString( "select_data_set" ) , "'")';
@@ -175,6 +172,7 @@
 var i18n_select_department = "[ " + '$encoder.jsEscape( $i18n.getString( "please_select_department" ) , "'")' + " ]";
 var i18n_please_select_unit = "[ " + '$encoder.jsEscape( $i18n.getString( "please_select_organisation_unit" ) , "'")' + " ]";
 var i18n_please_select_data_set = "[ " + '$encoder.jsEscape( $i18n.getString( "please_select_data_set" ) , "'")' + " ]";
+var i18n_please_select_chapter = "[ " + '$encoder.jsEscape( $i18n.getString( "please_select_chapter" ) , "'")' + " ]";
 var i18n_select_chapter = "[ " + '$encoder.jsEscape( $i18n.getString( "select_chapter" ) , "'")' + " ]";
 var i18n_explore_icd_report_result = '$encoder.jsEscape( $i18n.getString( "explore_icd_report_result" ) , "'")';
 var i18n_collpase_icd_report_result = '$encoder.jsEscape( $i18n.getString( "collapse_icd_report_result" ) , "'")';