← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3444: [DHISMobile] Speed up Activity Plan generating process

 

------------------------------------------------------------
revno: 3444
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Sat 2011-04-23 01:37:49 +0700
message:
  [DHISMobile] Speed up Activity Plan generating process
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/DefaultActivityPlanService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.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-patient/src/main/java/org/hisp/dhis/activityplan/DefaultActivityPlanService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/DefaultActivityPlanService.java	2011-04-12 12:15:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/DefaultActivityPlanService.java	2011-04-22 18:37:49 +0000
@@ -34,8 +34,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
@@ -97,46 +95,33 @@
     public Collection<Activity> getActivitiesByBeneficiary( Patient beneficiary )
     {
         Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( beneficiary, false );
-        
+
         return getActivties( programInstances );
     }
 
     public Collection<Activity> getCurrentActivitiesByProvider( OrganisationUnit organisationUnit )
     {
         long time = PeriodType.createCalendarInstance().getTime().getTime();
-        
+
         List<Activity> items = new ArrayList<Activity>();
 
-        List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
-
-        Collection<Program> programs = programService.getPrograms( organisationUnit );
-
-        for ( Program program : programs )
-        {
-            programInstances.addAll( programInstanceService.getProgramInstances( program, organisationUnit ) );
-        }
-
-        Calendar expiredDate = Calendar.getInstance(); 
+        Calendar expiredDate = Calendar.getInstance();
+
+        Collection<ProgramStageInstance> programStageInstances = programStageInstanceService.get( organisationUnit,
+            null, null, false );
         
-        for ( ProgramInstance programInstance : programInstances )
+        for ( ProgramStageInstance programStageInstance : programStageInstances )
         {
-            Set<ProgramStageInstance> programStageInstances = programInstance.getProgramStageInstances();
-                for ( ProgramStageInstance programStageInstance : programStageInstances )
+            expiredDate.setTime( DateUtils.getDateAfterAddition( programStageInstance.getDueDate(),
+                programStageInstance.getProgramInstance().getProgram().getMaxDaysAllowedInputData() ) );
+            // TODO compare with date.before
+            if ( programStageInstance.getDueDate().getTime() <= time && expiredDate.getTimeInMillis() > time )
             {
-                if(!programStageInstance.isCompleted()){
-                    expiredDate.setTime( DateUtils.getDateAfterAddition( programStageInstance.getDueDate(), programStageInstance.getProgramInstance().getProgram().getMaxDaysAllowedInputData() ) );
-                    
-                    //TODO compare with date.before
-                    
-                    if ( programStageInstance.getDueDate().getTime() <= time && expiredDate.getTimeInMillis() > time )
-                    {
-                        Activity activity = new Activity();
-                        activity.setBeneficiary( programInstance.getPatient() );
-                        activity.setTask( programStageInstance );
-                        activity.setDueDate( programStageInstance.getDueDate() );
-                        items.add( activity );
-                    }
-                }
+                Activity activity = new Activity();
+                activity.setBeneficiary( programStageInstance.getProgramInstance().getPatient() );
+                activity.setTask( programStageInstance );
+                activity.setDueDate( programStageInstance.getDueDate() );
+                items.add( activity );
             }
         }
         return items;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java	2011-04-04 11:46:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java	2011-04-22 18:37:49 +0000
@@ -96,14 +96,24 @@
     // -------------------------------------------------------------------------
     // MobileDataSetService
     // -------------------------------------------------------------------------
+    
+    private PatientMobileSetting setting;
+    
+    private org.hisp.dhis.patient.PatientAttribute groupByAttribute;
 
     public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit, String localeString )
     {
         long time = System.currentTimeMillis();
 
         List<Activity> items = new ArrayList<Activity>();
-
-        for ( org.hisp.dhis.activityplan.Activity activity : activityPlanService.getCurrentActivitiesByProvider( unit ) )
+        
+        this.setSetting( getSettings() );
+        
+        this.setGroupByAttribute( patientAttService.getPatientAttributeByGroupBy( true ) );
+        
+        Collection<org.hisp.dhis.activityplan.Activity> activities = activityPlanService.getCurrentActivitiesByProvider( unit );
+        
+        for ( org.hisp.dhis.activityplan.Activity activity : activities )
         {
             items.add( getActivity( activity.getTask(), activity.getDueDate().getTime() < time ) );
         }
@@ -187,7 +197,7 @@
     {
         Activity activity = new Activity();
         Patient patient = instance.getProgramInstance().getPatient();
-
+                
         activity.setBeneficiary( getBeneficiaryModel( patient ) );
         activity.setDueDate( instance.getDueDate() );
         activity.setTask( getTask( instance ) );
@@ -214,8 +224,8 @@
     private Beneficiary getBeneficiaryModel( Patient patient )
     {
         Beneficiary beneficiary = new Beneficiary();
-
         List<PatientAttribute> patientAtts = new ArrayList<PatientAttribute>();
+        List<org.hisp.dhis.patient.PatientAttribute> atts;
 
         beneficiary.setId( patient.getId() );
         beneficiary.setFirstName( patient.getFirstName() );
@@ -225,8 +235,6 @@
         Period period = new Period( new DateTime( patient.getBirthDate() ), new DateTime() );
         beneficiary.setAge( period.getYears() );
 
-        PatientMobileSetting setting = getSettings();
-
         if ( setting != null )
         {
             if ( setting.getGender() )
@@ -249,38 +257,32 @@
             {
                 beneficiary.setRegistrationDate( patient.getRegistrationDate() );
             }
+            
+            
+            atts = setting.getPatientAttributes();
+            for ( org.hisp.dhis.patient.PatientAttribute each : atts )
+            {
+                PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, each );
+                if ( value != null )
+                {
+                    patientAtts.add( new PatientAttribute( each.getName(), value.getValue() ) );
+                }
+            }
+            
         }
 
         // Set attribute which is used to group beneficiary on mobile (only if
         // there is attribute which is set to be group factor)
         PatientAttribute beneficiaryAttribute = null;
-        org.hisp.dhis.patient.PatientAttribute patientAttribute = patientAttService.getPatientAttributeByGroupBy( true );
-
-        if ( patientAttribute != null )
+       
+        if ( groupByAttribute != null )
         {
             beneficiaryAttribute = new PatientAttribute();
-            beneficiaryAttribute.setName( patientAttribute.getName() );
-            PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, patientAttribute );
+            beneficiaryAttribute.setName( groupByAttribute.getName() );
+            PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, groupByAttribute );
             beneficiaryAttribute.setValue( value == null ? "Unknown" : value.getValue() );
             beneficiary.setGroupAttribute( beneficiaryAttribute );
         }
-        patientAttribute = null;
-
-        // Set all attributes
-
-        List<org.hisp.dhis.patient.PatientAttribute> atts;
-        if ( setting != null )
-        {
-            atts = setting.getPatientAttributes();
-            for ( org.hisp.dhis.patient.PatientAttribute each : atts )
-            {
-                PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, each );
-                if ( value != null )
-                {
-                    patientAtts.add( new PatientAttribute( each.getName(), value.getValue() ) );
-                }
-            }
-        }
 
         // Set all identifier
         Set<PatientIdentifier> patientIdentifiers = patient.getIdentifiers();
@@ -425,4 +427,26 @@
         this.activityPlanService = activityPlanService;
     }
 
+    public PatientMobileSetting getSetting()
+    {
+        return setting;
+    }
+
+    public void setSetting( PatientMobileSetting setting )
+    {
+        this.setting = setting;
+    }
+
+    public org.hisp.dhis.patient.PatientAttribute getGroupByAttribute()
+    {
+        return groupByAttribute;
+    }
+
+    public void setGroupByAttribute( org.hisp.dhis.patient.PatientAttribute groupByAttribute )
+    {
+        this.groupByAttribute = groupByAttribute;
+    }
+    
+    
+
 }