=== 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-11-04 03:13:27 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-11-04 06:00:38 +0000 @@ -112,49 +112,6 @@ ProgramStage programStage ); /** - * Retrieve an event list on a program stage - * - * @param programStage ProgramStage - * - * @return ProgramStageInstance - */ - Collection getProgramStageInstances( ProgramStage programStage ); - - /** - * Retrieve an event list on program stage by an orgunit - * - * @param programStage ProgramStage - * @param organisationUnit OrganisationUnit - * - * @return ProgramStageInstance list - */ - Collection getProgramStageInstances( ProgramStage programStage, - OrganisationUnit organisationUnit ); - - /** - * Retrieve an event list on program stage by an orgunit in a due date - * period - * - * @param programStage ProgramStage - * @param organisationUnit OrganisationUnit - * @param after Optional date the instance should be on or after. - * @param before Optional date the instance should be on or before. - * - * @return ProgramStageInstance list - */ - Collection getProgramStageInstances( ProgramStage programStage, - OrganisationUnit organisationUnit, Date after, Date before ); - - /** - * Retrieve an event list on program instance list - * - * @param programInstances ProgramInstance list - * - * @return ProgramStageInstance list - */ - Collection getProgramStageInstances( Collection programInstances ); - - /** * Retrieve an event list on program instance list with a certain status * * @param programInstances ProgramInstance list @@ -167,54 +124,6 @@ boolean completed ); /** - * Retrieve an event list on due-date - * - * @param dueDate Due date - * - * @return ProgramStageInstance list - */ - Collection getProgramStageInstances( Date dueDate ); - - /** - * Retrieve an event list by status on due date - * - * @param dueDate Due date - * @param completed Optional flag to only get completed (true ) - * or uncompleted (false) instances. - * - * @return ProgramStageInstance list - */ - Collection getProgramStageInstances( Date dueDate, Boolean completed ); - - /** - * Retrieve an event list in a period - * - * @param after - Optional date the instance should be on or after. - * @param before - optional date the instance should be on or before. - * - * @param ProgramStageInstance list - */ - Collection getProgramStageInstances( Date after, Date before ); - - /** - * Retrieve an event list by complete status in a period - * - * @param after Optional date the instance should be on or after. - * @param before Optional date the instance should be on or before. - * @param completed Optional flag to only get completed (true ) - * or uncompleted (false) instances. - */ - Collection getProgramStageInstances( Date startDate, Date endDate, Boolean completed ); - - /** - * Returns all {@link ProgramStageInstance}. - * - * @return a collection of all event, or an empty collection if there are no - * ProgramStageInstances. - */ - Collection getAllProgramStageInstances(); - - /** * Get statuses of events * * @param programStageInstances ProgramStageInstance list @@ -224,19 +133,6 @@ Map statusProgramStageInstances( Collection programStageInstances ); /** - * Get all {@link ProgramStageInstance program stage instances} for unit, - * optionally filtering by date or completed. - * - * @param unit - the unit to get instances for. - * @param after - optional date the instance should be on or after. - * @param before - optional date the instance should be on or before. - * @param completed - optional flag to only get completed (true - * ) or uncompleted (false) instances. - * @return - */ - List get( OrganisationUnit unit, Date after, Date before, Boolean completed ); - - /** * Get all events by patient, optionally filtering by completed. * * @param patient Patient @@ -313,10 +209,6 @@ List getStatisticalProgramStageDetailsReport( ProgramStage programStage, Collection orgunitIds, Date startDate, Date endDate, int status, Integer max, Integer min ); - // ------------------------------------------------------------------------- - // Statistical - // ------------------------------------------------------------------------- - /** * Get events of a program by report date * @@ -358,7 +250,7 @@ * @return A number */ int averageNumberCompletedProgramInstance( Program program, Collection orgunitIds, Date startDate, - Date endDate, Integer status ); + Date endDate, int status ); /** * Get ids of orgunits where events happened in a period @@ -441,4 +333,5 @@ */ void createProgramStageInstance( Patient patient, Program program, Date executionDate, OrganisationUnit organisationUnit ); + } === 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-11-04 03:13:27 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2013-11-04 06:00:38 +0000 @@ -79,55 +79,6 @@ Collection get( ProgramStage programStage ); /** - * Retrieve an event list on due-date - * - * @param dueDate Due date - * - * @return ProgramStageInstance list - */ - Collection get( Date dueDate ); - - /** - * Retrieve an event list by status on due date - * - * @param dueDate Due date - * @param completed Optional flag to only get completed (true ) - * or uncompleted (false) instances. - * - * @return ProgramStageInstance list - */ - Collection get( Date dueDate, Boolean completed ); - - /** - * Retrieve an event list in a due date period - * - * @param after - Optional date the instance should be on or after. - * @param before - optional date the instance should be on or before. - * - * @param ProgramStageInstance list - */ - Collection get( Date startDate, Date endDate ); - - /** - * Retrieve an event list by complete status in a period - * - * @param after Optional date the instance should be on or after. - * @param before Optional date the instance should be on or before. - * @param completed Optional flag to only get completed (true ) - * or uncompleted (false) instances. - */ - Collection get( Date startDate, Date endDate, Boolean completed ); - - /** - * Retrieve an event list on program instance list - * - * @param programInstances ProgramInstance list - * - * @return ProgramStageInstance list - */ - Collection get( Collection programInstances ); - - /** * Retrieve an event list on program instance list with a certain status * * @param programInstances ProgramInstance list @@ -139,18 +90,6 @@ Collection get( Collection programInstances, boolean completed ); /** - * Get all {@link ProgramStageInstance program stage instances} for unit. - * - * @param unit - the unit to get instances for. - * @param after - optional date the instance should be on or after. - * @param before - optional date the instance should be on or before. - * @param completed - optional flag to only get completed (true - * ) or uncompleted (false) instances. - * @return - */ - List get( OrganisationUnit unit, Date after, Date before, Boolean completed ); - - /** * Get all events by patient, optionally filtering by completed. * * @param patient Patient @@ -163,30 +102,6 @@ List get( Patient patient, Boolean completed ); /** - * Retrieve an event list on program stage by an orgunit - * - * @param programStage ProgramStage - * @param organisationUnit OrganisationUnit - * - * @return ProgramStageInstance list - */ - List get( ProgramStage programStage, OrganisationUnit orgunit ); - - /** - * Retrieve an event list on program stage by an orgunit in a due date - * period - * - * @param programStage ProgramStage - * @param organisationUnit OrganisationUnit - * @param after Optional date the instance should be on or after. - * @param before Optional date the instance should be on or before. - * - * @return ProgramStageInstance list - */ - List get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate, Date endDate, - int min, int max ); - - /** * Remove events without any data values * * @param programStage Empty events belong to this program stage are removed @@ -306,8 +221,8 @@ * LATE_VISIT_STATUS * @return A number */ - int averageNumberCompleted( Program program, Collection orgunitIds, Date startDate, Date endDate, - Integer status ); + int averageNumberCompleted( Program program, Collection orgunitIds, Date after, Date before, + int status ); /** * Get ids of orgunits where events happened in a period === 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-11-04 00:01:39 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-11-04 06:00:38 +0000 @@ -124,32 +124,32 @@ // Implementation methods // ------------------------------------------------------------------------- + @Override public int addProgramStageInstance( ProgramStageInstance programStageInstance ) { programStageInstance.setAutoFields(); return programStageInstanceStore.save( programStageInstance ); } + @Override public void deleteProgramStageInstance( ProgramStageInstance programStageInstance ) { programStageInstanceStore.delete( programStageInstance ); } - public Collection getAllProgramStageInstances() - { - return programStageInstanceStore.getAll(); - } - + @Override public ProgramStageInstance getProgramStageInstance( int id ) { return programStageInstanceStore.get( id ); } + @Override public ProgramStageInstance getProgramStageInstance( String uid ) { return programStageInstanceStore.getByUid( uid ); } + @Override public ProgramStageInstance getProgramStageInstance( ProgramInstance programInstance, ProgramStage programStage ) { return programStageInstanceStore.get( programInstance, programStage ); @@ -162,31 +162,14 @@ return programStageInstanceStore.getAll( programInstance, programStage ); } - public Collection getProgramStageInstances( ProgramStage programStage ) - { - return programStageInstanceStore.get( programStage ); - } - - @Override - public Collection getProgramStageInstances( ProgramStage programStage, - OrganisationUnit organisationUnit ) - { - return programStageInstanceStore.get( programStage, organisationUnit ); - } - - @Override - public Collection getProgramStageInstances( ProgramStage programStage, - OrganisationUnit organisationUnit, Date start, Date end ) - { - return programStageInstanceStore.get( programStage, organisationUnit, start, end, 0, Integer.MAX_VALUE ); - } - + @Override public void updateProgramStageInstance( ProgramStageInstance programStageInstance ) { programStageInstance.setAutoFields(); programStageInstanceStore.update( programStageInstance ); } + @Override public Map statusProgramStageInstances( Collection programStageInstances ) { Map colorMap = new HashMap(); @@ -199,47 +182,20 @@ return colorMap; } - public Collection getProgramStageInstances( Collection programInstances ) - { - return programStageInstanceStore.get( programInstances ); - } - + @Override public Collection getProgramStageInstances( Collection programInstances, boolean completed ) { return programStageInstanceStore.get( programInstances, completed ); } - public Collection getProgramStageInstances( Date dueDate ) - { - return programStageInstanceStore.get( dueDate ); - } - - public Collection getProgramStageInstances( Date dueDate, Boolean completed ) - { - return programStageInstanceStore.get( dueDate, completed ); - } - - public Collection getProgramStageInstances( Date startDate, Date endDate ) - { - return programStageInstanceStore.get( startDate, endDate ); - } - - public Collection getProgramStageInstances( Date startDate, Date endDate, Boolean completed ) - { - return programStageInstanceStore.get( startDate, endDate, completed ); - } - - public List get( OrganisationUnit unit, Date after, Date before, Boolean completed ) - { - return programStageInstanceStore.get( unit, after, before, completed ); - } - + @Override public List getProgramStageInstances( Patient patient, Boolean completed ) { return programStageInstanceStore.get( patient, completed ); } + @Override public List getProgramStageInstancesReport( ProgramInstance programInstance, I18nFormat format, I18n i18n ) { List grids = new ArrayList(); @@ -309,6 +265,7 @@ return grids; } + @Override public void removeEmptyEvents( ProgramStage programStage, OrganisationUnit organisationUnit ) { programStageInstanceStore.removeEmptyEvents( programStage, organisationUnit ); @@ -320,29 +277,19 @@ programStageInstanceStore.update( programStageInstanceIds, outboundSms ); } + @Override public Collection getSendMesssageEvents() { return programStageInstanceStore.getSendMesssageEvents(); } + @Override public Collection getProgramStageInstances( Program program, Collection orgunitIds, Date startDate, Date endDate, Boolean completed ) { return programStageInstanceStore.get( program, orgunitIds, startDate, endDate, completed ); } - public int getProgramStageInstanceCount( Program program, Collection orgunitIds, Date startDate, - Date endDate, Boolean completed ) - { - return programStageInstanceStore.count( program, orgunitIds, startDate, endDate, completed ); - } - - public int getProgramStageInstanceCount( ProgramStage programStage, Collection orgunitIds, Date startDate, - Date endDate, Boolean completed ) - { - return programStageInstanceStore.count( programStage, orgunitIds, startDate, endDate, completed ); - } - @Override public Grid getStatisticalReport( Program program, Collection orgunitIds, Date startDate, Date endDate, I18n i18n, I18nFormat format ) @@ -465,16 +412,14 @@ grid.addValue( programStage.getDisplayName() ); // Visits scheduled (All) - - int totalAll = this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate, null ); + int totalAll = programStageInstanceStore.count( programStage, orgunitIds, startDate, endDate, null ); grid.addValue( totalAll ); // Visits done (#) = Incomplete + Complete stages. - - int totalCompletedEvent = this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate, + int totalCompletedEvent = programStageInstanceStore.count( programStage, orgunitIds, startDate, endDate, true ); int totalVisit = totalCompletedEvent - + this.getProgramStageInstanceCount( programStage, orgunitIds, startDate, endDate, false ); + + programStageInstanceStore.count( programStage, orgunitIds, startDate, endDate, false ); grid.addValue( totalVisit ); // Visits done (%) @@ -516,6 +461,7 @@ return grid; } + @Override public List getStatisticalProgramStageDetailsReport( ProgramStage programStage, Collection orgunitIds, Date startDate, Date endDate, int status, Integer min, Integer max ) { @@ -532,7 +478,7 @@ @Override public int averageNumberCompletedProgramInstance( Program program, Collection orgunitIds, Date startDate, - Date endDate, Integer status ) + Date endDate, int status ) { return programStageInstanceStore.averageNumberCompleted( program, orgunitIds, startDate, endDate, status ); } @@ -755,4 +701,5 @@ return outboundSms; } + } \ No newline at end of file === 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-11-04 00:01:39 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-11-04 06:00:38 +0000 @@ -36,7 +36,6 @@ import java.util.List; import org.hibernate.Criteria; -import org.hibernate.Query; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; @@ -71,7 +70,7 @@ // ------------------------------------------------------------------------- // Dependency // ------------------------------------------------------------------------- - + private ProgramInstanceService programInstanceService; public void setProgramInstanceService( ProgramInstanceService programInstanceService ) @@ -83,6 +82,7 @@ // Implemented methods // ------------------------------------------------------------------------- + @Override @SuppressWarnings( "unchecked" ) public ProgramStageInstance get( ProgramInstance programInstance, ProgramStage programStage ) { @@ -93,6 +93,7 @@ return list.isEmpty() ? null : list.get( list.size() - 1 ); } + @Override @SuppressWarnings( "unchecked" ) public Collection getAll( ProgramInstance programInstance, ProgramStage programStage ) { @@ -102,18 +103,14 @@ return criteria.list(); } + @Override @SuppressWarnings( "unchecked" ) public Collection get( ProgramStage programStage ) { return getCriteria( Restrictions.eq( "programStage", programStage ) ).list(); } - @SuppressWarnings( "unchecked" ) - public Collection get( Collection programInstances ) - { - return getCriteria( Restrictions.in( "programInstance", programInstances ) ).list(); - } - + @Override @SuppressWarnings( "unchecked" ) public Collection get( Collection programInstances, boolean completed ) { @@ -121,71 +118,7 @@ Restrictions.eq( "completed", completed ) ).list(); } - @SuppressWarnings( "unchecked" ) - public Collection get( Date dueDate ) - { - return getCriteria( Restrictions.eq( "dueDate", dueDate ) ).list(); - } - - @SuppressWarnings( "unchecked" ) - public Collection get( Date dueDate, Boolean completed ) - { - return getCriteria( Restrictions.eq( "dueDate", dueDate ), Restrictions.eq( "completed", completed ) ).list(); - } - - @SuppressWarnings( "unchecked" ) - public Collection get( Date startDate, Date endDate ) - { - return (getCriteria( Restrictions.ge( "dueDate", startDate ), Restrictions.le( "dueDate", endDate ) )).list(); - } - - @SuppressWarnings( "unchecked" ) - public Collection get( Date startDate, Date endDate, Boolean completed ) - { - return (getCriteria( Restrictions.ge( "dueDate", startDate ), Restrictions.le( "dueDate", endDate ), - Restrictions.eq( "completed", completed ) )).list(); - } - - @SuppressWarnings( "unchecked" ) - public List get( OrganisationUnit unit, Date after, Date before, Boolean completed ) - { - String hql = "from ProgramStageInstance psi where psi.organisationUnit = :unit"; - - if ( after != null ) - { - hql += " and dueDate >= :after"; - } - - if ( before != null ) - { - hql += " and dueDate <= :before"; - } - - if ( completed != null ) - { - hql += " and completed = :completed"; - } - - Query q = getQuery( hql ).setEntity( "unit", unit ); - - if ( after != null ) - { - q.setDate( "after", after ); - } - - if ( before != null ) - { - q.setDate( "before", before ); - } - - if ( completed != null ) - { - q.setBoolean( "completed", completed ); - } - - return q.list(); - } - + @Override @SuppressWarnings( "unchecked" ) public List get( Patient patient, Boolean completed ) { @@ -194,23 +127,8 @@ return getQuery( hql ).setEntity( "patient", patient ).setBoolean( "completed", completed ).list(); } + @Override - @SuppressWarnings( "unchecked" ) - public List get( ProgramStage programStage, OrganisationUnit organisationUnit ) - { - return getCriteria( Restrictions.eq( "programStage", programStage ), - Restrictions.eq( "organisationUnit", organisationUnit ) ).list(); - } - - @SuppressWarnings( "unchecked" ) - public List get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate, - Date endDate, int min, int max ) - { - return getCriteria( Restrictions.eq( "programStage", programStage ), - Restrictions.eq( "organisationUnit", orgunit ), Restrictions.between( "dueDate", startDate, endDate ) ) - .setFirstResult( min ).setMaxResults( max ).list(); - } - public void removeEmptyEvents( ProgramStage programStage, OrganisationUnit organisationUnit ) { String sql = "delete from programstageinstance where programstageid=" + programStage.getId() @@ -242,6 +160,7 @@ } } + @Override public Collection getSendMesssageEvents() { String sql = " ( " + sendMessageToPatientSql() + " ) "; @@ -296,6 +215,7 @@ return schedulingProgramObjects; } + @Override public int getStatisticalProgramStageReport( ProgramStage programStage, Collection orgunitIds, Date startDate, Date endDate, int status ) { @@ -306,6 +226,7 @@ return rs != null ? rs.intValue() : 0; } + @Override @SuppressWarnings( "unchecked" ) public List getStatisticalProgramStageDetailsReport( ProgramStage programStage, Collection orgunitIds, Date startDate, Date endDate, int status, Integer min, Integer max ) @@ -321,6 +242,7 @@ return criteria.list(); } + @Override public int getOverDueCount( ProgramStage programStage, Collection orgunitIds, Date startDate, Date endDate ) { Calendar yesterday = Calendar.getInstance(); @@ -349,6 +271,7 @@ return rs != null ? rs.intValue() : 0; } + @Override @SuppressWarnings( "unchecked" ) public Collection get( Program program, Collection orgunitIds, Date startDate, Date endDate, Boolean completed ) @@ -356,6 +279,7 @@ return getCriteria( program, orgunitIds, startDate, endDate, completed ).list(); } + @Override public int count( Program program, Collection orgunitIds, Date startDate, Date endDate, Boolean completed ) { Number rs = (Number) getCriteria( program, orgunitIds, startDate, endDate, completed ).setProjection( @@ -364,6 +288,7 @@ return rs != null ? rs.intValue() : 0; } + @Override public int count( ProgramStage programStage, Collection orgunitIds, Date startDate, Date endDate, Boolean completed ) { @@ -373,6 +298,7 @@ return rs != null ? rs.intValue() : 0; } + @Override public Grid getCompleteness( Collection orgunitIds, Program program, String startDate, String endDate, I18n i18n ) { @@ -539,11 +465,12 @@ return criteria; } - public int averageNumberCompleted( Program program, Collection orgunitIds, Date startDate, Date endDate, - Integer status ) + @Override + public int averageNumberCompleted( Program program, Collection orgunitIds, Date after, Date before, + int status ) { Collection programInstances = programInstanceService.getProgramInstancesByStatus( - ProgramInstance.STATUS_COMPLETED, program, orgunitIds, startDate, endDate ); + ProgramInstance.STATUS_COMPLETED, program, orgunitIds, after, before ); Criteria criteria = getCriteria(); criteria.createAlias( "programInstance", "programInstance" ); criteria.createAlias( "programStage", "programStage" ); @@ -551,7 +478,7 @@ criteria.add( Restrictions.eq( "programInstance.program", program ) ); criteria.add( Restrictions.eq( "programInstance.status", status ) ); criteria.add( Restrictions.in( "organisationUnit.id", orgunitIds ) ); - criteria.add( Restrictions.between( "programInstance.endDate", startDate, endDate ) ); + criteria.add( Restrictions.between( "programInstance.endDate", after, before ) ); criteria.add( Restrictions.eq( "completed", true ) ); if ( programInstances != null && programInstances.size() > 0 ) {