← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17135: removed PIController, functionality will be merged into EnrollmentController. Added service metho...

 

------------------------------------------------------------
revno: 17135
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-16 15:57:58 +0700
message:
  removed PIController, functionality will be merged into EnrollmentController. Added service methods for getting enrollments by status, program, orgUnits, start, end.
removed:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramInstanceController.java
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


--
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	2014-09-08 11:29:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2014-10-16 08:57:58 +0000
@@ -30,9 +30,9 @@
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.common.QueryItem;
 import org.hisp.dhis.common.QueryOperator;
@@ -65,6 +65,7 @@
 import org.springframework.util.Assert;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -93,10 +94,10 @@
 
     @Autowired
     private TrackedEntityAttributeValueService trackedEntityAttributeValueService;
-    
+
     @Autowired
     protected CurrentUserService currentUserService;
-    
+
     @Autowired
     private TrackedEntityCommentService commentService;
 
@@ -188,6 +189,24 @@
     }
 
     @Override
+    public Enrollments getEnrollments( Program program, EnrollmentStatus status, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+    {
+        List<ProgramInstance> programInstances = new ArrayList<>(
+            programInstanceService.getProgramInstancesByStatus( status.getValue(), program, Arrays.asList( organisationUnit.getId() ), startDate, endDate ) );
+
+        return getEnrollments( programInstances );
+    }
+
+    @Override
+    public Enrollments getEnrollments( Program program, EnrollmentStatus status, List<OrganisationUnit> organisationUnits, Date startDate, Date endDate )
+    {
+        List<ProgramInstance> programInstances = new ArrayList<>(
+            programInstanceService.getProgramInstancesByStatus( status.getValue(), program, IdentifiableObjectUtils.getIdentifiers( organisationUnits ), startDate, endDate ) );
+
+        return getEnrollments( programInstances );
+    }
+
+    @Override
     public Enrollments getEnrollments( OrganisationUnit organisationUnit )
     {
         List<Program> programs = getProgramsWithRegistration();
@@ -348,7 +367,7 @@
         updateAttributeValues( enrollment );
         programInstance.setFollowup( enrollment.getFollowup() );
         programInstanceService.updateProgramInstance( programInstance );
-        
+
         saveTrackedEntityComment( programInstance, enrollment );
 
         importSummary.setReference( programInstance.getUid() );
@@ -430,7 +449,7 @@
 
         updateAttributeValues( enrollment );
         programInstanceService.updateProgramInstance( programInstance );
-        
+
         saveTrackedEntityComment( programInstance, enrollment );
 
         importSummary.setReference( enrollment.getEnrollment() );
@@ -712,11 +731,11 @@
 
         return importConflicts;
     }
-    
+
     private void saveTrackedEntityComment( ProgramInstance programInstance, Enrollment enrollment )
     {
         String storedBy = currentUserService.getCurrentUsername();
-        
+
         for ( Note note : enrollment.getNotes() )
         {
             TrackedEntityComment comment = new TrackedEntityComment();

=== 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	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java	2014-10-16 08:57:58 +0000
@@ -28,10 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-
 import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
@@ -39,6 +35,12 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -64,6 +66,10 @@
 
     Enrollments getEnrollments( Program program, EnrollmentStatus status );
 
+    Enrollments getEnrollments( Program program, EnrollmentStatus status, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
+    Enrollments getEnrollments( Program program, EnrollmentStatus status, List<OrganisationUnit> organisationUnits, Date startDate, Date endDate );
+
     Enrollments getEnrollments( Program program, TrackedEntityInstance trackedEntityInstance );
 
     Enrollments getEnrollments( Program program, TrackedEntityInstance trackedEntityInstance, EnrollmentStatus status );

=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramInstanceController.java	2014-10-16 05:49:47 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramInstanceController.java	1970-01-01 00:00:00 +0000
@@ -1,155 +0,0 @@
-package org.hisp.dhis.webapi.controller.event;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Lists;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.common.IdentifiableObjectUtils;
-import org.hisp.dhis.common.Pager;
-import org.hisp.dhis.dxf2.fieldfilter.FieldFilterService;
-import org.hisp.dhis.node.types.ComplexNode;
-import org.hisp.dhis.node.types.RootNode;
-import org.hisp.dhis.node.types.SimpleNode;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.program.Program;
-import org.hisp.dhis.program.ProgramInstance;
-import org.hisp.dhis.program.ProgramInstanceService;
-import org.hisp.dhis.webapi.service.ContextService;
-import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.webapi.webdomain.WebMetaData;
-import org.hisp.dhis.webapi.webdomain.WebOptions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.format.annotation.DateTimeFormat;
-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.RestController;
-
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@RestController
-@RequestMapping( value = "/programInstances" )
-public class ProgramInstanceController
-{
-    @Autowired
-    private ProgramInstanceService programInstanceService;
-
-    @Autowired
-    private IdentifiableObjectManager manager;
-
-    @Autowired
-    protected ContextService contextService;
-
-    @Autowired
-    protected FieldFilterService fieldFilterService;
-
-    @RequestMapping( method = RequestMethod.GET )
-    public RootNode getProgramInstances(
-        @RequestParam( value = "program" ) String programId,
-        @RequestParam( value = "orgUnit" ) List<String> orgUnits,
-        @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
-        @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
-        @RequestParam( required = false ) Integer status,
-        @RequestParam Map<String, String> parameters, HttpServletResponse response
-    )
-    {
-        List<String> fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) );
-
-        if ( fields.isEmpty() )
-        {
-            fields.add( ":identifiable" );
-        }
-
-        WebOptions options = new WebOptions( parameters );
-        WebMetaData metaData = new WebMetaData();
-
-        Program program = manager.get( Program.class, programId );
-
-        if ( program == null )
-        {
-            ContextUtils.conflictResponse( response, "program parameter is required." );
-        }
-
-        if ( orgUnits.isEmpty() )
-        {
-            ContextUtils.conflictResponse( response, "At least one orgUnit is required." );
-        }
-
-        List<OrganisationUnit> organisationUnits = new ArrayList<>( manager.getByUid( OrganisationUnit.class, orgUnits ) );
-        List<Integer> identifiers = IdentifiableObjectUtils.getIdentifiers( organisationUnits );
-
-        List<ProgramInstance> programInstances;
-
-        if ( options.hasPaging() )
-        {
-            int count = status == null ?
-                programInstanceService.countProgramInstances( program, identifiers, startDate, endDate ) :
-                programInstanceService.countProgramInstancesByStatus( status, program, identifiers, startDate, endDate );
-
-            Pager pager = new Pager( options.getPage(), count, options.getPageSize() );
-            metaData.setPager( pager );
-
-            programInstances = new ArrayList<>( status == null ?
-                programInstanceService.getProgramInstances( program, identifiers, startDate, endDate, pager.getOffset(), pager.getPageSize() ) :
-                programInstanceService.getProgramInstancesByStatus( status, program, identifiers, startDate, endDate, pager.getOffset(), pager.getPageSize() ) );
-        }
-        else
-        {
-            programInstances = new ArrayList<>( status == null ?
-                programInstanceService.getProgramInstances( program, identifiers, startDate, endDate, 0, Integer.MAX_VALUE ) :
-                programInstanceService.getProgramInstancesByStatus( status, program, identifiers, startDate, endDate ) );
-        }
-
-        RootNode rootNode = new RootNode( "metadata" );
-        rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
-        rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
-
-        if ( options.hasPaging() )
-        {
-            ComplexNode pagerNode = rootNode.addChild( new ComplexNode( "pager" ) );
-            pagerNode.addChild( new SimpleNode( "page", metaData.getPager().getPage() ) );
-            pagerNode.addChild( new SimpleNode( "pageCount", metaData.getPager().getPageCount() ) );
-            pagerNode.addChild( new SimpleNode( "total", metaData.getPager().getTotal() ) );
-            pagerNode.addChild( new SimpleNode( "nextPage", metaData.getPager().getNextPage() ) );
-            pagerNode.addChild( new SimpleNode( "prevPage", metaData.getPager().getPrevPage() ) );
-        }
-
-        rootNode.addChild( fieldFilterService.filter( ProgramInstance.class, programInstances, fields ) );
-
-        return rootNode;
-    }
-}