← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8441: Load single event program into active program tab of dashboard, remove them from enrollment form.

 

------------------------------------------------------------
revno: 8441
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-09 10:53:11 +0700
message:
  Load single event program into active program tab of dashboard, remove them from enrollment form.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.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/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.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/patient/PatientDashboardAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java	2012-10-03 06:04:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java	2012-10-09 03:53:11 +0000
@@ -32,6 +32,8 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.hisp.dhis.caseentry.state.SelectedStateManager;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAudit;
 import org.hisp.dhis.patient.PatientAuditService;
@@ -39,8 +41,10 @@
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+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.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.user.CurrentUserService;
@@ -71,6 +75,10 @@
 
     private CurrentUserService currentUserService;
 
+    private ProgramService programService;
+
+    private SelectedStateManager selectedStateManager;
+
     // -------------------------------------------------------------------------
     // Input && Output
     // -------------------------------------------------------------------------
@@ -91,6 +99,8 @@
 
     private Collection<PatientAudit> patientAudits;
 
+    private Collection<Program> singlePrograms;
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -100,6 +110,21 @@
         this.patientAuditService = patientAuditService;
     }
 
+    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
+    {
+        this.selectedStateManager = selectedStateManager;
+    }
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    public Collection<Program> getSinglePrograms()
+    {
+        return singlePrograms;
+    }
+
     public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
     {
         this.patientAttributeValueService = patientAttributeValueService;
@@ -199,6 +224,20 @@
             }
         }
 
+        // ---------------------------------------------------------------------
+        // Check single-event with registration
+        // ---------------------------------------------------------------------
+
+        OrganisationUnit orgunit = selectedStateManager.getSelectedOrganisationUnit();
+
+        singlePrograms = programService.getPrograms( Program.SINGLE_EVENT_WITH_REGISTRATION, orgunit );
+
+        singlePrograms.removeAll( patient.getPrograms() );
+
+        // ---------------------------------------------------------------------
+        // Patient-Audit
+        // ---------------------------------------------------------------------
+
         patientAudits = patientAuditService.getPatientAudits( patient );
 
         long millisInDay = 60 * 60 * 24 * 1000;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java	2012-09-04 10:10:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java	2012-10-09 03:53:11 +0000
@@ -116,36 +116,10 @@
         patient = patientService.getPatient( id );
 
         // Get all programs
-        programs = programService.getPrograms( Program.MULTIPLE_EVENTS_WITH_REGISTRATION );
-
-        // Get single-event programs by the selected orgunit
-        Collection<Program> singleProgramsByOrgunit = programService.getPrograms(
-            Program.SINGLE_EVENT_WITH_REGISTRATION, orgunit );
-        programs.addAll( singleProgramsByOrgunit );
-
+        programs = programService.getPrograms( Program.MULTIPLE_EVENTS_WITH_REGISTRATION );        
         // Except anonymous program
         programs.removeAll( programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION ) );
 
-        // Get single-event if patient no have any single event
-        // OR have un-completed single-event
-        Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient, false );
-
-        for ( ProgramInstance programInstance : programInstances )
-        {
-            programs.remove( programInstance.getProgram() );
-        }
-
-        // Remove single-event with registation programs which patient completed
-        Collection<ProgramInstance> completedProgramInstances = programInstanceService.getProgramInstances( patient, true );
-
-        for ( ProgramInstance programInstance : completedProgramInstances )
-        {
-            if ( programInstance.getProgram().isSingleEvent() )
-            {
-                programs.remove( programInstance.getProgram() );
-            }
-        }
-
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java	2012-09-25 05:18:34 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java	2012-10-09 03:53:11 +0000
@@ -163,7 +163,7 @@
         {
             programInstance = programInstances.iterator().next();
         }
-
+        
         if ( programInstance == null )
         {
             programInstance = new ProgramInstance();
@@ -179,10 +179,16 @@
             patientService.updatePatient( patient );
 
             Date dateCreatedEvent = format.parseDate( dateOfIncident );
-            if( program.getGeneratedByEnrollmentDate())
+            if ( program.getGeneratedByEnrollmentDate() )
             {
                 dateCreatedEvent = format.parseDate( enrollmentDate );
             }
+            
+            if( program.isRegistration() && program.isSingleEvent())
+            {
+                
+            }
+            
             boolean isFirstStage = false;
             for ( ProgramStage programStage : program.getProgramStages() )
             {
@@ -191,11 +197,15 @@
                     ProgramStageInstance programStageInstance = new ProgramStageInstance();
                     programStageInstance.setProgramInstance( programInstance );
                     programStageInstance.setProgramStage( programStage );
-                    Date dueDate = DateUtils.getDateAfterAddition( dateCreatedEvent,
-                        programStage.getMinDaysFromStart() );
+                    Date dueDate = DateUtils
+                        .getDateAfterAddition( dateCreatedEvent, programStage.getMinDaysFromStart() );
 
                     programStageInstance.setDueDate( dueDate );
 
+                    if( program.isSingleEvent())
+                    {
+                        programStageInstance.setExecutionDate( dueDate );
+                    }
                     programStageInstanceService.addProgramStageInstance( programStageInstance );
 
                     if ( !isFirstStage )
@@ -215,12 +225,16 @@
 
             for ( ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances() )
             {
-                Date dueDate = DateUtils.getDateAfterAddition( format.parseDate( dateOfIncident ), programStageInstance
-                    .getProgramStage().getMinDaysFromStart() );
-
-                programStageInstance.setDueDate( dueDate );
-
-                programStageInstanceService.updateProgramStageInstance( programStageInstance );
+                if ( !programStageInstance.isCompleted()
+                    || programStageInstance.getStatus() != ProgramStageInstance.SKIPPED_STATUS )
+                {
+                    Date dueDate = DateUtils.getDateAfterAddition( format.parseDate( dateOfIncident ),
+                        programStageInstance.getProgramStage().getMinDaysFromStart() );
+
+                    programStageInstance.setDueDate( dueDate );
+
+                    programStageInstanceService.updateProgramStageInstance( programStageInstance );
+                }
             }
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java	2012-10-07 03:09:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java	2012-10-09 03:53:11 +0000
@@ -43,7 +43,6 @@
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramService;
-import org.hisp.dhis.system.util.ConversionUtils;
 
 /**
  * @author Abyot Asalefew Gizaw

=== 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-10-06 15:55:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-10-09 03:53:11 +0000
@@ -996,6 +996,8 @@
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
 		<property name="patientAuditService" ref="org.hisp.dhis.patient.PatientAuditService" />
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
+		<property name="selectedStateManager" ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 	</bean>
 
 	<!-- Comment -->

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2012-10-09 02:31:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2012-10-09 03:53:11 +0000
@@ -1253,6 +1253,43 @@
 		});
 }
 
+function saveSingleEnrollment(patientId, programId)
+{
+	jQuery.postJSON( "saveProgramEnrollment.action",
+		{
+			patientId: patientId,
+			programId: programId,
+			dateOfIncident: getCurrentDate(),
+			enrollmentDate: getCurrentDate()
+		}, 
+		function( json ) 
+		{    
+			var programInstanceId = json.programInstanceId;
+			var programStageInstanceId = json.activeProgramStageInstanceId;
+			var programStageName = json.activeProgramStageName;
+			var programInfor = getInnerHTML('infor_' + programId);
+			var dueDate = json.dueDate;
+			var type = jQuery('#enrollmentDiv [id=programId] option:selected').attr('programType');
+			
+			var activedRow = "<tr id='tr1_" + programInstanceId 
+							+ "' type='" + type +"'"
+							+ " programStageInstanceId='" + programStageInstanceId + "'>"
+							+ " <td id='td_" + programInstanceId + "'>"
+							+ " <a href='javascript:loadActiveProgramStageRecords(" + programInstanceId + "," + programStageInstanceId + ")'>"
+							+ "<span id='infor_" + programInstanceId + "' class='selected bold'>" 
+							+ programInfor + "</span></a></td>"
+							+ "</tr>";
+			
+			jQuery('#tr_' + programId ).remove();
+			
+			jQuery('#activeTB' ).append(activedRow);
+			jQuery('#enrollmentDiv').dialog("close");
+			saveIdentifierAndAttribute( patientId, programId,'identifierAndAttributeDiv' );
+			loadActiveProgramStageRecords( programInstanceId );
+			showSuccessMessage(i18n_enrol_success);
+		});
+}
+
 // ----------------------------------------------------------------
 // Program enrollmment && unenrollment
 // ----------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2012-10-05 08:12:39 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2012-10-09 03:53:11 +0000
@@ -120,11 +120,13 @@
 														<a><span id='infor_$programInstance.id'>$programInstance.program.name ($format.formatDate($programInstance.enrollmentDate))</span></a>
 													</td>
 												</tr>
+												#if($programInstance.program.type==1)
 												<tr>
 													<td id='tr2_$programInstance.id' onclick='javascript:loadActiveProgramStageRecords("$programInstance.id", "$programStageInstance.id")' style='cursor:pointer;'>
 														<a>>> $programStageInstance.programStage.name ($format.formatDate($programStageInstance.dueDate))</a>
 													</td>
 												</tr>
+												#end
 											#set($flag = 'true')
 											#end
 										#end
@@ -136,10 +138,22 @@
 												<a><span id='infor_$programInstance.id'>$programInstance.program.name ($format.formatDate($programInstance.enrollmentDate))</span></a>
 											</td>
 										</tr>
+										#end
+									#end
+									#foreach($program in $singlePrograms)
+										<tr id='tr_$program.id' name='tr_$program.id' style='cursor:pointer;'
+											onclick='javascript:saveSingleEnrollment("$patient.id","$program.id")' >
+											<td>
+												<a><span id='infor_$program.id'></span></a>
+												<script>
+													var infor = "$program.name" + " (" + getCurrentDate() + ")";
+													setInnerHTML("infor_$program.id", infor);
+												</script>
+											</td>
+										</tr>
 										<tr style='cursor:pointer;'>
 											<td id='tr2_$programInstance.id'></td>
 										</tr>
-										#end
 									#end
 								</table>
 							</div>