← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21440: service and web-api end point for re-activiting completed program instance

 

------------------------------------------------------------
revno: 21440
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-14 16:03:55 +0100
message:
  service and web-api end point for re-activiting completed program instance
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.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/ProgramInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java	2015-10-20 07:00:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java	2015-12-14 15:03:55 +0000
@@ -368,4 +368,12 @@
      * @param programInstance ProgramInstance
      */
     void cancelProgramInstanceStatus( ProgramInstance programInstance );
+    
+    /**
+     * Incomplete a program instance. This is is possible only if there is
+     * no other program instance with active status.
+     *
+     * @param programInstance ProgramInstance
+     */
+    void incompleteProgramInstanceStatus( ProgramInstance programInstance );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2015-11-20 11:38:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2015-12-14 15:03:55 +0000
@@ -617,6 +617,29 @@
             }
         }
     }
+    
+    @Override
+    public void incompleteProgramInstanceStatus( ProgramInstance programInstance )
+    {        
+        Program program = programInstance.getProgram();
+        
+        TrackedEntityInstance tei = programInstance.getEntityInstance();
+        
+        if( getProgramInstances( tei, program, ProgramStatus.ACTIVE).size() > 0 )
+        {
+            log.warn( "Program has another active enrollment going on. Not possible to incomplete" );
+
+            throw new IllegalQueryException( "Program has another active enrollment going on. Not possible to incomplete" );
+        }
+        
+        // -----------------------------------------------------------------
+        // Update program-instance
+        // -----------------------------------------------------------------
+
+        programInstance.setStatus( ProgramStatus.ACTIVE );
+        
+        updateProgramInstance( programInstance );
+    }
 
     // -------------------------------------------------------------------------
     // Supportive methods

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java	2015-11-03 02:43:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java	2015-12-14 15:03:55 +0000
@@ -414,6 +414,22 @@
         assertEquals( ProgramStatus.COMPLETED, programInstanceService.getProgramInstance( idA ).getStatus() );
         assertEquals( ProgramStatus.COMPLETED, programInstanceService.getProgramInstance( idD ).getStatus() );
     }
+    
+    @Test
+    public void testIncompleteProgramInstanceStatus()
+    {   
+        programInstanceA.setStatus( ProgramStatus.COMPLETED );
+        programInstanceD.setStatus( ProgramStatus.COMPLETED );
+        
+        int idA = programInstanceService.addProgramInstance( programInstanceA );
+        int idD = programInstanceService.addProgramInstance( programInstanceD );
+        
+        programInstanceService.incompleteProgramInstanceStatus( programInstanceA );
+        programInstanceService.incompleteProgramInstanceStatus( programInstanceD );
+        
+        assertEquals( ProgramStatus.ACTIVE, programInstanceService.getProgramInstance( idA ).getStatus() );
+        assertEquals( ProgramStatus.ACTIVE, programInstanceService.getProgramInstance( idD ).getStatus() );
+    }
 
     @Test
     public void testCancelProgramInstanceStatus()

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-12-06 23:17:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-12-14 15:03:55 +0000
@@ -475,6 +475,13 @@
         ProgramInstance programInstance = programInstanceService.getProgramInstance( uid );
         programInstanceService.completeProgramInstanceStatus( programInstance );
     }
+    
+    @Override
+    public void incompleteEnrollment( String uid )
+    {
+        ProgramInstance programInstance = programInstanceService.getProgramInstance( uid );
+        programInstanceService.incompleteProgramInstanceStatus( programInstance );
+    }
 
     // -------------------------------------------------------------------------
     // HELPERS

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java	2015-11-21 11:27:07 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java	2015-12-14 15:03:55 +0000
@@ -81,6 +81,12 @@
     ImportSummary updateEnrollment( Enrollment enrollment );
     
     ImportSummary updateEnrollmentForNote( Enrollment enrollment );
+    
+    void cancelEnrollment( String uid );
+
+    void completeEnrollment( String uid );
+    
+    void incompleteEnrollment( String uid );
 
     // -------------------------------------------------------------------------
     // DELETE
@@ -89,8 +95,5 @@
     ImportSummary deleteEnrollment( String uid );
 
     ImportSummaries deleteEnrollments( List<String> uids );
-
-    void cancelEnrollment( String uid );
-
-    void completeEnrollment( String uid );
+    
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java	2015-11-23 11:11:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java	2015-12-14 15:03:55 +0000
@@ -270,6 +270,19 @@
 
         enrollmentService.completeEnrollment( id );
     }
+    
+    @RequestMapping( value = "/{id}/incompleted", method = RequestMethod.PUT )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')" )
+    @ResponseStatus( HttpStatus.NO_CONTENT )
+    public void incompleteEnrollment( @PathVariable String id ) throws NotFoundException, WebMessageException
+    {
+        if ( !programInstanceService.programInstanceExists( id ) )
+        {
+            throw new WebMessageException( WebMessageUtils.notFound( "Enrollment not found for ID " + id ) );
+        }
+
+        enrollmentService.incompleteEnrollment( id );
+    }
 
     // -------------------------------------------------------------------------
     // DELETE