dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11106
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3113: [DHISMobile] Limit the activities sent to mobile: only current activities (due date is before cur...
------------------------------------------------------------
revno: 3113
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: dhis2
timestamp: Tue 2011-03-22 11:36:39 +0700
message:
[DHISMobile] Limit the activities sent to mobile: only current activities (due date is before current date) and late activities (if maxDaysAllowedInputData is before current date).
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/activityplan/ActivityPlanService.java
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/resources/OrgUnitResource.java
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/resources/META-INF/dhis/beans.xml
--
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-api/src/main/java/org/hisp/dhis/activityplan/ActivityPlanService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/activityplan/ActivityPlanService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/activityplan/ActivityPlanService.java 2011-03-22 04:36:39 +0000
@@ -13,24 +13,26 @@
/**
* @author abyotag_adm
- *
+ *
*/
public interface ActivityPlanService
{
String ID = ActivityPlanService.class.getName();
-
- Collection<Activity> getActivitiesByProvider( OrganisationUnit organisationUnit );
-
+
+ Collection<Activity> getActivitiesByProvider( OrganisationUnit organisationUnit );
+
Collection<Activity> getActivitiesByProvider( OrganisationUnit organisationUnit, Collection<Program> programs );
-
- Collection<Activity> getActivitiesByProgram( Collection<Program> programs);
-
+
+ Collection<Activity> getActivitiesByProgram( Collection<Program> programs );
+
Collection<Activity> getActivitiesByBeneficiary( Patient beneficiary );
-
+
Collection<Activity> getActivitiesByTask( ProgramStageInstance task );
-
+
Collection<Activity> getActivitiesByDueDate( Date dueDate );
-
- Collection<Activity> getActivitiesWithInDate( Date startDate, Date endDate );
+
+ Collection<Activity> getActivitiesWithInDate( Date startDate, Date endDate );
+
+ Collection<Activity> getCurrentActivitiesByProvider( OrganisationUnit organisationUnit );
}
=== 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 2010-11-25 22:22:10 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/DefaultActivityPlanService.java 2011-03-22 04:36:39 +0000
@@ -4,10 +4,13 @@
package org.hisp.dhis.activityplan;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
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;
@@ -20,6 +23,7 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.system.util.DateUtils;
/**
* @author abyotag_adm
@@ -59,7 +63,7 @@
{
this.programStageInstanceService = programStageInstanceService;
}
-
+
// -------------------------------------------------------------------------
// ActivityPlan
// -------------------------------------------------------------------------
@@ -82,6 +86,52 @@
}
+ public Collection<Activity> getCurrentActivitiesByProvider( OrganisationUnit organisationUnit )
+ {
+ long time = System.currentTimeMillis();
+
+ 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();
+
+ for ( ProgramInstance programInstance : programInstances )
+ {
+ Set<ProgramStageInstance> programStageInstances = programInstance.getProgramStageInstances();
+ Inner: for ( ProgramStageInstance programStageInstance : programStageInstances )
+ {
+ expiredDate.setTime( DateUtils.getDateAfterAddition( programStageInstance.getDueDate(),
+ programStageInstance.getProgramInstance().getProgram().getMaxDaysAllowedInputData() ) );
+ 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 );
+ }
+ 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 );
+ break Inner;
+ }
+ }
+ }
+ return items;
+ }
+
public Collection<Activity> getActivitiesByProvider( OrganisationUnit organisationUnit )
{
Collection<Activity> activities = new ArrayList<Activity>();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-03-16 07:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-03-22 04:36:39 +0000
@@ -102,9 +102,9 @@
{
OrganisationUnit unit = getUnit();
- if (unit == null)
+ if ( unit == null )
return null;
-
+
OrgUnit orgUnit = new OrgUnitMapper().get( unit );
new UrlResourceListener( uriInfo ).beforeMarshal( orgUnit );
return orgUnit;
@@ -128,7 +128,7 @@
mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit(), locale ) );
mobileModel.setPrograms( programService.getPrograms( getUnit(), locale ) );
mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( getUnit(), locale ) );
- mobileModel.setServerCurrentDate(new Date());
+ mobileModel.setServerCurrentDate( new Date() );
return mobileModel;
}
@@ -170,12 +170,12 @@
@POST
@Path( "activitiyplan" )
- public MobileModel updatePrograms( @HeaderParam( "accept-language" ) String locale, ModelList programsFromClient)
+ public MobileModel updatePrograms( @HeaderParam( "accept-language" ) String locale, ModelList programsFromClient )
{
MobileModel model = new MobileModel();
model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit() ) );
model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit(), locale ) );
- model.setServerCurrentDate(new Date());
+ model.setServerCurrentDate( new Date() );
return model;
}
=== 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-03-15 07:35:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java 2011-03-22 04:36:39 +0000
@@ -50,6 +50,8 @@
import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.system.util.DateUtils;
@@ -82,6 +84,8 @@
private org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService;
+ private org.hisp.dhis.activityplan.ActivityPlanService activityPlanService;
+
private PatientAttributeValueService patientAttValueService;
private PatientAttributeService patientAttService;
@@ -102,24 +106,35 @@
List<Activity> items = new ArrayList<Activity>();
- DateTime dt = new DateTime();
- DateMidnight from = dt.withDayOfMonth( 1 ).toDateMidnight();
- DateMidnight to = from.plusMonths( 1 );
-
- List<ProgramStageInstance> instances = programStageInstanceService.get( unit, from.toDate(), to.toDate(), false );
-
- for ( ProgramStageInstance instance : instances )
- {
- items.add( getActivity( instance, false ) );
- }
-
- instances = programStageInstanceService.get( unit, null, from.minusDays( 1 ).toDate(), false );
-
- for ( ProgramStageInstance instance : instances )
- {
- items.add( getActivity( instance, true ) );
- }
-
+ Collection<org.hisp.dhis.activityplan.Activity> activities;
+
+ activities = activityPlanService.getCurrentActivitiesByProvider( unit );
+
+ for ( org.hisp.dhis.activityplan.Activity each : activities )
+ {
+ Date expiredDate = DateUtils.getDateAfterAddition( each.getTask().getDueDate(), each.getTask()
+ .getProgramInstance().getProgram().getMaxDaysAllowedInputData() );
+
+ Activity activity = new Activity();
+ Patient patient = each.getBeneficiary();
+
+ activity.setBeneficiary( getBeneficiaryModel( patient ) );
+
+ activity.setDueDate( each.getDueDate() );
+
+ Task task = new Task();
+ task.setCompleted( each.getTask().isCompleted() );
+ task.setId( each.getTask().getId() );
+ task.setProgramStageId( each.getTask().getProgramStage().getId() );
+ task.setProgramId( each.getTask().getProgramInstance().getProgram().getId() );
+ activity.setTask( task );
+
+ activity.setLate( each.isCompleted() );
+
+ activity.setExpireDate( expiredDate );
+
+ items.add( activity );
+ }
if ( items.isEmpty() )
{
return null;
@@ -212,8 +227,9 @@
activity.setDueDate( instance.getDueDate() );
activity.setTask( getTask( instance ) );
activity.setLate( late );
- activity.setExpireDate(DateUtils.getDateAfterAddition(instance.getDueDate(), instance.getProgramInstance().getProgram().getMaxDaysAllowedInputData()));
-
+ activity.setExpireDate( DateUtils.getDateAfterAddition( instance.getDueDate(), instance.getProgramInstance()
+ .getProgram().getMaxDaysAllowedInputData() ) );
+
return activity;
}
@@ -443,4 +459,9 @@
this.patientMobileSettingService = patientMobileSettingService;
}
+ public void setActivityPlanService( org.hisp.dhis.activityplan.ActivityPlanService activityPlanService )
+ {
+ this.activityPlanService = activityPlanService;
+ }
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-03-22 04:36:39 +0000
@@ -59,6 +59,7 @@
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="dataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
<property name="patientMobileSettingService" ref="org.hisp.dhis.patient.PatientMobileSettingService" />
+ <property name="activityPlanService" ref="org.hisp.dhis.activityplan.ActivityPlanService" />
</bean>
<bean id="org.hisp.dhis.web.api.service.IProgramService" class="org.hisp.dhis.web.api.service.DefaultProgramService">