← Back to team overview

dhis-mobile-devs team mailing list archive

[Branch ~dhis-mobile-devs/dhis-mobile/lwuit-tracking] Rev 226: added GetPatientsTask and patientList.java

 

------------------------------------------------------------
revno: 226
committer: sherylyn.marie
branch nick: lwuit-tracking
timestamp: Thu 2014-05-29 00:22:15 +0800
message:
  added GetPatientsTask and patientList.java
added:
  src/org/hisp/dhis/mobile/connection/task/GetPatientsTask.java
  src/org/hisp/dhis/mobile/model/PatientList.java


--
lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking
https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking

Your team DHIS mobile developers is subscribed to branch lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking/+edit-subscription
=== added file 'src/org/hisp/dhis/mobile/connection/task/GetPatientsTask.java'
--- src/org/hisp/dhis/mobile/connection/task/GetPatientsTask.java	1970-01-01 00:00:00 +0000
+++ src/org/hisp/dhis/mobile/connection/task/GetPatientsTask.java	2014-05-28 16:22:15 +0000
@@ -0,0 +1,80 @@
+package org.hisp.dhis.mobile.connection.task;
+
+import java.io.DataInputStream;
+import java.util.Vector;
+
+import org.hisp.dhis.mobile.connection.ConnectionManager;
+import org.hisp.dhis.mobile.log.LogMan;
+import org.hisp.dhis.mobile.midlet.NameBasedMIDlet;
+import org.hisp.dhis.mobile.model.Patient;
+import org.hisp.dhis.mobile.model.PatientList;
+import org.hisp.dhis.mobile.recordstore.PatientRecordStore;
+
+import com.sun.lwuit.List;
+
+public class GetPatientsTask
+    extends AbstractTask
+{
+
+    private static final String CLASS_TAG = "GetPatientsTask";
+
+    private String patientIds;
+
+    private NameBasedMIDlet nameBasedMIDlet;
+
+    public GetPatientsTask()
+    {
+        this.nameBasedMIDlet = (NameBasedMIDlet) ConnectionManager.getDhisMIDlet();
+    }
+
+    public void run()
+    {
+        LogMan.log( LogMan.INFO, "Network," + CLASS_TAG, "Starting GetPatientsTask..." );
+        DataInputStream inputStream = null;
+
+        try
+        {
+            // search patient by id
+            inputStream = this.download( patientIds, "patientIds" );
+            PatientList patientlist = new PatientList();
+            patientlist.deSerialize( inputStream );
+
+            // Save patient to record store
+            Vector patients = patientlist.getPatientList();
+            for ( int i = 0; i < patients.size(); i++ )
+            {
+                PatientRecordStore.savePatient( (Patient) patients.elementAt( i ) );
+            }
+
+            nameBasedMIDlet.getAlertBoxView( "Instances saved", "Success" ).showView();
+        }
+        catch ( Exception e )
+        {
+            nameBasedMIDlet.getAlertBoxView(
+                "An error is encountered in downloading instances. Please try again later", "Error" ).showView();
+            e.printStackTrace();
+            LogMan.log( "Network," + CLASS_TAG, e );
+        }
+    }
+
+    public String getPatientIds()
+    {
+        return patientIds;
+    }
+
+    public void setPatientIds( String patientIds )
+    {
+        this.patientIds = patientIds;
+    }
+
+    public NameBasedMIDlet getNameBasedMIDlet()
+    {
+        return nameBasedMIDlet;
+    }
+
+    public void setNameBasedMIDlet( NameBasedMIDlet nameBasedMIDlet )
+    {
+        this.nameBasedMIDlet = nameBasedMIDlet;
+    }
+
+}

=== added file 'src/org/hisp/dhis/mobile/model/PatientList.java'
--- src/org/hisp/dhis/mobile/model/PatientList.java	1970-01-01 00:00:00 +0000
+++ src/org/hisp/dhis/mobile/model/PatientList.java	2014-05-28 16:22:15 +0000
@@ -0,0 +1,49 @@
+package org.hisp.dhis.mobile.model;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Vector;
+
+public class PatientList extends Model
+{
+    private Vector patientList;
+    
+    public PatientList()
+    {
+    }
+    
+    public Vector getPatientList()
+    {
+        return patientList;
+    }
+    
+    public void serialize( DataOutputStream dataOutputStream )
+        throws IOException
+    {
+        if ( patientList != null )
+        {
+            dataOutputStream.writeInt( patientList.size() );
+            for ( int i = 0; i <  patientList.size(); i++){
+                ((Patient)patientList.elementAt( i )).serialize( dataOutputStream );
+            }
+        }else{
+            dataOutputStream.writeInt( 0 );
+        }
+    }
+    
+    public void deSerialize( DataInputStream dataInputStream )
+        throws IOException
+    {
+        int temp = 0;
+        temp = dataInputStream.readInt();
+        if(temp > 0){
+            patientList = new Vector();
+            for(int i = 0; i < temp; i++){
+                Patient patient = new Patient();
+                patient.deSerialize( dataInputStream );
+                patientList.addElement( patient );
+            }
+        }
+    }
+}