← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9313: Add statistical report in patient module (DONE).

 

------------------------------------------------------------
revno: 9313
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-14 14:29:29 +0700
message:
  Add statistical report in patient module (DONE).
removed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/statisticalProgramReport.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateStatisticalProgramReportAction.java
  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


--
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/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-12-13 08:48:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-12-14 07:29:29 +0000
@@ -86,9 +86,6 @@
      */
     List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, Boolean completed );
 
-   int getProgramInstancesCount( ProgramStage programStage, Collection<Integer> orgunitIds,
-        Date startDate, Date endDate );
-
     List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed );
 
     Grid getTabularReport( ProgramStage programStage, List<TabularReportColumn> columns,
@@ -105,4 +102,7 @@
     void updateProgramStageInstances( Collection<Integer> programStageInstances, OutboundSms outboundSms );
 
     Collection<SchedulingProgramObject> getSendMesssageEvents();
+    
+    Grid getStatisticalReport( Program program, Collection<Integer> orgunitIds,
+        Date startDate, Date endDate, I18n i18n, I18nFormat format );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2012-12-13 08:48:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2012-12-14 07:29:29 +0000
@@ -92,5 +92,7 @@
 
     Collection<SchedulingProgramObject> getSendMesssageEvents();
 
-    int getCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate, Date endDate);
+    int getStatisticalProgramStageReport( ProgramStage programStage, Collection<Integer> orgunitIds,
+        Date startDate, Date endDate, int status );
+    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-12-13 08:48:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-12-14 07:29:29 +0000
@@ -68,6 +68,13 @@
         this.programStageInstanceStore = programStageInstanceStore;
     }
 
+    private ProgramInstanceService programInstanceService;
+
+    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+    {
+        this.programInstanceService = programInstanceService;
+    }
+
     private PatientDataValueService patientDataValueService;
 
     public void setPatientDataValueService( PatientDataValueService patientDataValueService )
@@ -275,10 +282,54 @@
     }
 
     @Override
-    public int getProgramInstancesCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate,
-        Date endDate )
+    public Grid getStatisticalReport( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+        I18n i18n, I18nFormat format )
     {
-        return programStageInstanceStore.getCount( programStage, orgunitIds, startDate, endDate  );
+
+        Grid grid = new ListGrid();
+        grid.setTitle( program.getName() + " ( " + format.formatDate( startDate ) + " - " + format.formatDate( endDate )
+            + " )" );
+
+        int total = programInstanceService.countProgramInstances( program, orgunitIds, startDate, endDate );
+        grid.setSubtitle( i18n.getString( "total_result" ) + ": " + total );
+
+        grid.addHeader( new GridHeader( i18n.getString( "program_stage" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "completed" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "percent_completed" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "incomplete" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "percent_incomplete" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "Scheduled" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "percent_Scheduled" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "overdue" ), false, false ) );
+        grid.addHeader( new GridHeader( i18n.getString( "percent_overdue" ), false, false ) );
+
+        for ( ProgramStage programStage : program.getProgramStages() )
+        {
+            grid.addRow();
+            grid.addValue( programStage.getName() );
+
+            int completed = programStageInstanceStore.getStatisticalProgramStageReport( programStage, orgunitIds,
+                startDate, endDate, ProgramStageInstance.COMPLETED_STATUS );
+            grid.addValue( completed );
+            grid.addValue( (completed + 0.0) / total );
+
+            int incomplete = programStageInstanceStore.getStatisticalProgramStageReport( programStage, orgunitIds,
+                startDate, endDate, ProgramStageInstance.VISITED_STATUS );
+            grid.addValue( incomplete );
+            grid.addValue( (incomplete + 0.0) / total );
+
+            int Scheduled = programStageInstanceStore.getStatisticalProgramStageReport( programStage, orgunitIds,
+                startDate, endDate, ProgramStageInstance.FUTURE_VISIT_STATUS );
+            grid.addValue( Scheduled );
+            grid.addValue( (Scheduled + 0.0) / total );
+
+            int overdue = programStageInstanceStore.getStatisticalProgramStageReport( programStage, orgunitIds,
+                startDate, endDate, ProgramStageInstance.LATE_VISIT_STATUS );
+            grid.addValue( overdue );
+            grid.addValue( (overdue + 0.0) / total );
+        }
+
+        return grid;
     }
 
 }

=== 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	2012-12-13 08:48:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-12-14 07:29:29 +0000
@@ -344,16 +344,40 @@
         return schedulingProgramObjects;
     }
 
-    public int getCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate, Date endDate )
+    public int getStatisticalProgramStageReport( ProgramStage programStage, Collection<Integer> orgunitIds,
+        Date startDate, Date endDate, int status )
     {
         Criteria criteria = getCriteria( Restrictions.eq( "programStage", programStage ),
-            Restrictions.isNull( "programInstance.endDate" ),
-            Restrictions.between( "programInstance.enrollmentDate", startDate, endDate ) );
+            Restrictions.isNull( "programInstance.endDate" ) );
         criteria.createAlias( "programInstance", "programInstance" );
         criteria.createAlias( "programInstance.patient", "patient" );
         criteria.createAlias( "patient.organisationUnit", "regOrgunit" );
         criteria.add( Restrictions.in( "regOrgunit.id", orgunitIds ) );
-        
+
+        switch ( status )
+        {
+        case ProgramStageInstance.COMPLETED_STATUS:
+            criteria.add( Restrictions.eq( "completed", true ) );
+            criteria.add( Restrictions.between( "executionDate", startDate, endDate ) );
+            break;
+        case ProgramStageInstance.VISITED_STATUS:
+            criteria.add( Restrictions.eq( "completed", false ) );
+            criteria.add( Restrictions.between( "executionDate", startDate, endDate ) );
+            break;
+        case ProgramStageInstance.FUTURE_VISIT_STATUS:
+            criteria.add( Restrictions.between( "programInstance.enrollmentDate", startDate, endDate ) );
+            criteria.add( Restrictions.isNull( "executionDate" ) );
+            criteria.add( Restrictions.ge( "dueDate", new Date() ) );
+            break;
+        case ProgramStageInstance.LATE_VISIT_STATUS:
+            criteria.add( Restrictions.between( "programInstance.enrollmentDate", startDate, endDate ) );
+            criteria.add( Restrictions.isNull( "executionDate" ) );
+            criteria.add( Restrictions.lt( "dueDate", new Date() ) );
+            break;
+        default:
+            break;
+        }
+
         Number rs = (Number) criteria.setProjection( Projections.rowCount() ).uniqueResult();
 
         return rs != null ? rs.intValue() : 0;
@@ -501,4 +525,5 @@
 
         return sql;
     }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-11-16 03:50:03 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-12-14 07:29:29 +0000
@@ -188,6 +188,8 @@
 		class="org.hisp.dhis.program.DefaultProgramStageInstanceService">
 		<property name="programStageInstanceStore"
 			ref="org.hisp.dhis.program.ProgramStageInstanceStore" />
+		<property name="programInstanceService"
+			ref="org.hisp.dhis.program.ProgramInstanceService" />
 		<property name="patientDataValueService"
 			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
 		<property name="organisationUnitService"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateStatisticalProgramReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateStatisticalProgramReportAction.java	2012-12-14 05:49:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateStatisticalProgramReportAction.java	2012-12-14 07:29:29 +0000
@@ -34,6 +34,8 @@
 import java.util.HashSet;
 import java.util.Map;
 
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -49,10 +51,12 @@
 
 /**
  * @author Chau Thu Tran
- *
- * @version GenerateStatisticalProgramReportAction.java 11:13:25 AM Dec 14, 2012 $
+ * 
+ * @version GenerateStatisticalProgramReportAction.java 11:13:25 AM Dec 14, 2012
+ *          $
  */
-public class GenerateStatisticalProgramReportAction implements Action
+public class GenerateStatisticalProgramReportAction
+    implements Action
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -100,6 +104,13 @@
         this.format = format;
     }
 
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
     // -------------------------------------------------------------------------
     // Input/output
     // -------------------------------------------------------------------------
@@ -167,13 +178,13 @@
         return total;
     }
 
-    private Map<Integer, Integer> completedMap = new HashMap<Integer, Integer>();
+    private Grid grid;
 
-    public Map<Integer, Integer> getCompletedMap()
+    public Grid getGrid()
     {
-        return completedMap;
+        return grid;
     }
-    
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -213,21 +224,9 @@
 
         if ( orgunitIds.size() > 0 )
         {
-            // ---------------------------------------------------------------------
-            // Program instances for the selected program
-            // ---------------------------------------------------------------------
-
-            total = programInstanceService.countProgramInstances( program, orgunitIds, sDate, eDate );
-
-            for ( ProgramStage programStage : program.getProgramStages() )
-            {
-                int completedNo = programStageInstanceService.getProgramInstancesCount( programStage, orgunitIds,
-                    sDate, eDate );
-                completedMap.put( programStage.getId(), completedNo );
-            }
+            grid = programStageInstanceService.getStatisticalReport( program, orgunitIds, sDate, eDate, i18n, format );
         }
 
         return SUCCESS;
     }
 }
-

=== 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	2012-12-14 05:49:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-12-14 07:29:29 +0000
@@ -480,4 +480,8 @@
 events_completed = Events completed
 statistical_program = Statistical Program
 statistical_program_report = Statistical program report
-intro_statistical_program = Statistical reports on program performance, e.g. drop-out rates, how many completed every month/year - counts/percentages etc 
\ No newline at end of file
+intro_statistical_program = Statistical reports on program performance, e.g. drop-out rates, how many completed every month/year - counts/percentages etc
+percent_completed = Percent Completed
+percent_incomplete = Percent Incomplete
+percent_Scheduled = Percent scheduled
+percent_overdue = Percent Overdue
\ 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	2012-12-14 05:49:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2012-12-14 07:29:29 +0000
@@ -346,8 +346,7 @@
 		<action name="generateStatisticalProgramReport"
 			class="org.hisp.dhis.caseentry.action.report.GenerateStatisticalProgramReportAction">
 			<result name="success" type="velocity">/content.vm</result>
-			<param name="page">/dhis-web-caseentry/statisticalProgramReport.vm</param>
-			<param name="javascripts">javascript/commons.js,javascript/statisticalReport.js</param>
+			<param name="page">/dhis-web-commons/ajax/htmlGrid.vm</param>
 			<param name="requiredAuthorities">F_GENERATE_STATISTICAL_PROGRAM_REPORT</param>
 		</action>
 		

=== removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/statisticalProgramReport.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/statisticalProgramReport.vm	2012-12-14 05:49:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/statisticalProgramReport.vm	1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-<h3>$encoder.htmlEncode($program.name) ( <span id="dateLbl"></span> )</h3>
-<h5>
-	$i18n.getString( "total_result" ): #if($!total) $total #else 0 #end
-</h5>
-
-<script>
-	setInnerHTML("dateLbl", getFieldValue("startDate") + " - " + getFieldValue("endDate") );
-</script>
-
-<table class='listTable gridTable'>
-	
-	#if($total>0)
-		<thead>
-			<tr> 
-				<th style="text-align:left">$i18n.getString( "program_stage")</th>
-				<th>$i18n.getString("events_completed")</th>
-				<th>$i18n.getString("percent")</th>
-			</tr>
-		</thead>
-		<tbody>
-			#set( $mark = false ) 
-			#foreach($programStage in $program.programStages)
-				#set($completeEventsNo = $completedMap.get($programStage.id) )
-			<tr #alternate( $mark )>
-				<td style="text-align:left">$encoder.htmlEncode($programStage.name)</td>
-				<td>$completeEventsNo</td>
-				<td id="rate$programStage.id"></td>
-				<script>
-					var rate = ($completeEventsNo/$total * 100);
-					if(!isInt( rate )){
-						rate = rate.toFixed(2);
-					}
-					setInnerHTML("rate$programStage.id", rate + "%");
-				</script>
-			</tr>
-			#set( $mark = !$mark )
-			#end
-		</tbody>
-	#end
-</table>