← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2095: [DHIS Mobile] Send compulsory flags to mobile client, set ProgramStageInstance to "completed" whe...

 

------------------------------------------------------------
revno: 2095
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Thu 2010-11-18 11:09:03 +0700
message:
  [DHIS Mobile] Send compulsory flags to mobile client, set ProgramStageInstance to "completed" when receive data value from client.
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.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-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java	2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java	2010-11-18 04:09:03 +0000
@@ -27,32 +27,49 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-public class DataElement extends Model {	
-
-	private String type;
-
-	private ModelList categoryOptionCombos;
-	
-	public DataElement() {
-
-	}	
-
-	public String getType() {
-		return type;
-	}
-
-	public void setType(String type) {
-		this.type = type;
-	}
-
-        public ModelList getCategoryOptionCombos()
-        {
-            return categoryOptionCombos;
-        }
-    
-        public void setCategoryOptionCombos( ModelList categoryOptionCombos )
-        {
-            this.categoryOptionCombos = categoryOptionCombos;
-        }
-		
+public class DataElement
+    extends Model
+{
+
+    private String type;
+
+    private boolean compulsory;
+
+    private ModelList categoryOptionCombos;
+
+    public DataElement()
+    {
+
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    public ModelList getCategoryOptionCombos()
+    {
+        return categoryOptionCombos;
+    }
+
+    public void setCategoryOptionCombos( ModelList categoryOptionCombos )
+    {
+        this.categoryOptionCombos = categoryOptionCombos;
+    }
+
+    public boolean isCompulsory()
+    {
+        return compulsory;
+    }
+
+    public void setCompulsory( boolean compulsory )
+    {
+        this.compulsory = compulsory;
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java	2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java	2010-11-18 04:09:03 +0000
@@ -64,7 +64,8 @@
             dout.writeInt( de.getId() );
             dout.writeUTF( de.getName() );
             dout.writeUTF( de.getType() );
-
+            dout.writeBoolean( de.isCompulsory() );
+            
             List<Model> cateOptCombos = de.getCategoryOptionCombos().getAbstractModels();
             if ( cateOptCombos == null || cateOptCombos.size() <= 0 )
             {
@@ -79,6 +80,7 @@
                     dout.writeUTF( each.getName() );
                 }
             }
+            
         }
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java	2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java	2010-11-18 04:09:03 +0000
@@ -63,6 +63,8 @@
                 dout.writeInt( de.getId() );
                 dout.writeUTF( de.getName() );
                 dout.writeUTF( de.getType() );
+                dout.writeBoolean( de.isCompulsory() );
+                
                 List<Model> cateOptCombos = de.getCategoryOptionCombos().getAbstractModels();
                 if ( cateOptCombos == null || cateOptCombos.size() <= 0 )
                 {

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java	2010-11-18 04:09:03 +0000
@@ -0,0 +1,77 @@
+package org.hisp.dhis.web.api.provider;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import org.hisp.dhis.web.api.model.ActivityPlan;
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZOutputStream;
+import com.sun.jersey.spi.resource.Singleton;
+
+@Provider
+@Singleton
+@Produces( "application/vnd.org.dhis2.activityplan+serialized" )
+public class ActivityPlanProvider
+    implements MessageBodyWriter<ActivityPlan>
+{
+
+    @Override
+    public long getSize( ActivityPlan arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4 )
+    {
+        return -1;
+    }
+
+    @Override
+    public boolean isWriteable( Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3 )
+    {
+
+        return true;
+    }
+
+    @Override
+    public void writeTo( ActivityPlan arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4,
+        MultivaluedMap<String, Object> arg5, OutputStream stream )
+        throws IOException, WebApplicationException
+    {
+        serializeZipped( arg0, stream );
+    }
+
+    public void serializeZipped( ActivityPlan activityPlan, OutputStream os )
+        throws IOException
+    {
+        ByteArrayOutputStream baos = serializePersistent( activityPlan );
+        ZOutputStream gzip = new ZOutputStream( os, JZlib.Z_BEST_COMPRESSION );
+        DataOutputStream dos = new DataOutputStream( gzip );
+
+        try
+        {
+            dos.write( baos.toByteArray() );
+        }
+        finally
+        {
+            dos.flush();
+            gzip.finish();
+        }
+    }
+
+    public ByteArrayOutputStream serializePersistent( ActivityPlan activityPlan )
+        throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream out = new DataOutputStream( baos );
+        activityPlan.serialize( out );
+        out.flush();
+        return baos;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java	2010-11-18 03:02:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java	2010-11-18 04:09:03 +0000
@@ -1,14 +1,10 @@
 package org.hisp.dhis.web.api.service;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
-
 import org.hisp.dhis.activityplan.Activity;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
@@ -23,7 +19,6 @@
 import org.hisp.dhis.web.api.service.mapping.TaskMapper;
 import org.joda.time.DateMidnight;
 import org.joda.time.DateTime;
-import org.springframework.beans.factory.annotation.Autowired;
 
 public class DefaultActivityPlanService
     implements IActivityPlanService
@@ -116,7 +111,7 @@
         {
             // there are error on db with patientattributeid 14, so I limit the
             // patient to be downloaded
-            if ( i++ > 10 )
+            if ( i > 10 )
             {
                 break;
             }
@@ -130,12 +125,14 @@
             if ( from.isBefore( dueTime ) )
             {
                 items.add( getActivityModel( activity ) );
+                i++;
             }
             else if ( !activity.getTask().isCompleted() )
             {
                 org.hisp.dhis.web.api.model.Activity a = getActivityModel( activity );
                 items.add( a );
                 a.setLate( true );
+                i++;
             }
         }
         if ( !items.isEmpty() )
@@ -204,39 +201,40 @@
             .getPatientAttributeByName( "Nearest Contact Person Name" );
 
         PatientAttributeValue houseNameValue = patientAttValueService.getPatientAttributeValue( patient, houseName );
-        if(houseNameValue!=null){
-            patientAtts.add( new PatientAttribute( "House Name", houseNameValue.getValue() ));
+        if ( houseNameValue != null )
+        {
+            patientAtts.add( new PatientAttribute( "House Name", houseNameValue.getValue() ) );
         }
-        
-        
+
         PatientAttributeValue houseNumberValue = patientAttValueService.getPatientAttributeValue( patient, houseNumber );
-        if(houseNumberValue!=null){
-            patientAtts.add( new PatientAttribute( "House Number", houseNumberValue.getValue() ));
+        if ( houseNumberValue != null )
+        {
+            patientAtts.add( new PatientAttribute( "House Number", houseNumberValue.getValue() ) );
         }
-        
-        
+
         PatientAttributeValue wardNumberValue = patientAttValueService.getPatientAttributeValue( patient, wardNumber );
-        if(wardNumberValue!=null){
-            patientAtts.add( new PatientAttribute( "Ward Number", wardNumberValue.getValue() ));
-        }
-        
-        
-        PatientAttributeValue nearestContactValue = patientAttValueService.getPatientAttributeValue( patient, nearestContact );
-        if(nearestContactValue!=null){
-            patientAtts.add( new PatientAttribute( "Nearest Contact", nearestContactValue.getValue() ));
-        }
-        
+        if ( wardNumberValue != null )
+        {
+            patientAtts.add( new PatientAttribute( "Ward Number", wardNumberValue.getValue() ) );
+        }
+
+        PatientAttributeValue nearestContactValue = patientAttValueService.getPatientAttributeValue( patient,
+            nearestContact );
+        if ( nearestContactValue != null )
+        {
+            patientAtts.add( new PatientAttribute( "Nearest Contact", nearestContactValue.getValue() ) );
+        }
+
         beneficiary.setPatientAttValues( patientAtts );
-        
-        
-//         for ( PatientAttributeValue patientAttributeValue :
-//         patientAttValueService.getPatientAttributeValues( patient ) )
-//         {
-//         patientAttValues.add(
-//         patientAttributeValue.getPatientAttribute().getName() + " : "
-//         + patientAttributeValue.getValue() );
-//         }
-//         beneficiary.setPatientAttValues( patientAttValues );
+
+        // for ( PatientAttributeValue patientAttributeValue :
+        // patientAttValueService.getPatientAttributeValues( patient ) )
+        // {
+        // patientAttValues.add(
+        // patientAttributeValue.getPatientAttribute().getName() + " : "
+        // + patientAttributeValue.getValue() );
+        // }
+        // beneficiary.setPatientAttValues( patientAttValues );
 
         return beneficiary;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java	2010-11-15 08:35:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java	2010-11-18 04:09:03 +0000
@@ -132,6 +132,9 @@
             dataElementMap.put( dataElement.getId(), dataElement );
         }
 
+        // Set ProgramStageInstance to completed
+        programStageInstance.setCompleted( true );
+        programStageInstanceService.updateProgramStageInstance( programStageInstance );
         // Everything is fine, hence save
         saveDataValues( activityValue, programStageInstance, dataElementMap, unit,
             categoryService.getDefaultDataElementCategoryOptionCombo() );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java	2010-11-17 06:12:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java	2010-11-18 04:09:03 +0000
@@ -140,6 +140,7 @@
                 de.setId( programStagedataElement.getDataElement().getId() );
                 de.setName( programStagedataElement.getDataElement().getName() );
                 de.setType( programStagedataElement.getDataElement().getType() );
+                de.setCompulsory( programStagedataElement.isCompulsory() );
                 de.setCategoryOptionCombos( mobileCategpryOptCombos );
 
                 des.add( de );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java	2010-11-16 18:26:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java	2010-11-18 04:09:03 +0000
@@ -159,6 +159,9 @@
                 de.setId( dataElement.getId() );
                 de.setName( dataElement.getName() );
                 de.setType( dataElement.getType() );
+                
+                //For facility Reporting, all data element are mandetory
+                de.setCompulsory( true );
                 de.setCategoryOptionCombos( deCateOptCombo );
                 dataElementList.add( de );
             }

=== 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	2010-11-16 19:05:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml	2010-11-18 04:09:03 +0000
@@ -66,6 +66,9 @@
 
   <bean id="org.hisp.dhis.web.api.provider.DataSerializableProvider" class="org.hisp.dhis.web.api.provider.DataSerializableProvider"
     scope="singleton" />
+	
+	<bean id="org.hisp.dhis.web.api.provider.ActivityPlanProvider"
+		class="org.hisp.dhis.web.api.provider.ActivityPlanProvider" scope="singleton"/>
 
   <bean id="org.hisp.dhis.web.api.consumer.DataSetValueConsumer" class="org.hisp.dhis.web.api.provider.DataSetValueConsumer"
     scope="singleton" />