← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15325: [mobile] migrate to TEI new method in line 286, update enrollProgram() to support for register an...

 

------------------------------------------------------------
revno: 15325
committer: Long <long.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2014-05-21 14:08:14 +0700
message:
  [mobile] migrate to TEI new method in line 286, update enrollProgram() to support for register and import Data Value on-the-fly
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.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-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java	2014-05-20 15:42:40 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java	2014-05-21 07:08:14 +0000
@@ -30,6 +30,7 @@
 
 import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 
 import org.hisp.dhis.api.mobile.model.ActivityPlan;
 import org.hisp.dhis.api.mobile.model.ActivityValue;
@@ -40,6 +41,7 @@
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Notification;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Patient;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Program;
+import org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramInstance;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -65,7 +67,7 @@
     String saveProgramStage( ProgramStage programStage, int patientId, int orgUnitId )
         throws NotAllowedException;
 
-    Patient enrollProgram( String enrollInfo, Date incidentDate )
+    Patient enrollProgram( String  enrollInfo, List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage>  mobileProgramStageList, Date incidentDate )
         throws NotAllowedException;
 
     Collection<org.hisp.dhis.trackedentity.TrackedEntityAttribute> getPatientAtts( String programId );

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-05-20 15:42:40 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-05-21 07:08:14 +0000
@@ -283,13 +283,19 @@
         long lowerBound = cal.getTime().getTime();
 
         List<Activity> items = new ArrayList<Activity>();
-        Collection<TrackedEntityInstance> patients = entityInstanceService.getTrackedEntityInstances( unit, 0,
-            Integer.MAX_VALUE );
-
-        for ( TrackedEntityInstance patient : patients )
+
+        TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
+        param.addOrganisationUnit( unit );
+
+        Grid trackedEntityDrid = entityInstanceService.getTrackedEntityInstances( param );
+        List<List<Object>> entityInstanceList = trackedEntityDrid.getRows();
+
+        for ( List<Object> entityInstance : entityInstanceList )
         {
+            TrackedEntityInstance trackedEntityInstance = entityInstanceService
+                .getTrackedEntityInstance( entityInstance.get( 0 ).toString() );
             for ( ProgramStageInstance programStageInstance : programStageInstanceService.getProgramStageInstances(
-                patient, false ) )
+                trackedEntityInstance, false ) )
             {
                 if ( programStageInstance.getDueDate().getTime() >= lowerBound
                     && programStageInstance.getDueDate().getTime() <= upperBound )
@@ -319,19 +325,19 @@
         param.addOrganisationUnit( unit );
 
         Grid trackedEntityDrid = entityInstanceService.getTrackedEntityInstances( param );
-        List<List<Object>> listOfListProgramStageInstance = trackedEntityDrid.getRows();
+        List<List<Object>> entityInstanceList = trackedEntityDrid.getRows();
 
-        for ( List<Object> listProgramStageInstance : listOfListProgramStageInstance )
+        for ( List<Object> entityInstance : entityInstanceList )
         {
-            for ( Object obj : listProgramStageInstance )
+            TrackedEntityInstance trackedEntityInstance = entityInstanceService
+                .getTrackedEntityInstance( entityInstance.get( 0 ).toString() );
+            for ( ProgramStageInstance programStageInstance : programStageInstanceService.getProgramStageInstances(
+                trackedEntityInstance, false ) )
             {
-                TrackedEntityInstance patient = (TrackedEntityInstance) obj;
-                for ( ProgramStageInstance programStageInstance : programStageInstanceService.getProgramStageInstances(
-                    patient, false ) )
-                {
-                    items.add( getActivity( programStageInstance, false ) );
-                }
+
+                items.add( getActivity( programStageInstance, false ) );
             }
+
         }
 
         if ( items.isEmpty() )
@@ -597,7 +603,8 @@
     }
 
     @Override
-    public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram( String enrollInfo, Date incidentDate )
+    public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram( String enrollInfo,
+        List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> mobileProgramStageList, Date incidentDate )
         throws NotAllowedException
     {
         String[] enrollProgramInfo = enrollInfo.split( "-" );
@@ -614,8 +621,13 @@
         programInstance.setEntityInstance( patient );
         programInstance.setStatus( ProgramInstance.STATUS_ACTIVE );
         programInstanceService.addProgramInstance( programInstance );
-        for ( ProgramStage programStage : program.getProgramStages() )
+
+        Iterator<ProgramStage> programStagesIterator = program.getProgramStages().iterator();
+
+        for ( int i = 0; i < program.getProgramStages().size(); i++ )
         {
+            ProgramStage programStage = programStagesIterator.next();
+
             if ( programStage.getAutoGenerateEvent() )
             {
                 ProgramStageInstance programStageInstance = new ProgramStageInstance();
@@ -636,7 +648,20 @@
                     programStageInstance.setExecutionDate( dueDate );
                 }
 
-                programStageInstanceService.addProgramStageInstance( programStageInstance );
+                int programStageInstanceId = programStageInstanceService.addProgramStageInstance( programStageInstance );
+
+                // Inject Datavalue avaiable on-the-fly
+                if ( mobileProgramStageList != null && mobileProgramStageList.size() > 0 )
+                {
+                    org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage = mobileProgramStageList
+                        .get( i );
+                    if ( mobileProgramStage != null && mobileProgramStage.getDataElements().size() > 0 )
+                    {
+                        mobileProgramStage.setId( programStageInstanceId );
+                        this.saveProgramStage( mobileProgramStage, patientId, patient.getOrganisationUnit().getId() );
+                    }
+                }
+
                 programInstance.getProgramStageInstances().add( programStageInstance );
             }
         }
@@ -1147,7 +1172,7 @@
                         programsInfo += program.getId() + "/" + program.getName() + "$";
                     }
                 }
-                
+
                 throw new NotAllowedException( programsInfo );
             }
         }
@@ -1462,7 +1487,8 @@
                 .getEnrollmentPrograms() )
             {
                 Date incidentDate = PeriodUtil.stringToDate( mobileProgramInstance.getDateOfIncident() );
-                enrollProgram( patientId + "-" + mobileProgramInstance.getProgramId(), incidentDate );
+                enrollProgram( patientId + "-" + mobileProgramInstance.getProgramId(),
+                    mobileProgramInstance.getProgramStageInstances(), incidentDate );
             }
         }
         catch ( Exception e )
@@ -1768,7 +1794,7 @@
     }
 
     // TODO remove, we cannot have state like this in a singleton
-    
+
     private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile;
 
     private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientMobile()

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2014-05-16 06:06:48 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2014-05-21 07:08:14 +0000
@@ -403,7 +403,7 @@
     String enrollInfo )
         throws NotAllowedException
     {
-        return activityReportingService.enrollProgram( enrollInfo, new Date() );
+        return activityReportingService.enrollProgram( enrollInfo,null, new Date() );
     }
 
     @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/addRelationship" )