← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15826: Fixed bug - Exception thrown when to click DataEntry icon to open Update single-event with regist...

 

------------------------------------------------------------
revno: 15826
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-24 18:12:20 +0800
message:
  Fixed bug - Exception thrown when to click DataEntry icon to open Update single-event with registration form.
removed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm
renamed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java => dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstanceAction.java
modified:
  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/javascript/form.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstanceAction.java


--
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
=== renamed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java' => 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2014-06-22 13:38:08 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstanceAction.java	2014-06-24 10:12:20 +0000
@@ -29,29 +29,38 @@
  */
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
 /**
  * @author Chau Thu Tran
  */
-public class LoadProgramStageInstancesAction
+public class LoadProgramStageInstanceAction
     implements Action
 {
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
 
+    @Autowired
+    private SelectionTreeManager selectionTreeManager;
+
     private TrackedEntityInstanceService entityInstanceService;
 
     public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
@@ -98,18 +107,11 @@
         return statusMap;
     }
 
-    private ProgramInstance programInstance;
-
-    public ProgramInstance getProgramInstance()
-    {
-        return programInstance;
-    }
-
-    private List<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
-
-    public List<ProgramStageInstance> getProgramStageInstances()
-    {
-        return programStageInstances;
+    private ProgramStageInstance programStageInstance;
+
+    public ProgramStageInstance getProgramStageInstance()
+    {
+        return programStageInstance;
     }
 
     private Program program;
@@ -126,26 +128,28 @@
     public String execute()
         throws Exception
     {
-//        TrackedEntityInstance entityInstance = entityInstanceService.getTrackedEntityInstance( entityInstanceId );
+        TrackedEntityInstance entityInstance = entityInstanceService.getTrackedEntityInstance( entityInstanceId );
 
         program = programService.getProgram( programId );
-//
-//        List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
-//
-//        if ( program.getType() == Program.MULTIPLE_EVENTS_WITH_REGISTRATION )
-//        {
-//            programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( entityInstance,
-//                program, ProgramInstance.STATUS_ACTIVE ) );
-//        }
-//        else if ( program.getType() == Program.SINGLE_EVENT_WITH_REGISTRATION )
-//        {
-//            programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( entityInstance,
-//                program ) );
-//        }
-//        else
-//        {
-//            programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( program ) );
-//        }
+
+        List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
+
+        programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( entityInstance,
+            program ) );
+
+        if ( programInstances != null && programInstances.size() > 0 )
+        {
+            Iterator<ProgramInstance> iterProgram =  programInstances.iterator();
+            programStageInstance = iterProgram.next().getProgramStageInstances().iterator().next();
+        }
+        else
+        {
+            OrganisationUnit orgunit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
+            Date today = new Date();
+            ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance,
+                program, today, today, orgunit );
+            programStageInstance = programInstance.getProgramStageInstances().iterator().next();
+        }
 
         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	2014-06-20 12:32:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-06-24 10:12:20 +0000
@@ -49,8 +49,8 @@
 	</bean>
 
 	<bean
-		id="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstancesAction"
-		class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstancesAction"
+		id="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstanceAction"
+		class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstanceAction"
 		scope="prototype">
 		<property name="entityInstanceService" ref="org.hisp.dhis.trackedentity.TrackedEntityInstanceService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />

=== 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	2014-06-18 13:30:41 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2014-06-24 10:12:20 +0000
@@ -43,10 +43,10 @@
 			<param name="requiredAuthorities">F_TRACKED_ENTITY_INSTANCE_SEARCH</param>
 		</action>
 
-		<action name="loadProgramStageInstances"
-			class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstancesAction">
+		<action name="loadProgramStageInstance"
+			class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstanceAction">
 			<result name="success" type="velocity-json">
-				/dhis-web-caseentry/jsonProgramStageInstances.vm
+				/dhis-web-caseentry/jsonProgramStageInstance.vm
 			</result>
 		</action>
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js	2014-05-25 14:36:40 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js	2014-06-24 10:12:20 +0000
@@ -335,41 +335,18 @@
 
 function loadProgramStages( entityInstanceId, programId )
 {
-	jQuery.getJSON( "loadProgramStageInstances.action",
+	jQuery.getJSON( "loadProgramStageInstance.action",
 		{
 			entityInstanceId:entityInstanceId,
 			programId: programId
 		},  
 		function( json ) 
 		{   
-			if( json.programStageInstances == 0)
-			{
-				createProgramInstance( entityInstanceId, programId );
-			}
-			else
-			{
-				jQuery("#selectForm [id=programStageId]").attr('psid', json.programStageInstances[0].programStageId);	
-				loadDataEntry( json.programStageInstances[0].id );
-			}
+			jQuery("#selectForm [id=programStageId]").attr('psid', json.id);	
+			loadDataEntry( json.id );
 		});
 }
 
-function createProgramInstance( entityInstanceId, programId )
-{
-	jQuery.postJSON( "saveProgramEnrollment.action",
-		{
-			entityInstanceId: entityInstanceId,
-			programId: programId,
-			dateOfIncident: getCurrentDate(),
-			enrollmentDate: getCurrentDate()
-		}, 
-		function( json ) 
-		{
-			jQuery("#selectForm [id=programStageId]").attr('psid', json.programStageId);	
-			loadDataEntry( json.activeProgramStageInstanceId );
-		});
-};		
-
 function removeSingleEvent(uid)
 {
 	var result = window.confirm( i18n_comfirm_delete_event );

=== removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm	2014-06-20 13:08:17 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm	1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
-#set( $size = $programInstance.programStageInstances.size() )
-{ 
-"programStageInstances": [
-	#foreach( $programStageInstance in $!programInstance.programStageInstances )
-	  {
-		"id": "$programStageInstance.id",
-		"programStageId": "$programStageInstance.programStage.id",
-		"programStageName": "$programStageInstance.programStage.displayName",
-		"dueDate": "$format.formatDate( $programStageInstance.dueDate )",
-		"status": "$programStageInstance.getEventStatus().getValue()"
-	  }#if( $velocityCount < $size ),#end
-	#end]
-}
\ No newline at end of file