← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12145: support updating Enrollment status by PUT to /api/enrollments/UID/cancelled and /api/enrollments/...

 

------------------------------------------------------------
revno: 12145
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-18 16:03:19 +0200
message:
  support updating Enrollment status by PUT to /api/enrollments/UID/cancelled and /api/enrollments/UID/completed
modified:
  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/api/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-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	2013-09-18 13:42:06 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2013-09-18 14:03:19 +0000
@@ -287,11 +287,30 @@
     @Override
     public void deleteEnrollment( Enrollment enrollment )
     {
+        ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
+        programInstanceService.deleteProgramInstance( programInstance );
     }
 
     @Override
     public void cancelEnrollment( Enrollment enrollment )
     {
+        ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
+        programInstanceService.cancelProgramInstanceStatus( programInstance );
+    }
+
+    @Override
+    public void completeEnrollment( Enrollment enrollment )
+    {
+        try
+        {
+            format = i18nManager.getI18nFormat();
+        }
+        catch ( I18nManagerException ignored )
+        {
+        }
+
+        ProgramInstance programInstance = programInstanceService.getProgramInstance( enrollment.getEnrollment() );
+        programInstanceService.completeProgramInstanceStatus( programInstance, format );
     }
 
     // -------------------------------------------------------------------------

=== 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	2013-09-18 13:09:07 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java	2013-09-18 14:03:19 +0000
@@ -108,4 +108,6 @@
     void deleteEnrollment( Enrollment enrollment );
 
     void cancelEnrollment( Enrollment enrollment );
+
+    void completeEnrollment( Enrollment enrollment );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java	2013-09-18 13:09:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java	2013-09-18 14:03:19 +0000
@@ -125,7 +125,7 @@
         }
         else
         {
-                Person person = getPerson( personUid );
+            Person person = getPerson( personUid );
             enrollments = status != null ? enrollmentService.getEnrollments( person, status ) : enrollmentService.getEnrollments( person );
         }
 
@@ -219,6 +219,22 @@
         JacksonUtils.toJson( response.getOutputStream(), importSummary );
     }
 
+    @RequestMapping( value = "/{id}/cancelled", method = RequestMethod.PUT )
+    @ResponseStatus( HttpStatus.NO_CONTENT )
+    public void cancelEnrollment( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model ) throws NotFoundException
+    {
+        Enrollment enrollment = getEnrollment( id );
+        enrollmentService.cancelEnrollment( enrollment );
+    }
+
+    @RequestMapping( value = "/{id}/completed", method = RequestMethod.PUT )
+    @ResponseStatus( HttpStatus.NO_CONTENT )
+    public void completedEnrollment( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model ) throws NotFoundException
+    {
+        Enrollment enrollment = getEnrollment( id );
+        enrollmentService.completeEnrollment( enrollment );
+    }
+
     // -------------------------------------------------------------------------
     // DELETE
     // -------------------------------------------------------------------------
@@ -228,7 +244,7 @@
     public void deleteEnrollment( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model ) throws NotFoundException
     {
         Enrollment enrollment = getEnrollment( id );
-        enrollmentService.cancelEnrollment( enrollment );
+        enrollmentService.deleteEnrollment( enrollment );
     }
 
     // -------------------------------------------------------------------------