← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11350: support PUT on events

 

------------------------------------------------------------
revno: 11350
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-07-05 16:21:49 +0700
message:
  support PUT on events
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.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-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java	2013-07-05 06:34:10 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java	2013-07-05 09:21:49 +0000
@@ -54,6 +54,8 @@
 
 import java.util.Collection;
 import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -372,6 +374,64 @@
     }
 
     @Override
+    public void updateEvent( Event event )
+    {
+        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() );
+
+        if ( programStageInstance == null )
+        {
+            return;
+        }
+
+        OrganisationUnit organisationUnit = null;
+
+        if ( event.getOrgUnit() != null )
+        {
+            organisationUnit = organisationUnitService.getOrganisationUnit( event.getOrgUnit() );
+        }
+        else
+        {
+            organisationUnit = programStageInstance.getOrganisationUnit();
+        }
+
+        Date date = new Date();
+
+        programStageInstance.setDueDate( date );
+        programStageInstance.setExecutionDate( date );
+        programStageInstance.setOrganisationUnit( organisationUnit );
+        programStageInstance.setCompletedUser( event.getStoredBy() );
+
+        programStageInstanceService.updateProgramStageInstance( programStageInstance );
+
+        Set<PatientDataValue> patientDataValues = new HashSet<PatientDataValue>( patientDataValueService.getPatientDataValues( programStageInstance ) );
+
+        for ( DataValue value : event.getDataValues() )
+        {
+            DataElement dataElement = dataElementService.getDataElement( value.getDataElement() );
+
+            PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, dataElement );
+
+            if ( patientDataValue != null )
+            {
+                patientDataValue.setValue( value.getValue() );
+                patientDataValue.setProvidedElsewhere( value.getProvidedElsewhere() );
+                patientDataValueService.updatePatientDataValue( patientDataValue );
+
+                patientDataValues.remove( patientDataValue );
+            }
+            else
+            {
+                saveDataValue( programStageInstance, event.getStoredBy(), dataElement, value.getValue(), value.getProvidedElsewhere() );
+            }
+        }
+
+        for ( PatientDataValue value : patientDataValues )
+        {
+            patientDataValueService.deletePatientDataValue( value );
+        }
+    }
+
+    @Override
     public void deleteEvent( Event event )
     {
         ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() );

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java	2013-07-05 06:34:10 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java	2013-07-05 09:21:49 +0000
@@ -48,5 +48,7 @@
 
     Event getEvent( String uid );
 
+    void updateEvent( Event event );
+
     void deleteEvent( Event event );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2013-07-05 06:45:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2013-07-05 09:21:49 +0000
@@ -164,6 +164,10 @@
         }
 
         Event updatedEvent = JacksonUtils.fromXml( request.getInputStream(), Event.class );
+        updatedEvent.setEvent( uid );
+
+        eventService.updateEvent( updatedEvent );
+        ContextUtils.okResponse( response, "" );
     }
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
@@ -179,11 +183,17 @@
         }
 
         Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
+        updatedEvent.setEvent( uid );
+
+        eventService.updateEvent( updatedEvent );
+        ContextUtils.okResponse( response, "" );
     }
 
+    /*
     @ExceptionHandler( IllegalArgumentException.class )
     public void handleError( IllegalArgumentException ex, HttpServletResponse response )
     {
         ContextUtils.conflictResponse( response, ex.getMessage() );
     }
+    */
 }