← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12848: re-sort events when create new repeatable event

 

------------------------------------------------------------
revno: 12848
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-11-01 16:56:52 +0700
message:
  re-sort events when create new repeatable event
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.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-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2013-10-31 04:12:32 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2013-11-01 09:56:52 +0000
@@ -91,6 +91,7 @@
 import org.hisp.dhis.program.ProgramStageSection;
 import org.hisp.dhis.program.ProgramStageSectionService;
 import org.hisp.dhis.program.ProgramStageService;
+import org.hisp.dhis.program.comparator.ProgramStageInstanceVisitDateComparator;
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
@@ -2093,7 +2094,7 @@
         
         ProgramStageInstance oldProgramStageIntance = programStageInstanceService.getProgramStageInstance( Integer.valueOf( mobileProgramStageId ) );
         
-        ProgramInstance programInstance = oldProgramStageIntance.getProgramInstance(); 
+        ProgramInstance programInstance = oldProgramStageIntance.getProgramInstance();
         
         ProgramStageInstance newProgramStageInstance = new ProgramStageInstance( programInstance, oldProgramStageIntance.getProgramStage() );
         
@@ -2103,6 +2104,13 @@
         
         programInstance.getProgramStageInstances().add( newProgramStageInstance );
         
+        List<ProgramStageInstance> proStageInstanceList = new ArrayList<ProgramStageInstance>( programInstance.getProgramStageInstances() );
+        
+        Collections.sort( proStageInstanceList, new ProgramStageInstanceVisitDateComparator() );
+        
+        programInstance.getProgramStageInstances().removeAll( proStageInstanceList );
+        programInstance.getProgramStageInstances().addAll( proStageInstanceList );
+        
         programStageInstanceService.addProgramStageInstance( newProgramStageInstance );
         
         programInstanceService.updateProgramInstance( programInstance );