← Back to team overview

dhis-mobile-devs team mailing list archive

[Branch ~dhis-mobile-devs/dhis-mobile/lwuit-tracking] Rev 235: Use TrackedEntityInstanceService.getTrackedEntityInstances( TrackedEntityInstanceQueryParams ) in...

 

------------------------------------------------------------
revno: 235
committer: sherylyn.marie
branch nick: lwuit-tracking
timestamp: Wed 2014-09-10 18:14:12 +0800
message:
  Use TrackedEntityInstanceService.getTrackedEntityInstances( TrackedEntityInstanceQueryParams ) in FindPatientInAdvanced()
modified:
  src/org/hisp/dhis/mobile/connection/task/FindPatientTask.java
  src/org/hisp/dhis/mobile/view/FindBeneficiaryView.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
=== modified file 'src/org/hisp/dhis/mobile/connection/task/FindPatientTask.java'
--- src/org/hisp/dhis/mobile/connection/task/FindPatientTask.java	2014-05-30 03:43:28 +0000
+++ src/org/hisp/dhis/mobile/connection/task/FindPatientTask.java	2014-09-10 10:14:12 +0000
@@ -113,15 +113,17 @@
             else
             {
                 message = e.getMessage();
-                Vector patientInfos = new Vector();
-                while ( message.length() > 0 )
-                {
-                    patientInfos.addElement( message.substring( 0, message.indexOf( "$" ) ) );
-                    message = message.substring( message.indexOf( "$" ) + 1, message.length() );
-                }
-                nameBasedMIDlet.getPersonListView().setPatientInfos( patientInfos );
-                patientInfos = null;
-                nameBasedMIDlet.getPersonListView().showView();
+                nameBasedMIDlet.getAlertBoxView( message, "Warning" ).showView();
+                nameBasedMIDlet.getFindBeneficiaryView().showView();
+//                Vector patientInfos = new Vector();
+//                while ( message.length() > 0 )
+//                {
+//                    patientInfos.addElement( message.substring( 0, message.indexOf( "$" ) ) );
+//                    message = message.substring( message.indexOf( "$" ) + 1, message.length() );
+//                }
+//                nameBasedMIDlet.getPersonListView().setPatientInfos( patientInfos );
+//                patientInfos = null;
+//                nameBasedMIDlet.getPersonListView().showView();
             }
         }
     }

=== modified file 'src/org/hisp/dhis/mobile/view/FindBeneficiaryView.java'
--- src/org/hisp/dhis/mobile/view/FindBeneficiaryView.java	2014-09-03 11:23:09 +0000
+++ src/org/hisp/dhis/mobile/view/FindBeneficiaryView.java	2014-09-10 10:14:12 +0000
@@ -34,6 +34,8 @@
 import org.hisp.dhis.mobile.midlet.NameBasedMIDlet;
 import org.hisp.dhis.mobile.model.Model;
 import org.hisp.dhis.mobile.model.OrgUnit;
+import org.hisp.dhis.mobile.model.PatientAttribute;
+import org.hisp.dhis.mobile.model.Program;
 import org.hisp.dhis.mobile.recordstore.OrgUnitRecordStore;
 import org.hisp.dhis.mobile.recordstore.ProgramRecordStore;
 import org.hisp.dhis.mobile.ui.Text;
@@ -77,6 +79,8 @@
 
     private TextArea notification;
 
+    private ComboBox attributeOptions;
+
     private ComboBox orgUnitOptions;
 
     private ComboBox programOptions;
@@ -87,6 +91,10 @@
 
     private String keyword;
 
+    private String query;
+
+    Vector attributeVector;
+
     Vector orgUnitVector;
 
     Vector programVector;
@@ -107,8 +115,10 @@
         txtSearchHint.setEditable( false );
         mainForm.addComponent( txtSearchHint );
 
+        mainForm.addComponent( getAttributeOptions() );
+        attributeOptions.requestFocus();
+
         mainForm.addComponent( getKeywordTextField() );
-        keywordTextField.requestFocus();
 
         TextArea txtSelectOrgUnit = new TextArea( Text.ORG_UNIT() );
         txtSelectOrgUnit.setEditable( false );
@@ -202,9 +212,10 @@
                     else if ( keyword.length() < MINIMUM_KEYWORD_LENGTH )
                     {
                         prepareView();
-                        getNotification().setText( "Keyword must be at least " + MINIMUM_KEYWORD_LENGTH + " characters." );
+                        getNotification().setText(
+                            "Keyword must be at least " + MINIMUM_KEYWORD_LENGTH + " characters." );
                         getMainForm().show();
-                        
+
                     }
                     else
                     {
@@ -225,18 +236,11 @@
                         }
                         else
                         {
-                            for ( int i = 0; i < orgUnitVector.size(); i++ )
-                            {
-                                if ( ((String) orgUnitOptions.getSelectedItem()).equals( ((OrgUnit) orgUnitVector
-                                    .elementAt( i )).getName() ) )
-                                {
-                                    nameBasedMIDlet.setCurrentOrgUnit( (OrgUnit) orgUnitVector.elementAt( i ) );
-                                    ConnectionManager.setUrl( nameBasedMIDlet.getCurrentOrgUnit()
-                                        .getFindPatientInAdvancedUrl() );
-                                    orgUnitIndex = i + 1;
-                                    break;
-                                }
-                            }
+                            nameBasedMIDlet.setCurrentOrgUnit( (OrgUnit) orgUnitVector.elementAt( orgUnitOptions
+                                .getSelectedIndex() - 1 ) );
+                            ConnectionManager
+                                .setUrl( nameBasedMIDlet.getCurrentOrgUnit().getFindPatientInAdvancedUrl() );
+                            orgUnitIndex = orgUnitOptions.getSelectedIndex() + 1;
                         }
 
                         // Program Selection
@@ -271,8 +275,17 @@
                         // }
                         // }
 
-                        ConnectionManager.findPatientByName( keyword );
+                        if ( attributeOptions.getSelectedItem().toString().equals( "All" ) )
+                        {
+                            query = "like:" + keyword;
+                        }
+                        else
+                        {
+                            query = attributeOptions.getSelectedItem().toString() + ":like:" + keyword;
+                        }
+                        ConnectionManager.findPatientByName( query );
                         mainForm = null;
+                        attributeOptions = null;
                         keywordTextField = null;
                         btnFind = null;
                         backCommand = null;
@@ -281,6 +294,7 @@
                         orgUnitVector = null;
                         programOptions = null;
                         programVector = null;
+                        query = null;
 
                         System.gc();
                     }
@@ -318,6 +332,85 @@
         this.backCommand = backCommand;
     }
 
+    public ComboBox getAttributeOptions()
+    {
+        if ( attributeOptions == null )
+        {
+            try
+            {
+                attributeOptions = new ComboBox();
+
+                attributeVector = new Vector();
+
+                programVector = ProgramRecordStore.getCurrentPrograms().getModels();
+
+                for ( int j = 0; j < programVector.size(); j++ )
+                {
+                    Program program = ProgramRecordStore.getProgram( ((Model) programVector.elementAt( j )).getId() );
+                    Vector patientAttributeVector = program.getProgramAttributes();
+                    if ( patientAttributeVector != null )
+                    {
+                        for ( int i = 0; i < patientAttributeVector.size(); i++ )
+                        {
+                            PatientAttribute patientAttribute = (PatientAttribute) patientAttributeVector.elementAt( i );
+                            if ( !attributeVectorContains( patientAttribute ) )
+                            {
+                                attributeVector.addElement( patientAttribute );
+                            }
+                        }
+                    }
+                }
+
+                attributeOptions.addItem( "All" );
+                for ( int i = 0; i < attributeVector.size(); i++ )
+                {
+                    attributeOptions.addItem( ((PatientAttribute) attributeVector.elementAt( i )).getName() );
+                }
+
+                attributeOptions.setHint( "Select attribute" );
+                ActionListener ae = new ActionListener()
+                {
+                    public void actionPerformed( ActionEvent arg0 )
+                    {
+                        int index = attributeOptions.getSelectedIndex();
+                        if ( index != 0
+                            && ((PatientAttribute) attributeVector.elementAt( index - 1 )).getType().equals( "date" ) )
+                        {
+                            keywordTextField.setHint( "YYYY-MM-dd" );
+                        }
+                        else
+                        {
+                            keywordTextField.setHint( "" );
+                        }
+                    }
+                };
+                attributeOptions.addActionListener( ae );
+            }
+            catch ( Exception e )
+            {
+                LogMan.log( "UI," + CLASS_TAG, e );
+                e.printStackTrace();
+            }
+        }
+
+        return attributeOptions;
+    }
+
+    private boolean attributeVectorContains( PatientAttribute patientAttribute )
+    {
+        if ( attributeVector != null )
+        {
+            for ( int i = 0; i < attributeVector.size(); i++ )
+            {
+                if ( ((PatientAttribute) attributeVector.elementAt( i )).getName().equals( patientAttribute.getName() ) )
+                {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     public ComboBox getOrgUnitOptions()
     {
         if ( orgUnitOptions == null )
@@ -392,6 +485,7 @@
         {
             nameBasedMIDlet.getTrackingMainMenuView().showView();
             mainForm = null;
+            attributeOptions = null;
             keywordTextField = null;
             btnFind = null;
             backCommand = null;
@@ -400,6 +494,7 @@
             orgUnitVector = null;
             programOptions = null;
             programVector = null;
+            query = null;
             System.gc();
         }
     }