dhis-mobile-devs team mailing list archive
-
dhis-mobile-devs team
-
Mailing list archive
-
Message #00431
[Branch ~dhis-mobile-devs/dhis-mobile/lwuit-tracking] Rev 238: Add Relationship Feature, fixed navigation from MessagingMenuView back to TrackingMainMenu
------------------------------------------------------------
revno: 238
committer: sherylyn.marie
branch nick: lwuit-tracking
timestamp: Sat 2014-09-13 19:27:25 +0800
message:
Add Relationship Feature, fixed navigation from MessagingMenuView back to TrackingMainMenu
added:
src/org/hisp/dhis/mobile/model/RelationshipType.java
src/org/hisp/dhis/mobile/recordstore/RelationshipTypeRecordStore.java
modified:
src/org/hisp/dhis/mobile/connection/task/AddRelationshipTask.java
src/org/hisp/dhis/mobile/connection/task/DownloadAllResourceTask.java
src/org/hisp/dhis/mobile/model/MobileModel.java
src/org/hisp/dhis/mobile/model/Patient.java
src/org/hisp/dhis/mobile/view/AddingRelationshipView.java
src/org/hisp/dhis/mobile/view/MessagingMenuView.java
src/org/hisp/dhis/mobile/view/PersonDashboardView.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/AddRelationshipTask.java'
--- src/org/hisp/dhis/mobile/connection/task/AddRelationshipTask.java 2014-04-03 01:58:41 +0000
+++ src/org/hisp/dhis/mobile/connection/task/AddRelationshipTask.java 2014-09-13 11:27:25 +0000
@@ -93,6 +93,9 @@
e.printStackTrace();
String message = null;
+
+ String personBName = enrollmentRelationship.getPersonBName();
+ enrollmentRelationship.setPersonBName( personBName.substring( personBName.lastIndexOf( ':' ) + 1 ) );
if ( e.getMessage().equalsIgnoreCase( "NO_BENEFICIARY_FOUND" ) )
{
=== modified file 'src/org/hisp/dhis/mobile/connection/task/DownloadAllResourceTask.java'
--- src/org/hisp/dhis/mobile/connection/task/DownloadAllResourceTask.java 2014-04-03 01:58:41 +0000
+++ src/org/hisp/dhis/mobile/connection/task/DownloadAllResourceTask.java 2014-09-13 11:27:25 +0000
@@ -32,6 +32,7 @@
import org.hisp.dhis.mobile.model.MobileModel;
import org.hisp.dhis.mobile.model.OrgUnit;
import org.hisp.dhis.mobile.recordstore.ProgramRecordStore;
+import org.hisp.dhis.mobile.recordstore.RelationshipTypeRecordStore;
public class DownloadAllResourceTask
extends AbstractTask
@@ -77,7 +78,7 @@
inputStream = this.download();
this.handleDownloadAllResource( inputStream );
ProgramRecordStore.savePrograms( mobileModel.getPrograms() );
-
+ RelationshipTypeRecordStore.saveRelationshipTypes( mobileModel.getRelationshipTypes() );
}
catch ( IOException e )
{
=== modified file 'src/org/hisp/dhis/mobile/model/MobileModel.java'
--- src/org/hisp/dhis/mobile/model/MobileModel.java 2013-07-17 03:33:24 +0000
+++ src/org/hisp/dhis/mobile/model/MobileModel.java 2014-09-13 11:27:25 +0000
@@ -44,6 +44,8 @@
private Date serverCurrentDate;
+ private Vector relationshipTypes;
+
public void serialize( DataOutputStream din )
throws IOException
{
@@ -63,6 +65,15 @@
}
this.serverCurrentDate = new Date( din.readLong() );
+
+ this.relationshipTypes = new Vector();
+ int numRelTypes = din.readInt();
+ for(int i=0; i<numRelTypes; i++)
+ {
+ RelationshipType relType = new RelationshipType();
+ relType.deSerialize( din );
+ relationshipTypes.addElement( relType );
+ }
}
public Vector getPrograms()
@@ -84,4 +95,14 @@
{
this.serverCurrentDate = serverCurrentDate;
}
+
+ public Vector getRelationshipTypes()
+ {
+ return relationshipTypes;
+ }
+
+ public void setRelationshipTypes(Vector relationshipTypes)
+ {
+ this.relationshipTypes = relationshipTypes;
+ }
}
=== modified file 'src/org/hisp/dhis/mobile/model/Patient.java'
--- src/org/hisp/dhis/mobile/model/Patient.java 2014-09-03 11:23:09 +0000
+++ src/org/hisp/dhis/mobile/model/Patient.java 2014-09-13 11:27:25 +0000
@@ -133,6 +133,20 @@
{
this.completedPrograms = completedPrograms;
}
+
+ public String getDisplayInListAttributeValues()
+ {
+ String name = "";
+ for ( int i = 0; i < getPatientAttValues().size(); i++ )
+ {
+ PatientAttribute patientAttribute = (PatientAttribute) getPatientAttValues().elementAt( i );
+ if(patientAttribute.isDisplayedInList())
+ {
+ name += patientAttribute.getValue() + " ";
+ }
+ }
+ return name.trim();
+ }
public void deSerialize( DataInputStream din )
throws IOException
=== added file 'src/org/hisp/dhis/mobile/model/RelationshipType.java'
--- src/org/hisp/dhis/mobile/model/RelationshipType.java 1970-01-01 00:00:00 +0000
+++ src/org/hisp/dhis/mobile/model/RelationshipType.java 2014-09-13 11:27:25 +0000
@@ -0,0 +1,83 @@
+package org.hisp.dhis.mobile.model;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class RelationshipType
+ extends Model
+{
+ private int id;
+
+ private String aIsToB;
+
+ private String bIsToA;
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public String getAIsToB()
+ {
+ return aIsToB;
+ }
+
+ public void setAIsToB( String aIsToB )
+ {
+ this.aIsToB = aIsToB;
+ }
+
+ public String getBIsToA()
+ {
+ return bIsToA;
+ }
+
+ public void setBIsToA( String bIsToA )
+ {
+ this.bIsToA = bIsToA;
+ }
+
+ public void serialize( DataOutputStream dataOutputStream )
+ throws IOException
+ {
+ dataOutputStream.writeInt( this.id );
+ dataOutputStream.writeUTF( getName() );
+ dataOutputStream.writeUTF( this.aIsToB );
+ dataOutputStream.writeUTF( this.bIsToA );
+ }
+
+ public void deSerialize( DataInputStream dataInputStream )
+ throws IOException
+ {
+ this.id = dataInputStream.readInt();
+ setName( dataInputStream.readUTF() );
+ this.aIsToB = dataInputStream.readUTF();
+ this.bIsToA = dataInputStream.readUTF();
+ }
+
+ public void serializeVersion2_8( DataOutputStream dataOutputStream )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void serializeVersion2_9( DataOutputStream dataOutputStream )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void serializeVersion2_10( DataOutputStream dataOutputStream )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ }
+}
=== added file 'src/org/hisp/dhis/mobile/recordstore/RelationshipTypeRecordStore.java'
--- src/org/hisp/dhis/mobile/recordstore/RelationshipTypeRecordStore.java 1970-01-01 00:00:00 +0000
+++ src/org/hisp/dhis/mobile/recordstore/RelationshipTypeRecordStore.java 2014-09-13 11:27:25 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.mobile.recordstore;
+
+import java.io.IOException;
+import java.util.Vector;
+
+import javax.microedition.rms.RecordEnumeration;
+import javax.microedition.rms.RecordStore;
+import javax.microedition.rms.RecordStoreException;
+import javax.microedition.rms.RecordStoreFullException;
+import javax.microedition.rms.RecordStoreNotFoundException;
+
+import org.hisp.dhis.mobile.model.OrgUnit;
+import org.hisp.dhis.mobile.model.Program;
+import org.hisp.dhis.mobile.model.RelationshipType;
+import org.hisp.dhis.mobile.util.SerializationUtil;
+
+public class RelationshipTypeRecordStore
+{
+ public static final String RELATIONSHIP_TYPE_DB = "RELATIONSHIP_TYPE";
+
+ public static boolean saveRelationshipTypes( Vector relTypeVector )
+ throws RecordStoreFullException, RecordStoreNotFoundException, RecordStoreException, IOException
+ {
+ for ( int i = 0; i < relTypeVector.size(); i++ )
+ {
+ RelationshipType relType = (RelationshipType) relTypeVector.elementAt( i );
+ if ( !saveRelationshipType( relType ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean saveRelationshipType( RelationshipType relType )
+ throws RecordStoreFullException, RecordStoreNotFoundException, RecordStoreException, IOException
+ {
+ RecordStore recordStore = null;
+ try
+ {
+ recordStore = RecordStore.openRecordStore( RELATIONSHIP_TYPE_DB, true );
+ byte[] bite = SerializationUtil.serialize( relType );
+ recordStore.addRecord( bite, 0, bite.length );
+ }
+ finally
+ {
+ recordStore.closeRecordStore();
+ System.gc();
+ }
+ return true;
+ }
+
+ public static Vector loadAllRelationshipType()
+ throws RecordStoreFullException, RecordStoreNotFoundException, RecordStoreException, IOException
+ {
+ Vector relTypeVector = new Vector();
+ try
+ {
+ RecordStore recordStore = RecordStore.openRecordStore( RELATIONSHIP_TYPE_DB, true );
+ RecordEnumeration recordEnum = recordStore.enumerateRecords( null, null, false );
+ while ( recordEnum.hasNextElement() )
+ {
+ RelationshipType relType = new RelationshipType();
+ SerializationUtil.deSerialize( relType, recordEnum.nextRecord() );
+ relTypeVector.addElement( relType );
+ }
+ recordEnum.destroy();
+ recordStore.closeRecordStore();
+ }
+ finally
+ {
+ System.gc();
+ }
+ return relTypeVector;
+ }
+
+ public static void deleteAllRelationshipType()
+ throws RecordStoreNotFoundException, RecordStoreException
+ {
+ RecordStore recordStore = RecordStore.openRecordStore( RELATIONSHIP_TYPE_DB, true );
+ if ( recordStore.getSize() > 0 )
+ {
+ recordStore.closeRecordStore();
+ RecordStore.deleteRecordStore( RELATIONSHIP_TYPE_DB );
+ }
+ }
+}
=== modified file 'src/org/hisp/dhis/mobile/view/AddingRelationshipView.java'
--- src/org/hisp/dhis/mobile/view/AddingRelationshipView.java 2013-04-22 08:32:16 +0000
+++ src/org/hisp/dhis/mobile/view/AddingRelationshipView.java 2014-09-13 11:27:25 +0000
@@ -31,9 +31,13 @@
import org.hisp.dhis.mobile.connection.ConnectionManager;
import org.hisp.dhis.mobile.midlet.DHISMIDlet;
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.model.Relationship;
import org.hisp.dhis.mobile.recordstore.OrgUnitRecordStore;
+import org.hisp.dhis.mobile.recordstore.ProgramRecordStore;
import org.hisp.dhis.mobile.ui.Text;
import org.hisp.dhis.mobile.util.TrackingUtils;
@@ -49,47 +53,60 @@
/**
* @author Nguyen Kim Lai
- *
+ *
* @version AddingRelationshipForm.java 10:11:49 AM Mar 18, 2013 $
*/
-public class AddingRelationshipView extends AbstractView implements ActionListener
+public class AddingRelationshipView
+ extends AbstractView
+ implements ActionListener
{
private NameBasedMIDlet nameBasedMIDlet;
-
- private Command addCommand;
+
+ private Command findCommand;
private Command backCommand;
-
+
private Form mainForm;
-
+
private ComboBox relationshipOptions;
-
+
+ private ComboBox attributeOptions;
+
+ private Vector attributeVector;
+
private TextField keywordTextField;
-
+
private Relationship enrollmentRelationship;
-
+
private TextArea notification;
-
+
private ComboBox orgUnitOptions;
-
+
Vector orgUnitVector;
+ private int relationshipIndex = 0;
+
+ private int orgUnitIndex = 0;
+
+ private int attributeIndex = 0;
+
public AddingRelationshipView( DHISMIDlet dhisMIDlet )
{
super( dhisMIDlet );
- this.nameBasedMIDlet = ( NameBasedMIDlet ) dhisMIDlet;
+ this.nameBasedMIDlet = (NameBasedMIDlet) dhisMIDlet;
}
public void actionPerformed( ActionEvent ae )
{
- if ( ae.getCommand().getCommandName().equals( Text.ADD() ) )
+ if ( ae.getCommand().getCommandName().equals( Text.FIND() ) )
{
nameBasedMIDlet.getWaitingView().showView();
String keyWord = this.getKeywordTextField().getText().trim();
enrollmentRelationship.setPersonBName( keyWord );
enrollmentRelationship.setChosenRelationship( (String) relationshipOptions.getSelectedItem() );
-
- if( keyWord.equals( "" ) )
+ relationshipIndex = relationshipOptions.getSelectedIndex();
+
+ if ( keyWord.equals( "" ) )
{
this.prepareView();
this.getNotification().setText( "(*) : Required Field" );
@@ -97,50 +114,63 @@
}
else
{
+ String query = "";
+ if ( attributeOptions.getSelectedItem().toString().equals( "All" ) )
+ {
+ query = "like:" + keyWord;
+ attributeIndex = 0;
+ }
+ else
+ {
+ query = attributeOptions.getSelectedItem().toString() + ":like:" + keyWord;
+ attributeIndex = attributeOptions.getSelectedIndex();
+ }
+ enrollmentRelationship.setPersonBName( query );
+
if ( ((String) orgUnitOptions.getSelectedItem()).equals( "All" ) )
{
String tempURL = nameBasedMIDlet.getCurrentOrgUnit().getAddRelationshipUrl();
-
+
ConnectionManager.setUrl( TrackingUtils.getUrlForSelectionAll( tempURL ) );
-
+
tempURL = null;
+ orgUnitIndex = orgUnitOptions.getSelectedIndex();
}
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().getAddRelationshipUrl() );
- break;
- }
- }
+ nameBasedMIDlet.setCurrentOrgUnit( (OrgUnit) orgUnitVector.elementAt( orgUnitOptions
+ .getSelectedIndex() ) );
+ ConnectionManager.setUrl( nameBasedMIDlet.getCurrentOrgUnit().getAddRelationshipUrl() );
+ orgUnitIndex = orgUnitOptions.getSelectedIndex();
}
-
+
ConnectionManager.addRelationship( enrollmentRelationship );
- addCommand = null;
+ findCommand = null;
backCommand = null;
mainForm = null;
relationshipOptions = null;
+ attributeOptions = null;
keywordTextField = null;
enrollmentRelationship = null;
notification = null;
orgUnitOptions = null;
orgUnitVector = null;
-
+
System.gc();
}
}
else
{
- addCommand = null;
+ findCommand = null;
backCommand = null;
mainForm = null;
relationshipOptions = null;
+ attributeOptions = null;
keywordTextField = null;
enrollmentRelationship = null;
notification = null;
+ orgUnitOptions = null;
+ orgUnitVector = null;
nameBasedMIDlet.getPersonDashboardView().showView();
}
}
@@ -152,21 +182,25 @@
mainForm.removeAll();
TextArea txtPatientAName = new TextArea( enrollmentRelationship.getPersonAName() + " is" );
txtPatientAName.setEditable( false );
+ txtPatientAName.setFocusable( false );
mainForm.addComponent( txtPatientAName );
-
+
mainForm.addComponent( getRelationshipOptions() );
relationshipOptions.requestFocus();
-
- TextArea txtSearchHint = new TextArea( "of: ( please enter a FULL name ) *" );
+
+ TextArea txtSearchHint = new TextArea( "of: *" );
txtSearchHint.setEditable( false );
+ txtSearchHint.setFocusable( false );
mainForm.addComponent( txtSearchHint );
+ mainForm.addComponent( getAttributeOptions() );
mainForm.addComponent( this.getKeywordTextField() );
-
+
TextArea txtSelectOrgUnit = new TextArea( "Select Organisation Unit" );
txtSearchHint.setEditable( false );
+ txtSearchHint.setFocusable( false );
mainForm.addComponent( txtSelectOrgUnit );
mainForm.addComponent( getOrgUnitOptions() );
-
+
mainForm.addComponent( this.getNotification() );
}
@@ -182,10 +216,10 @@
{
mainForm = new Form( "Add Relationship" );
mainForm.setLayout( new BoxLayout( BoxLayout.Y_AXIS ) );
- mainForm.setTransitionOutAnimator( CommonTransitions.createSlide(
- CommonTransitions.SLIDE_HORIZONTAL, true, 200 ) );
+ mainForm.setTransitionOutAnimator( CommonTransitions.createSlide( CommonTransitions.SLIDE_HORIZONTAL, true,
+ 200 ) );
mainForm.addCommand( this.getBackCommand() );
- mainForm.addCommand( this.getAddCommand() );
+ mainForm.addCommand( this.getFindCommand() );
mainForm.addCommandListener( this );
}
return mainForm;
@@ -206,25 +240,25 @@
this.nameBasedMIDlet = nameBasedMIDlet;
}
- public Command getAddCommand()
+ public Command getFindCommand()
{
- if ( addCommand == null )
+ if ( findCommand == null )
{
- addCommand = new Command( Text.ADD() );
+ findCommand = new Command( Text.FIND() );
}
- return addCommand;
+ return findCommand;
}
- public void setAddCommand( Command addCommand )
+ public void setFindCommand( Command findCommand )
{
- this.addCommand = addCommand;
+ this.findCommand = findCommand;
}
public Command getBackCommand()
{
if ( backCommand == null )
{
- backCommand = new Command ( Text.BACK() );
+ backCommand = new Command( Text.BACK() );
}
return backCommand;
}
@@ -263,6 +297,7 @@
relationshipOptions = new ComboBox();
relationshipOptions.addItem( this.enrollmentRelationship.getaIsToB() );
relationshipOptions.addItem( this.enrollmentRelationship.getbIsToA() );
+ relationshipOptions.setSelectedIndex( relationshipIndex );
return relationshipOptions;
}
@@ -270,7 +305,86 @@
{
this.relationshipOptions = relationshipOptions;
}
-
+
+ public ComboBox getAttributeOptions()
+ {
+ if ( attributeOptions == null )
+ {
+ try
+ {
+ attributeOptions = new ComboBox();
+
+ attributeVector = new Vector();
+
+ 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 );
+ attributeOptions.setSelectedIndex( attributeIndex );
+ }
+ catch ( Exception 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 TextArea getNotification()
{
if ( notification == null )
@@ -286,15 +400,15 @@
{
this.notification = notification;
}
-
+
public ComboBox getOrgUnitOptions()
{
if ( orgUnitOptions == null )
{
orgUnitOptions = new ComboBox();
-
+
orgUnitVector = null;
-
+
try
{
orgUnitVector = OrgUnitRecordStore.loadAllOrgUnit();
@@ -306,9 +420,10 @@
}
for ( int i = 0; i < orgUnitVector.size(); i++ )
{
- orgUnitOptions.addItem( (( OrgUnit )orgUnitVector.elementAt( i )).getName() );
+ orgUnitOptions.addItem( ((OrgUnit) orgUnitVector.elementAt( i )).getName() );
}
orgUnitOptions.addItem( "All" );
+ orgUnitOptions.setSelectedIndex( orgUnitIndex );
}
return orgUnitOptions;
}
@@ -317,4 +432,11 @@
{
this.orgUnitOptions = orgUnitOptions;
}
+
+ public void resetIndexes()
+ {
+ relationshipIndex = 0;
+ attributeIndex = 0;
+ orgUnitIndex = 0;
+ }
}
=== modified file 'src/org/hisp/dhis/mobile/view/MessagingMenuView.java'
--- src/org/hisp/dhis/mobile/view/MessagingMenuView.java 2014-06-05 06:58:28 +0000
+++ src/org/hisp/dhis/mobile/view/MessagingMenuView.java 2014-09-13 11:27:25 +0000
@@ -96,6 +96,15 @@
{
dhisMIDlet.exitMIDlet();
}
+ else if (ae.getCommand().getCommandName().equals( Text.BACK() ))
+ {
+ nameBasedMidlet.getWaitingView().showView();
+ nameBasedMidlet.getTrackingMainMenuView().showView();
+ menuList = null;
+ menuForm = null;
+ backCommand = null;
+ warningDialog = null;
+ }
else
{
this.showView();
=== modified file 'src/org/hisp/dhis/mobile/view/PersonDashboardView.java'
--- src/org/hisp/dhis/mobile/view/PersonDashboardView.java 2014-09-11 13:17:55 +0000
+++ src/org/hisp/dhis/mobile/view/PersonDashboardView.java 2014-09-13 11:27:25 +0000
@@ -46,8 +46,10 @@
import org.hisp.dhis.mobile.model.ProgramInstance;
import org.hisp.dhis.mobile.model.ProgramStage;
import org.hisp.dhis.mobile.model.Relationship;
+import org.hisp.dhis.mobile.model.RelationshipType;
import org.hisp.dhis.mobile.recordstore.PatientRecordStore;
import org.hisp.dhis.mobile.recordstore.ProgramRecordStore;
+import org.hisp.dhis.mobile.recordstore.RelationshipTypeRecordStore;
import org.hisp.dhis.mobile.ui.Text;
import com.sun.lwuit.Button;
@@ -166,19 +168,16 @@
}
// show enrollment relationship
- // Label lblEnrollmentRelationship = new Label( "Add Relationships" );
- // lblEnrollmentRelationship.setUnselectedStyle( labelStyle );
- // lblEnrollmentRelationship.setSelectedStyle( labelStyle );
- // mainForm.addComponent( lblEnrollmentRelationship );
- // this.prepareEnrollmentRelationships();
+ Label lblEnrollmentRelationship = new Label( "Add Relative" );
+ lblEnrollmentRelationship.setUnselectedStyle( labelStyle );
+ lblEnrollmentRelationship.setSelectedStyle( labelStyle );
+ mainForm.addComponent( lblEnrollmentRelationship );
+// this.prepareAddRelativeOptions();
+ this.prepareEnrollmentRelationships();
- Label spaceLabel1 = new Label( " " );
- Label spaceLabel2 = new Label( " " );
- Label spaceLabel3 = new Label( " " );
- spaceLabel3.setFocusable( true );
- mainForm.addComponent( spaceLabel1 );
- mainForm.addComponent( spaceLabel2 );
- mainForm.addComponent( spaceLabel3 );
+// Label spaceLabel = new Label( " " );
+// spaceLabel.setFocusable( true );
+// mainForm.addComponent( spaceLabel );
}
public void showView()
@@ -463,7 +462,7 @@
{
final Relationship relationship = (Relationship) patient.getRelationships().elementAt( i );
- LinkButton relationshipLink = new LinkButton( relationship.getName() + " of "
+ LinkButton relationshipLink = new LinkButton( relationship.getbIsToA() + ": "
+ relationship.getPersonBName() );
relationshipLink.addActionListener( new ActionListener()
@@ -486,38 +485,48 @@
public void prepareEnrollmentRelationships()
{
- // if ( patient.getEnrollmentRelationships() != null )
- // {
- // for ( int i = 0; i < patient.getEnrollmentRelationships().size(); i++
- // )
- // {
- // final Relationship enrollmentRelationship = (Relationship)
- // patient.getEnrollmentRelationships()
- // .elementAt( i );
- //
- // LinkButton enrollmentRelationshipLink = new LinkButton(
- // enrollmentRelationship.getName() );
- //
- // enrollmentRelationshipLink.addActionListener( new ActionListener()
- // {
- //
- // public void actionPerformed( ActionEvent ae )
- // {
- // enrollmentRelationship.setPersonAName( patient.getName() );
- // enrollmentRelationship.setPersonAId( patient.getId() );
- // namebasedMidlet.getAddingRelationshipView().setEnrollmentRelationship(
- // enrollmentRelationship );
- // namebasedMidlet.getAddingRelationshipView().showView();
- // }
- // } );
- // mainForm.addComponent( enrollmentRelationshipLink );
- // }
- // }
- // else
- // {
- // LinkButton relationshipLink = new LinkButton( "Not Available" );
- // mainForm.addComponent( relationshipLink );
- // }
+ Vector relTypes = null;
+ try
+ {
+ relTypes = RelationshipTypeRecordStore.loadAllRelationshipType();
+ }
+ catch ( Exception e )
+ {
+ LogMan.log( "UI," + CLASS_TAG, e );
+ e.printStackTrace();
+ }
+ if ( relTypes == null || relTypes.size() > 0 )
+ {
+ for ( int i = 0; i < relTypes.size(); i++ )
+ {
+ final RelationshipType relType = (RelationshipType) relTypes.elementAt( i );
+
+ final Relationship enrollmentRelationship = new Relationship();
+ enrollmentRelationship.setaIsToB( relType.getAIsToB() );
+ enrollmentRelationship.setbIsToA( relType.getBIsToA() );
+ enrollmentRelationship.setId( relType.getId() );
+ enrollmentRelationship.setName( relType.getName() );
+
+ LinkButton enrollmentRelationshipLink = new LinkButton( enrollmentRelationship.getName() );
+ enrollmentRelationshipLink.addActionListener( new ActionListener()
+ {
+ public void actionPerformed( ActionEvent ae )
+ {
+ enrollmentRelationship.setPersonAId( patient.getId() );
+ enrollmentRelationship.setPersonAName( patient.getDisplayInListAttributeValues() );
+ namebasedMidlet.getAddingRelationshipView().setEnrollmentRelationship( enrollmentRelationship );
+ namebasedMidlet.getAddingRelationshipView().resetIndexes();
+ namebasedMidlet.getAddingRelationshipView().showView();
+ }
+ } );
+ mainForm.addComponent( enrollmentRelationshipLink );
+ }
+ }
+ else
+ {
+ LinkButton relationshipLink = new LinkButton( "Not Available" );
+ mainForm.addComponent( relationshipLink );
+ }
}
public void prepareCompletedPrograms()