← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19552: switched to using nodes for rendering enrollments, also makes field filtering work

 

------------------------------------------------------------
revno: 19552
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-07-07 10:54:38 +0700
message:
  switched to using nodes for rendering enrollments, also makes field filtering work
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java	2015-03-21 04:23:16 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java	2015-07-07 03:54:38 +0000
@@ -75,6 +75,18 @@
 
     @JsonProperty( required = true )
     @JacksonXmlProperty( isAttribute = true )
+    public String getEnrollment()
+    {
+        return enrollment;
+    }
+
+    public void setEnrollment( String enrollment )
+    {
+        this.enrollment = enrollment;
+    }
+
+    @JsonProperty( required = true )
+    @JacksonXmlProperty( isAttribute = true )
     public String getTrackedEntityInstance()
     {
         return trackedEntityInstance;
@@ -87,18 +99,6 @@
 
     @JsonProperty( required = true )
     @JacksonXmlProperty( isAttribute = true )
-    public String getEnrollment()
-    {
-        return enrollment;
-    }
-
-    public void setEnrollment( String enrollment )
-    {
-        this.enrollment = enrollment;
-    }
-
-    @JsonProperty( required = true )
-    @JacksonXmlProperty( isAttribute = true )
     public String getProgram()
     {
         return program;
@@ -158,7 +158,6 @@
     }
 
     @JsonProperty
-    @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public List<Attribute> getAttributes()
     {
@@ -171,7 +170,6 @@
     }
     
     @JsonProperty
-    @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public List<Note> getNotes()
     {

=== 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-05-11 06:02:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EnrollmentController.java	2015-07-07 03:54:38 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.dxf2.common.JacksonUtils;
@@ -37,14 +38,18 @@
 import org.hisp.dhis.dxf2.events.enrollment.Enrollments;
 import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService;
+import org.hisp.dhis.dxf2.fieldfilter.FieldFilterService;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
 import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.node.NodeUtils;
+import org.hisp.dhis.node.types.RootNode;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.webapi.controller.exception.NotFoundException;
+import org.hisp.dhis.webapi.service.ContextService;
 import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.hisp.dhis.webapi.webdomain.WebOptions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -57,6 +62,7 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
 
 import javax.servlet.http.HttpServletRequest;
@@ -88,24 +94,41 @@
     @Autowired
     private OrganisationUnitService organisationUnitService;
 
+    @Autowired
+    protected FieldFilterService fieldFilterService;
+
+    @Autowired
+    protected ContextService contextService;
+
     // -------------------------------------------------------------------------
     // READ
     // -------------------------------------------------------------------------
 
     @RequestMapping( value = "", method = RequestMethod.GET )
-    public String getEnrollments(
+    public @ResponseBody RootNode getEnrollments(
         @RequestParam( value = "orgUnit", required = false ) String orgUnitUid,
         @RequestParam( value = "program", required = false ) String programUid,
         @RequestParam( value = "trackedEntityInstance", required = false ) String trackedEntityInstanceUid,
         @RequestParam( required = false ) Date startDate,
         @RequestParam( required = false ) Date endDate,
         @RequestParam( required = false ) OrganisationUnitSelectionMode ouMode,
-        @RequestParam( value = "status", required = false ) EnrollmentStatus status,
-        @RequestParam Map<String, String> parameters, Model model ) throws NotFoundException
+        @RequestParam( value = "status", required = false ) EnrollmentStatus status ) throws NotFoundException
     {
-        WebOptions options = new WebOptions( parameters );
+        List<String> fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) );
         Enrollments enrollments;
 
+        if ( fields.isEmpty() )
+        {
+            fields.add( "enrollment" );
+            fields.add( "trackedEntityInstance" );
+            fields.add( "program" );
+            fields.add( "status" );
+            fields.add( "orgUnit" );
+            fields.add( "dateOfEnrollment" );
+            fields.add( "dateOfIncident" );
+            fields.add( "followup" );
+        }
+
         if ( startDate != null && endDate != null && programUid != null && orgUnitUid != null && ouMode != null )
         {
             OrganisationUnit organisationUnit = getOrganisationUnit( orgUnitUid );
@@ -153,10 +176,10 @@
             enrollments = status != null ? enrollmentService.getEnrollments( trackedEntityInstance, status ) : enrollmentService.getEnrollments( trackedEntityInstance );
         }
 
-        model.addAttribute( "model", enrollments );
-        model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
+        RootNode rootNode = NodeUtils.createMetadata();
+        rootNode.addChild( fieldFilterService.filter( Enrollment.class, enrollments.getEnrollments(), fields ) );
 
-        return "enrollments";
+        return rootNode;
     }
 
     @RequestMapping( value = "/{id}", method = RequestMethod.GET )