← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11334: wip, event controller, get old events by uid

 

------------------------------------------------------------
revno: 11334
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-07-04 15:55:19 +0700
message:
  wip, event controller, get old events by uid
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  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/DataValue.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.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-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-05-30 09:08:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-07-04 08:55:19 +0000
@@ -56,6 +56,8 @@
 
     ProgramStageInstance getProgramStageInstance( int id );
 
+    ProgramStageInstance getProgramStageInstance( String uid );
+
     ProgramStageInstance getProgramStageInstance( ProgramInstance programInstance, ProgramStage programStage );
 
     Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage );

=== 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-04 06:19:49 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java	2013-07-04 08:55:19 +0000
@@ -335,4 +335,39 @@
             patientDataValueService.deletePatientDataValue( patientDataValue );
         }
     }
+
+    @Override
+    public Event getEvent( String uid )
+    {
+        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( uid );
+
+        if ( programStageInstance == null )
+        {
+            return null;
+        }
+
+        Event event = new Event();
+
+        event.setCompleted( programStageInstance.isCompleted() );
+        event.setEvent( uid );
+        event.setEventDate( programStageInstance.getExecutionDate().toString() );
+        event.setOrgUnit( programStageInstance.getOrganisationUnit().getUid() );
+        event.setProgram( programStageInstance.getProgramInstance().getProgram().getUid() );
+        event.setProgramStage( programStageInstance.getProgramStage().getUid() );
+        event.setStoredBy( programStageInstance.getCompletedUser() );
+
+        Collection<PatientDataValue> patientDataValues = patientDataValueService.getPatientDataValues( programStageInstance );
+
+        for ( PatientDataValue patientDataValue : patientDataValues )
+        {
+            DataValue value = new DataValue();
+            value.setDataElement( patientDataValue.getDataElement().getUid() );
+            value.setValue( patientDataValue.getValue() );
+            value.setProvidedElsewhere( patientDataValue.getProvidedElsewhere() );
+
+            event.getDataValues().add( value );
+        }
+
+        return event;
+    }
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java	2013-05-30 08:57:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java	2013-07-04 08:55:19 +0000
@@ -47,7 +47,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getValue()
     {
         return value;
@@ -59,7 +59,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getDataElement()
     {
         return dataElement;
@@ -71,7 +71,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public Boolean getProvidedElsewhere()
     {
         return providedElsewhere;

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java	2013-05-30 08:57:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java	2013-07-04 08:55:19 +0000
@@ -31,6 +31,7 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.BaseLinkableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 
 import java.util.ArrayList;
@@ -40,7 +41,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @JacksonXmlRootElement( localName = "event", namespace = DxfNamespaces.DXF_2_0 )
-public class Event
+public class Event extends BaseLinkableObject
 {
     private String program;
 
@@ -67,7 +68,7 @@
     }
 
     @JsonProperty( required = true )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getProgram()
     {
         return program;
@@ -79,7 +80,7 @@
     }
 
     @JsonProperty( required = true )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getProgramStage()
     {
         return programStage;
@@ -91,7 +92,7 @@
     }
 
     @JsonProperty( required = true )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getEvent()
     {
         return event;
@@ -103,7 +104,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getOrgUnit()
     {
         return orgUnit;
@@ -115,7 +116,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getPatient()
     {
         return patient;
@@ -127,7 +128,7 @@
     }
 
     @JsonProperty( required = true )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getEventDate()
     {
         return eventDate;
@@ -139,7 +140,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public Boolean getCompleted()
     {
         return completed;
@@ -151,7 +152,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getStoredBy()
     {
         return storedBy;
@@ -193,7 +194,7 @@
         return "Event{" +
             "program='" + program + '\'' +
             ", programStage='" + programStage + '\'' +
-            ", eventId='" + event + '\'' +
+            ", event='" + event + '\'' +
             ", orgUnit='" + orgUnit + '\'' +
             ", patient='" + patient + '\'' +
             ", eventDate='" + eventDate + '\'' +

=== 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-05-18 10:19:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java	2013-07-04 08:55:19 +0000
@@ -45,4 +45,6 @@
     ImportSummary saveEventJson( InputStream inputStream ) throws IOException;
 
     ImportSummaries saveEventsJson( InputStream inputStream ) throws IOException;
+
+    Event getEvent( String uid );
 }

=== 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-07-04 06:19:49 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2013-07-04 08:55:19 +0000
@@ -26,13 +26,6 @@
  */
 package org.hisp.dhis.program;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.dataelement.DataElement;
@@ -50,6 +43,13 @@
 import org.hisp.dhis.system.grid.ListGrid;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Abyot Asalefew
  * @version $Id$
@@ -115,6 +115,11 @@
         return programStageInstanceStore.get( id );
     }
 
+    public ProgramStageInstance getProgramStageInstance( String uid )
+    {
+        return programStageInstanceStore.getByUid( uid );
+    }
+
     public ProgramStageInstance getProgramStageInstance( ProgramInstance programInstance, ProgramStage programStage )
     {
         return programStageInstanceStore.get( programInstance, programStage );

=== 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-04 05:00:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2013-07-04 08:55:19 +0000
@@ -27,20 +27,27 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.dxf2.event.Event;
 import org.hisp.dhis.dxf2.event.EventService;
 import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -51,6 +58,10 @@
 {
     public static final String RESOURCE_PATH = "/events";
 
+    //--------------------------------------------------------------------------
+    // Dependencies
+    //--------------------------------------------------------------------------
+
     @Autowired
     private EventService eventService;
 
@@ -58,19 +69,42 @@
     // Controller
     // -------------------------------------------------------------------------
 
-    @RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
-    @PreAuthorize("hasRole('ALL') or hasRole('F_PATIENT_DATAVALUE_ADD')")
-    public void postXmlEvents( HttpServletResponse response, InputStream inputStream ) throws IOException
-    {
-        ImportSummaries importSummaries = eventService.saveEventsXml( inputStream );
+    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
+    public String getEvent( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
+        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    {
+        WebOptions options = new WebOptions( parameters );
+        Event event = eventService.getEvent( uid );
+
+        if ( event == null )
+        {
+            ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
+            return null;
+        }
+
+        if ( options.hasLinks() )
+        {
+            event.setHref( ContextUtils.getRootPath( request ) + "/events/" + uid );
+        }
+
+        model.addAttribute( "model", event );
+
+        return StringUtils.uncapitalize( "event" );
+    }
+
+    @RequestMapping( method = RequestMethod.POST, consumes = "application/xml" )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_PATIENT_DATAVALUE_ADD')" )
+    public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+    {
+        ImportSummaries importSummaries = eventService.saveEventsXml( request.getInputStream() );
         JacksonUtils.toXml( response.getOutputStream(), importSummaries );
     }
 
-    @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
-    @PreAuthorize("hasRole('ALL') or hasRole('F_PATIENT_DATAVALUE_ADD')")
-    public void postJsonEvents( HttpServletResponse response, InputStream inputStream ) throws IOException
+    @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_PATIENT_DATAVALUE_ADD')" )
+    public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
     {
-        ImportSummaries importSummaries = eventService.saveEventsJson( inputStream );
+        ImportSummaries importSummaries = eventService.saveEventsJson( request.getInputStream() );
         JacksonUtils.toJson( response.getOutputStream(), importSummaries );
     }