← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5050: Add Enter new encounter function for the data-entry form for irrgular-encounter program-stage.

 

------------------------------------------------------------
revno: 5050
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-10-27 12:51:06 +0700
message:
  Add Enter new encounter function for the data-entry form for irrgular-encounter program-stage.
added:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.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/org/hisp/dhis/caseentry/i18n_module.properties
  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/dataRecordingSelect.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/javascript/patient.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2011-05-02 18:40:36 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2011-10-27 05:51:06 +0000
@@ -26,6 +26,7 @@
  */
 package org.hisp.dhis.program.hibernate;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -48,10 +49,14 @@
     extends HibernateGenericStore<ProgramStageInstance>
     implements ProgramStageInstanceStore
 {
+    @SuppressWarnings( "unchecked" )
     public ProgramStageInstance get( ProgramInstance programInstance, ProgramStage programStage )
     {
-        return (ProgramStageInstance) getCriteria( Restrictions.eq( "programInstance", programInstance ),
-            Restrictions.eq( "programStage", programStage ) ).uniqueResult();
+        List<ProgramStageInstance> list = new ArrayList<ProgramStageInstance>( getCriteria(
+            Restrictions.eq( "programInstance", programInstance ), Restrictions.eq( "programStage", programStage ) )
+            .list() );
+
+        return (list == null) ? null : list.get( list.size() - 1 );
     }
 
     @SuppressWarnings( "unchecked" )
@@ -100,12 +105,12 @@
         {
             hql += " and dueDate >= :after";
         }
-        
+
         if ( before != null )
         {
             hql += " and dueDate <= :before";
         }
-        
+
         if ( completed != null )
         {
             hql += " and completed = :completed";
@@ -117,12 +122,12 @@
         {
             q.setDate( "after", after );
         }
-        
+
         if ( before != null )
         {
             q.setDate( "before", before );
         }
-        
+
         if ( completed != null )
         {
             q.setBoolean( "completed", completed );
@@ -135,7 +140,7 @@
     public List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed )
     {
         String hql = "from ProgramStageInstance where programInstance.patient = :patient and completed = :completed";
-        
+
         return getQuery( hql ).setEntity( "patient", patient ).setBoolean( "completed", completed ).list();
     }
 }

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java	2011-10-27 05:51:06 +0000
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2004-2010, 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.Date;
+
+import org.hisp.dhis.caseentry.state.SelectedStateManager;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $Id: AddIrregularEncounterAction.java Oct 27, 2011 10:58:23 AM $
+ */
+public class RegisterIrregularEncounterAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramStageInstanceService programStageInstanceService;
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
+    private SelectedStateManager selectedStateManager;
+
+    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
+    {
+        this.selectedStateManager = selectedStateManager;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        ProgramStageInstance currentStageInstance = selectedStateManager.getSelectedProgramStageInstance();
+
+        ProgramStageInstance programStageInstance = new ProgramStageInstance();
+        programStageInstance.setProgramInstance( currentStageInstance.getProgramInstance() );
+        programStageInstance.setProgramStage( currentStageInstance.getProgramStage() );
+        programStageInstance.setStageInProgram( currentStageInstance.getStageInProgram() + 1 );
+        programStageInstance.setDueDate( new Date() );
+        programStageInstance.setExecutionDate( new Date() );
+
+        programStageInstanceService.addProgramStageInstance( programStageInstance );
+
+        selectedStateManager.setSelectedProgramStageInstance( programStageInstance );
+        
+        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	2011-10-05 03:39:54 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2011-10-27 05:51:06 +0000
@@ -159,6 +159,15 @@
 			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.caseentry.action.caseentry.RegisterIrregularEncounterAction"
+		class="org.hisp.dhis.caseentry.action.caseentry.RegisterIrregularEncounterAction"
+		scope="prototype">
+		<property name="programStageInstanceService"
+			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+		<property name="selectedStateManager"
+			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
+	</bean>
 
 	<!-- Multi DataEntry -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2011-10-21 08:11:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2011-10-27 05:51:06 +0000
@@ -441,4 +441,5 @@
 aggregate_details												= Aggregate details
 show_details													= Show details
 representative_info												= Representative's Information
-relationship_for 												= Relationship for
\ No newline at end of file
+relationship_for 												= Relationship for
+enter_new_encounter												= Enter new encounter
\ No newline at end of file

=== 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	2011-10-06 09:06:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2011-10-27 05:51:06 +0000
@@ -93,6 +93,12 @@
 				/dhis-web-commons/ajax/xmlResponseInput.vm</result>
 			<param name="onExceptionReturn">plainTextError</param>
 		</action>
+		
+		<action name="registerIrregularEncounter"
+			class="org.hisp.dhis.caseentry.action.caseentry.RegisterIrregularEncounterAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+		</action>
 
 		<!-- save value -->
 

=== 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	2011-10-21 08:11:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2011-10-27 05:51:06 +0000
@@ -22,6 +22,8 @@
 
 <input type='hidden' id='incidentDate' value='$!format.formatDate($programStageInstance.programInstance.dateOfIncident)'>
 <input type='hidden' name='programStageInstanceId' id='programStageInstanceId' value='$!programStageInstance.id'>
+<input type='hidden' name='irregular' id='irregular' value='$!programStageInstance.programStage.irregular'>
+<input type='hidden' name='completed' id='completed' value='$!programStageInstance.completed'>
 
 <div id='entryForm' style="display: #if($!programStageInstance.executionDate) block #else none #end;">
 	#if( $customDataEntryFormCode )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataRecordingSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataRecordingSelect.vm	2011-10-21 08:11:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataRecordingSelect.vm	2011-10-27 05:51:06 +0000
@@ -54,7 +54,7 @@
 				
 				<tr>
 					<td><label for="executionDate">$i18n.getString( "report_date" ) </label></td>
-					<td><input type="text" id="executionDate" name="executionDate" style="width:350px" value="$!format.formatDate( $programStageInstance.executionDate )" >
+					<td><input type="text" id="executionDate" name="executionDate" style="width:330px" value="$!format.formatDate( $programStageInstance.executionDate )" >
 						<script type="text/javascript">
 						   datePickerValid( 'executionDate', false );
 						</script>
@@ -71,6 +71,11 @@
 			<table>
 				<tr>
 					<td align='right' colspan='2'>
+						<input type="button" id="newEncounterBtn" value="$i18n.getString('enter_new_encounter')" onClick="javascript: registerIrregularEncounter();" style="width:12em " disabled="disabled" >
+					</td>
+				</tr>
+				<tr>
+					<td align='right' colspan='2'>
 						<input type="button" id="validationBtn" value="$i18n.getString('validation')" onClick="javascript: runValidation();" style="width:12em " disabled="disabled" >
 					</td>
 				</tr>

=== 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	2011-10-21 08:11:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2011-10-27 05:51:06 +0000
@@ -9,12 +9,13 @@
 	clearListById('programStageId');
 	setFieldValue('executionDate','');
 	setFieldValue('dueDate','');
-	
+	disable('completeBtn');
+	disable('validationBtn');
+	disable('newEncounterBtn');
+		
 	var programId = jQuery('#dataRecordingSelectDiv [name=programId]').val();
 	if ( programId == 0 )
 	{
-		disable('completeBtn');
-		disable('validationBtn');
 		return;
 	}
 	jQuery.postJSON( "loadProgramStages.action",
@@ -74,12 +75,13 @@
 	showById('dataEntryFormDiv');
 	setFieldValue( 'dueDate', '' );
 	setFieldValue( 'executionDate', '' );
-	
+	disable('validationBtn');
+	disable('completeBtn');
+	disable('newEncounterBtn');
+		
 	if( getFieldValue('programStageId') == null
 		|| getFieldValue('programStageId') == 0 )
 	{
-		disable('validationBtn');
-		disable('completeBtn');
 		return;
 	}
 	
@@ -90,8 +92,27 @@
 			programStageId:getFieldValue('programStageId')
 		},function( )
 		{
-			enable('validationBtn');
-			enable('completeBtn');
+			var executionDate = jQuery('#dataRecordingSelectDiv input[id=executionDate]').val();
+			var completed = jQuery('#entryFormContainer input[id=completed]').val();
+			var irregular = jQuery('#entryFormContainer input[id=irregular]').val();
+			
+			enable('executionDate');
+			if( executionDate != '' && completed == 'false' )
+			{
+				enable('validationBtn');
+				enable('completeBtn');
+			}
+			else if( completed == 'true' )
+			{
+				disable('validationBtn');
+				disable('completeBtn');
+				disable('executionDate');
+			}
+			
+			if( completed == 'true' && irregular == 'true' )
+			{
+				enable( 'newEncounterBtn' );
+			}
 			
 			hideLoader();
 			hideById('contentDiv'); 
@@ -748,6 +769,15 @@
 						jQuery(this).attr('style', 'display:none');
 					});
 					
+					disable('validationBtn');
+					disable('completeBtn');
+					disable('executionDate');
+					var irregular = jQuery('#entryFormContainer [name=irregular]').val();
+					if( irregular == 'true')
+					{
+						enable('newEncounterBtn');
+					}
+					
 					hideLoader();
 					hideById('contentDiv');
 				},'xml');
@@ -836,4 +866,17 @@
 			width: 800,
 			height: 450
 		});
+}
+
+//------------------------------------------------------
+// Register Irregular-encounter
+//------------------------------------------------------
+
+function registerIrregularEncounter()
+{
+	jQuery.postJSON( "registerIrregularEncounter.action",{}, 
+		function( json ) 
+		{   
+			loadDataEntry();
+		});
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2011-10-21 08:11:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2011-10-27 05:51:06 +0000
@@ -863,6 +863,7 @@
 			hideById('programStageIdLabel');
 			hideById('programStageId');
 			hideById('patientInfoDiv');
+			hideById( 'newEncounterBtn' );
 			
 			showById('dataRecordingSelectDiv');