← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12226: add getAll(ProgramInstance, ProgramStage) method to programStageInstanceStore/Service, useful for...

 

------------------------------------------------------------
revno: 12226
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-24 11:31:28 +0200
message:
  add getAll(ProgramInstance, ProgramStage) method to programStageInstanceStore/Service, useful for cases where you have repeatable events (which means multiple PSIs for same combo)
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


--
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-09-18 06:54:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-09-24 09:31:28 +0000
@@ -28,11 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -43,6 +38,11 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.sms.outbound.OutboundSms;
 
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Abyot Asalefew
  * @version $Id$
@@ -63,6 +63,8 @@
 
     ProgramStageInstance getProgramStageInstance( ProgramInstance programInstance, ProgramStage programStage );
 
+    Collection<ProgramStageInstance> getProgramStageInstances( ProgramInstance programInstance, ProgramStage programStage );
+
     Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage );
 
     Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage,
@@ -91,12 +93,12 @@
     /**
      * 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 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 (<code>true</code>
-     *        ) or uncompleted (<code>false</code>) instances.
+     *                  ) or uncompleted (<code>false</code>) instances.
      * @return
      */
     List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, 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-09-18 06:54:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2013-09-24 09:31:28 +0000
@@ -55,6 +55,8 @@
 
     ProgramStageInstance get( ProgramInstance programInstance, ProgramStage programStage );
 
+    Collection<ProgramStageInstance> getAll( ProgramInstance programInstance, ProgramStage programStage );
+
     Collection<ProgramStageInstance> get( ProgramStage programStage );
 
     Collection<ProgramStageInstance> get( Date dueDate );

=== 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-09-23 11:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2013-09-24 09:31:28 +0000
@@ -166,6 +166,12 @@
         return programStageInstanceStore.get( programInstance, programStage );
     }
 
+    @Override
+    public Collection<ProgramStageInstance> getProgramStageInstances( ProgramInstance programInstance, ProgramStage programStage )
+    {
+        return programStageInstanceStore.getAll( programInstance, programStage );
+    }
+
     public Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage )
     {
         return programStageInstanceStore.get( programStage );

=== 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-09-18 06:54:48 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-09-24 09:31:28 +0000
@@ -155,7 +155,7 @@
     // Implemented methods
     // -------------------------------------------------------------------------
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public ProgramStageInstance get( ProgramInstance programInstance, ProgramStage programStage )
     {
         List<ProgramStageInstance> list = new ArrayList<ProgramStageInstance>( getCriteria(
@@ -165,13 +165,22 @@
         return list.isEmpty() ? null : list.get( list.size() - 1 );
     }
 
+    @SuppressWarnings( "unchecked" )
+    public Collection<ProgramStageInstance> getAll( ProgramInstance programInstance, ProgramStage programStage )
+    {
+        Criteria criteria = getCriteria( Restrictions.eq( "programInstance", programInstance ), Restrictions.eq( "programStage", programStage ) )
+            .addOrder( Order.asc( "id" ) );
+
+        return criteria.list();
+    }
+
     @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( ProgramStage programStage )
     {
         return getCriteria( Restrictions.eq( "programStage", programStage ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Collection<ProgramInstance> programInstances )
     {
         return getCriteria( Restrictions.in( "programInstance", programInstances ) ).list();