← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16739: new web-model, service and controller in the web-api. this helps for better rendering and interac...

 

------------------------------------------------------------
revno: 16739
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-09-17 16:51:26 +0200
message:
  new web-model, service and controller in the web-api. this helps for better rendering and interacting of tei event reports
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-09-09 12:54:28 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-09-17 14:51:26 +0000
@@ -415,7 +415,7 @@
         programStageInstance.setDueDate( dueDate );
         programStageInstance.setOrganisationUnit( organisationUnit );
 
-        if( !singleValue )
+        if ( !singleValue )
         {
             if ( programStageInstance.getProgramStage().getCaptureCoordinates() && event.getCoordinate().isValid() )
             {
@@ -427,7 +427,7 @@
                 programStageInstance.setLatitude( null );
                 programStageInstance.setLongitude( null );
             }
-        }        
+        }
 
         programStageInstanceService.updateProgramStageInstance( programStageInstance );
 
@@ -498,19 +498,11 @@
             executionDate = DateUtils.getMediumDate( event.getEventDate() );
         }
 
-        if ( event.getStatus() == EventStatus.ACTIVE )
-        {
-            programStageInstance.setStatus( EventStatus.VISITED );
-        }
-        else if ( event.getStatus() == EventStatus.COMPLETED )
+        if ( event.getStatus() == EventStatus.COMPLETED )
         {
             programStageInstance.setStatus( EventStatus.COMPLETED );
         }
-        else if ( event.getStatus() == EventStatus.SCHEDULE )
-        {
-            programStageInstance.setStatus( EventStatus.VISITED );
-        }
-        else if ( event.getStatus() == EventStatus.SKIPPED )
+        else
         {
             programStageInstance.setStatus( EventStatus.VISITED );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-09-09 12:54:28 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-09-17 14:51:26 +0000
@@ -300,11 +300,11 @@
             }
             else if ( status == EventStatus.SCHEDULE )
             {
-                sql += "and psi.executiondate is null and date(now()) <= date(psi.duedate) and psi.status = '" + EventStatus.ACTIVE.name() + "' ";
+                sql += "and psi.executiondate is null and date(now()) <= date(psi.duedate) and psi.status = '" + EventStatus.SCHEDULE.name() + "' ";
             }
             else if ( status == EventStatus.OVERDUE )
             {
-                sql += "and psi.executiondate is null and date(now()) > date(psi.duedate) and psi.status = '" + EventStatus.ACTIVE.name() + "' ";
+                sql += "and psi.executiondate is null and date(now()) > date(psi.duedate) and psi.status = '" + EventStatus.SCHEDULE.name() + "' ";
             }
             else
             {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-09-14 07:54:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-09-17 14:51:26 +0000
@@ -117,6 +117,7 @@
         trackedEntityInstance.setTrackedEntityInstance( entityInstance.getUid() );
         trackedEntityInstance.setOrgUnit( entityInstance.getOrganisationUnit().getUid() );
         trackedEntityInstance.setTrackedEntity( entityInstance.getTrackedEntity().getUid() );
+        trackedEntityInstance.setCreated( entityInstance.getCreated().toString() );
 
         Collection<Relationship> relationships = relationshipService
             .getRelationshipsForTrackedEntityInstance( entityInstance );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java	2014-08-22 04:55:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java	2014-09-17 14:51:26 +0000
@@ -32,6 +32,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.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.DxfNamespaces;
 
@@ -49,6 +50,8 @@
     private String trackedEntityInstance;
 
     private String orgUnit;
+    
+    private String created;
 
     private List<Relationship> relationships = new ArrayList<>();
 
@@ -107,6 +110,18 @@
     {
         this.orgUnit = orgUnit;
     }
+    
+    @JsonProperty( required = true )
+    @JacksonXmlProperty( isAttribute = true )
+    public String getCreated()
+    {
+        return created;
+    }
+
+    public void setCreated( String created )
+    {
+        this.created = created;
+    }
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -143,6 +158,7 @@
 
         if ( attributes != null ? !attributes.equals( that.attributes ) : that.attributes != null ) return false;
         if ( orgUnit != null ? !orgUnit.equals( that.orgUnit ) : that.orgUnit != null ) return false;
+        if ( created != null ? !created.equals( that.created ) : that.created != null ) return false;
         if ( relationships != null ? !relationships.equals( that.relationships ) : that.relationships != null ) return false;
         if ( trackedEntity != null ? !trackedEntity.equals( that.trackedEntity ) : that.trackedEntity != null ) return false;
         if ( trackedEntityInstance != null ? !trackedEntityInstance.equals( that.trackedEntityInstance ) : that.trackedEntityInstance != null )
@@ -157,6 +173,7 @@
         int result = trackedEntity != null ? trackedEntity.hashCode() : 0;
         result = 31 * result + (trackedEntityInstance != null ? trackedEntityInstance.hashCode() : 0);
         result = 31 * result + (orgUnit != null ? orgUnit.hashCode() : 0);
+        result = 31 * result + (created != null ? created.hashCode() : 0);
         result = 31 * result + (relationships != null ? relationships.hashCode() : 0);
         result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
         return result;
@@ -169,6 +186,7 @@
             "trackedEntity='" + trackedEntity + '\'' +
             ", trackedEntityInstance='" + trackedEntityInstance + '\'' +
             ", orgUnit='" + orgUnit + '\'' +
+            ", created='" + created + '\'' +
             ", relationships=" + relationships +
             ", attributes=" + attributes +
             '}';

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2014-09-14 07:55:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2014-09-17 14:51:26 +0000
@@ -28,6 +28,8 @@
   <bean id="org.hisp.dhis.dxf2.events.event.EventStore" class="org.hisp.dhis.dxf2.events.event.JdbcEventStore" />
 
   <bean id="org.hisp.dhis.dxf2.events.event.EventService" class="org.hisp.dhis.dxf2.events.event.JacksonEventService" />
+  
+  <bean id="org.hisp.dhis.dxf2.events.report.EventRowService" class="org.hisp.dhis.dxf2.events.report.AbstractEventRowService" />
 
   <bean id="org.hisp.dhis.dxf2.events.person.PersonService"
     class="org.hisp.dhis.dxf2.events.trackedentity.JacksonTrackedEntityInstanceService" />

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-09-17 14:51:26 +0000
@@ -51,6 +51,8 @@
 import org.hisp.dhis.dxf2.events.event.EventService;
 import org.hisp.dhis.dxf2.events.event.Events;
 import org.hisp.dhis.dxf2.events.event.ImportEventTask;
+import org.hisp.dhis.dxf2.events.report.EventRowService;
+import org.hisp.dhis.dxf2.events.report.EventRows;
 import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
@@ -107,6 +109,9 @@
 
     @Autowired
     private EventService eventService;
+    
+    @Autowired
+    private EventRowService eventRowService;
 
     @Autowired
     private TrackedEntityInstanceService trackedEntityInstanceService;
@@ -199,6 +204,58 @@
 
         return "events";
     }
+    
+    @RequestMapping( value = "/overdue", method = RequestMethod.GET )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
+    public String getOverdueEvents(
+        @RequestParam( required = false ) String program,        
+        @RequestParam( required = false ) String orgUnit,
+        @RequestParam( required = false ) OrganisationUnitSelectionMode ouMode,
+        @RequestParam( required = false ) EventStatus status,
+        @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request )
+    {
+        WebOptions options = new WebOptions( parameters );
+
+        Program pr = manager.get( Program.class, program );
+        List<OrganisationUnit> organisationUnits = new ArrayList<>();
+        OrganisationUnit rootOrganisationUnit = null;
+
+        if ( orgUnit != null )
+        {
+            rootOrganisationUnit = manager.get( OrganisationUnit.class, orgUnit );
+        }
+
+        if ( rootOrganisationUnit != null )
+        {
+            if ( OrganisationUnitSelectionMode.DESCENDANTS.equals( ouMode ) )
+            {
+                organisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( rootOrganisationUnit.getUid() ) );
+            }
+            else if ( OrganisationUnitSelectionMode.CHILDREN.equals( ouMode ) )
+            {
+                organisationUnits.add( rootOrganisationUnit );
+                organisationUnits.addAll( rootOrganisationUnit.getChildren() );
+            }
+            else // SELECTED
+            {
+                organisationUnits.add( rootOrganisationUnit );
+            }
+        }
+        
+        EventRows eventRows = eventRowService.getOverDueEventRows( pr, organisationUnits, status);
+        
+        if ( options.hasPaging() )
+        {
+            Pager pager = new Pager( options.getPage(), eventRows.getEventRows().size(), options.getPageSize() );
+            eventRows.setPager( pager );
+            eventRows.setEventRows( PagerUtils.pageCollection( eventRows.getEventRows(), pager ) );
+        }
+        
+        model.addAttribute( "model", eventRows );
+        model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
+
+        return "eventRows";
+    }
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )