dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21425
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10143: Fix bug for Program Statistics.
------------------------------------------------------------
revno: 10143
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-03-11 23:07:20 +0700
message:
Fix bug for Program Statistics.
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/HibernateProgramInstanceStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.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
=== 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 2013-03-08 08:47:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-03-11 16:07:20 +0000
@@ -133,4 +133,5 @@
int getOverDueEventCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate, Date endDate );
+ int averageNumberCompletedProgramInstance( Program program , Collection<Integer> orgunitIds, Date startDate, Date endDate, Boolean completed );
}
=== 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 2013-03-08 08:47:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2013-03-11 16:07:20 +0000
@@ -127,4 +127,7 @@
int getOverDueCount( ProgramStage programStage, Collection<Integer> orgunitIds, Date startDate, Date endDate );
+ int averageNumberCompleted( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+ Boolean completed );
+
}
=== 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 2013-03-09 05:42:33 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-03-11 16:07:20 +0000
@@ -363,16 +363,10 @@
// Average number of stages for complete programs
- int stageCount = program.getProgramStages().size();
- int stageCompleted = getProgramStageInstanceCount( program, orgunitIds, startDate, endDate, true );
- double average = 0.0;
- if ( total != 0 && stageCompleted != 0 )
- {
- average = stageCompleted * 100 / (stageCount * total);
- }
+ int stageCompleted = averageNumberCompletedProgramInstance( program, orgunitIds, startDate, endDate, true );
grid.addRow();
grid.addValue( i18n.getString( "average_number_of_stages_for_complete_programs" ) );
- grid.addValue( format.formatValue( average ) + "%" );
+ grid.addValue( stageCompleted );
grid.addValue( "" );
grid.addValue( "" );
grid.addValue( "" );
@@ -417,7 +411,7 @@
grid.addValue( i18n.getString( "visits_overdue_percent" ) );
// Add values for stage details
-
+
for ( ProgramStage programStage : program.getProgramStages() )
{
grid.addRow();
@@ -425,22 +419,23 @@
// Visits scheduled (All)
- int totalAll = this.getProgramStageInstanceCount( program, orgunitIds, startDate, endDate, null );
- grid.addValue( total );
+ int totalAll = this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate, null );
+ grid.addValue( totalAll );
// Visits done (#) = Incomplete + Complete stages.
int totalCompletedEvent = this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate,
true );
- int totalVisit = this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate, false );
- grid.addValue( totalCompletedEvent + totalVisit );
+ int totalVisit = totalCompletedEvent
+ + this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate, false );
+ grid.addValue( totalVisit );
// Visits done (%)
double percent = 0.0;
if ( totalAll != 0 )
{
- percent = (totalCompletedEvent + totalVisit + 0.0) * 100 / totalAll;
+ percent = (totalVisit + 0.0) * 100 / totalAll;
}
grid.addValue( format.formatValue( percent ) + "%" );
@@ -470,7 +465,7 @@
}
grid.addValue( format.formatValue( percent ) + "%" );
}
-
+
return grid;
}
@@ -568,4 +563,10 @@
return programStageInstanceStore.getOverDueCount( programStage, orgunitIds, startDate, endDate );
}
+ @Override
+ public int averageNumberCompletedProgramInstance( Program program, Collection<Integer> orgunitIds, Date startDate,
+ Date endDate, Boolean completed )
+ {
+ return programStageInstanceStore.averageNumberCompleted( program, orgunitIds, startDate, endDate, completed );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-03-08 08:47:35 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-03-11 16:07:20 +0000
@@ -134,10 +134,13 @@
public Collection<ProgramInstance> get( Program program, Collection<Integer> orgunitIds, Date startDate,
Date endDate, int min, int max )
{
- return getCriteria( Restrictions.eq( "program", program ), Restrictions.isNull( "endDate" ),
- Restrictions.ge( "enrollmentDate", startDate ), Restrictions.le( "enrollmentDate", endDate ) )
- .createAlias( "patient", "patient" ).createAlias( "patient.organisationUnit", "organisationUnit" )
- .add( Restrictions.in( "organisationUnit.id", orgunitIds ) ).addOrder( Order.asc( "patient.id" ) )
+ return getCriteria( Restrictions.eq( "program", program ),
+ Restrictions.ge( "enrollmentDate", startDate ),
+ Restrictions.le( "enrollmentDate", endDate ) )
+ .createAlias( "patient", "patient" )
+ .createAlias( "patient.organisationUnit", "organisationUnit" )
+ .add( Restrictions.in( "organisationUnit.id", orgunitIds ) )
+ .addOrder( Order.asc( "patient.id" ) )
.setFirstResult( min ).setMaxResults( max ).list();
}
=== 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 2013-03-11 07:15:42 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-03-11 16:07:20 +0000
@@ -804,7 +804,24 @@
if ( completed == null )
{
- criteria.add( Restrictions.between( "dueDate", startDate, endDate ) );
+ criteria.createAlias( "programInstance.patient", "patient" );
+ criteria.createAlias( "patient.organisationUnit", "regOrgunit" );
+ criteria.add( Restrictions.or(
+ Restrictions.and( Restrictions.eq( "completed", true ),
+ Restrictions.between( "executionDate", startDate, endDate ),
+ Restrictions.in( "organisationUnit.id", orgunitIds ) ),
+ Restrictions.and( Restrictions.eq( "completed", false ),
+ Restrictions.isNotNull( "executionDate" ),
+ Restrictions.between( "executionDate", startDate, endDate ),
+ Restrictions.in( "organisationUnit.id", orgunitIds ) ),
+ Restrictions.and( Restrictions.eq( "completed", false ),
+ Restrictions.isNull( "executionDate" ),
+ Restrictions.between( "dueDate", startDate, endDate ),
+ Restrictions.in( "regOrgunit.id", orgunitIds ) ),
+ Restrictions.and( Restrictions.eq( "status", ProgramStageInstance.SKIPPED_STATUS ),
+ Restrictions.between( "dueDate", startDate, endDate ),
+ Restrictions.in( "regOrgunit.id", orgunitIds ) )
+ ) );
}
else
{
@@ -1877,6 +1894,23 @@
return description;
}
+ public int averageNumberCompleted( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+ Boolean completed )
+ {
+ Criteria criteria = getCriteria();
+ criteria.createAlias( "programInstance", "programInstance" );
+ criteria.createAlias( "programStage", "programStage" );
+ criteria.createAlias( "programInstance.patient", "patient" );
+ criteria.add( Restrictions.eq( "programInstance.program", program ) );
+ criteria.add( Restrictions.eq( "programInstance.completed", completed ) );
+ criteria.add( Restrictions.in( "organisationUnit.id", orgunitIds ) );
+ criteria.add( Restrictions.between( "executionDate", startDate, endDate ) );
+ criteria.add( Restrictions.eq( "completed", true ) );
+
+ Number rs = (Number) criteria.setProjection( Projections.rowCount() ).uniqueResult();
+ return rs != null ? rs.intValue() : 0;
+ }
+
// ---------------------------------------------------------------------
// Get orgunitIds
// ---------------------------------------------------------------------