← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16713: Propagate fix from DHIS 2.16 (Rev. 16417 and 16423)

 

------------------------------------------------------------
revno: 16713
committer: sherylyn.marie
branch nick: dhis2
timestamp: Sun 2014-09-14 00:17:05 +0800
message:
  Propagate fix from DHIS 2.16 (Rev. 16417 and 16423)
added:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/RelationshipType.java
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/IProgramService.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/MobileModel.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java


--
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-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/IProgramService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/IProgramService.java	2014-05-20 15:38:30 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/IProgramService.java	2014-09-13 16:17:05 +0000
@@ -32,6 +32,7 @@
 
 import org.hisp.dhis.api.mobile.model.ModelList;
 import org.hisp.dhis.api.mobile.model.Program;
+import org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 
 public interface IProgramService
@@ -45,5 +46,7 @@
     org.hisp.dhis.api.mobile.model.LWUITmodel.Program getProgramLWUIT( int programId );
 
     List<Program> updateProgram( ModelList programsFromClient, String localeString, OrganisationUnit unit );
+    
+    List<RelationshipType> getAllRelationshipTypes();
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/MobileModel.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/MobileModel.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/MobileModel.java	2014-09-13 16:17:05 +0000
@@ -47,6 +47,8 @@
     private String clientVersion;
 
     private List<Program> programs;
+    
+    private List<RelationshipType> relationshipTypes;
 
     private Date serverCurrentDate;
 
@@ -68,6 +70,19 @@
         }
         // Write current server's date
         dout.writeLong( serverCurrentDate.getTime() );
+        
+        if(relationshipTypes == null)
+        {
+            dout.writeInt( 0 );
+        }
+        else
+        {
+            dout.writeInt( relationshipTypes.size() );
+            for (RelationshipType relType:relationshipTypes)
+            {
+                relType.serialize( dout );
+            }
+        }
     }
 
     public List<Program> getPrograms()
@@ -99,6 +114,16 @@
     {
         this.clientVersion = clientVersion;
     }
+    
+    public List<RelationshipType> getRelationshipTypes()
+    {
+        return relationshipTypes;
+    }
+    
+    public void setRelationshipTypes(List<RelationshipType> relationshipTypes)
+    {
+        this.relationshipTypes = relationshipTypes;
+    }
 
     @Override
     public void deSerialize( DataInputStream dataInputStream )

=== added file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/RelationshipType.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/RelationshipType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/RelationshipType.java	2014-09-13 16:17:05 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.api.mobile.model.LWUITmodel;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.hisp.dhis.api.mobile.model.Model;
+
+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( this.getName() );
+        dataOutputStream.writeUTF( this.aIsToB );
+        dataOutputStream.writeUTF( this.bIsToA );
+    }
+    
+    public void deSerialize( DataInputStream dataInputStream )
+        throws IOException
+    {
+        this.id = dataInputStream.readInt();
+        this.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
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-09-10 13:08:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-09-13 16:17:05 +0000
@@ -828,8 +828,7 @@
         patientModel.setCompletedPrograms( mobileCompletedProgramInstanceList );
 
         // Set Relationship
-        List<Relationship> relationships = new ArrayList<>(
-            relationshipService.getRelationshipsForTrackedEntityInstance( patient ) );
+        Collection<Relationship> relationships = relationshipService.getRelationshipsForTrackedEntityInstance( patient );
         List<org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship> relationshipList = new ArrayList<>();
 
         for ( Relationship eachRelationship : relationships )
@@ -839,15 +838,34 @@
             if ( eachRelationship.getEntityInstanceA().getId() == patient.getId() )
             {
                 relationshipMobile.setName( eachRelationship.getRelationshipType().getaIsToB() );
-                relationshipMobile.setPersonBName( eachRelationship.getEntityInstanceB().getName() );
+                relationshipMobile.setaIsToB( eachRelationship.getRelationshipType().getaIsToB() );
+                relationshipMobile.setbIsToA( eachRelationship.getRelationshipType().getbIsToA() );
                 relationshipMobile.setPersonBId( eachRelationship.getEntityInstanceB().getId() );
             }
             else
             {
                 relationshipMobile.setName( eachRelationship.getRelationshipType().getbIsToA() );
-                relationshipMobile.setPersonBName( eachRelationship.getEntityInstanceA().getName() );
+                relationshipMobile.setaIsToB( eachRelationship.getRelationshipType().getbIsToA() );
+                relationshipMobile.setbIsToA( eachRelationship.getRelationshipType().getaIsToB() );
                 relationshipMobile.setPersonBId( eachRelationship.getEntityInstanceA().getId() );
             }
+            
+            // get relative's name
+            TrackedEntityInstance relative = entityInstanceService.getTrackedEntityInstance( relationshipMobile
+                .getPersonBId() );
+            List<TrackedEntityAttributeValue> attributes = new ArrayList<TrackedEntityAttributeValue>(
+                relative.getAttributeValues() );
+
+            String relativeName = "";
+            for ( TrackedEntityAttributeValue value : attributes )
+            {
+                if ( value != null && value.getAttribute().getDisplayInListNoProgram() )
+                {
+                    relativeName += value.getValue() + " ";
+                }
+            }
+            relationshipMobile.setPersonBName( relativeName );
+            
             relationshipList.add( relationshipMobile );
         }
         patientModel.setRelationships( relationshipList );
@@ -1078,29 +1096,15 @@
         }
         else
         {
-            List<TrackedEntityInstance> patients = new ArrayList<>();
-
-            // remove the own searcher
-            patients = removeIfDuplicated( patients, enrollmentRelationship.getPersonAId() );
-
-            if ( patients.size() > 1 )
-            {
-                String patientsInfo = "";
-
-                for ( TrackedEntityInstance each : patients )
-                {
-                    patientsInfo += each.getId() + "/" + each.getName() + "$";
-                }
-
-                throw new NotAllowedException( patientsInfo );
-            }
-            else if ( patients.size() == 0 )
+            String instanceInfo = findPatientInAdvanced( enrollmentRelationship.getPersonBName(), orgUnitId,
+                0 );
+            if ( instanceInfo == null || instanceInfo.trim().length() == 0 )
             {
                 throw NotAllowedException.NO_BENEFICIARY_FOUND;
             }
             else
             {
-                patientB = patients.get( 0 );
+                throw new NotAllowedException( instanceInfo );
             }
         }
         TrackedEntityInstance patientA = entityInstanceService.getTrackedEntityInstance( enrollmentRelationship
@@ -1544,7 +1548,10 @@
             param.addAttribute( queryItem );
         }
 
-        param.setProgram( programService.getProgram( programId ) );
+        if ( programId != 0 )
+        {
+            param.setProgram( programService.getProgram( programId ) );
+        }
 
         if ( orgUnitId != 0 )
         {
@@ -1633,7 +1640,13 @@
                 instanceInfo += te.getDisplayName() + "$";
             }
 
-            instanceInfo += (String) row.get( instanceIndex ) + "/";
+            // NOTE: this line should be here but because the mobile client uses
+            // the int TEI id, we will temprarily get the int id for now.
+            // instanceInfo += (String) row.get( instanceIndex ) + "/";
+                        
+            TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance( (String) row.get( instanceIndex ) );
+            instanceInfo += tei.getId() + "/";
+            //end of temproary fix
 
             String attText = "";
             for ( Integer attIndex : attributesIndex )

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java	2014-09-13 16:17:05 +0000
@@ -45,7 +45,10 @@
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageSection;
 import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Required;
 
 public class DefaultProgramService
@@ -57,6 +60,9 @@
 
     private org.hisp.dhis.program.ProgramService programService;
 
+    @Autowired
+    private RelationshipTypeService relationshipTypeService;
+
     // -------------------------------------------------------------------------
     // ProgramService
     // -------------------------------------------------------------------------
@@ -322,7 +328,7 @@
             {
                 optionSet.setId( pa.getOptionSet().getId() );
                 optionSet.setName( pa.getOptionSet().getName() );
-//                optionSet.setOptions( pa.getOptionSet().getOptions() );
+                // optionSet.setOptions( pa.getOptionSet().getOptions() );
 
                 mobileAttribute.setOptionSet( optionSet );
             }
@@ -336,4 +342,31 @@
     {
         this.programService = programService;
     }
+
+    @Override
+    public List<org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType> getAllRelationshipTypes()
+    {
+        try
+        {
+            List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>(
+                relationshipTypeService.getAllRelationshipTypes() );
+
+            List<org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType> mobileRelationshipTypes = new ArrayList<org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType>();
+            for ( RelationshipType relType : relationshipTypes )
+            {
+                org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType mobileRelType = new org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType();
+                mobileRelType.setId( relType.getId() );
+                mobileRelType.setName( relType.getName() );
+                mobileRelType.setAIsToB( relType.getaIsToB() );
+                mobileRelType.setBIsToA( relType.getbIsToA() );
+                mobileRelationshipTypes.add( mobileRelType );
+            }
+            return mobileRelationshipTypes;
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2014-09-10 13:08:18 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2014-09-13 16:17:05 +0000
@@ -56,8 +56,8 @@
 import org.hisp.dhis.api.mobile.model.LWUITmodel.LostEvent;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Notification;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Patient;
+import org.hisp.dhis.api.mobile.model.LWUITmodel.PatientIdentifierAndAttribute;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList;
-import org.hisp.dhis.api.mobile.model.LWUITmodel.PatientIdentifierAndAttribute;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.Program;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramInstance;
 import org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage;
@@ -65,6 +65,7 @@
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.smscommand.SMSCommandService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -89,6 +90,9 @@
 
     @Autowired
     private IProgramService programService;
+    
+    @Autowired
+    private RelationshipTypeService relationshipTypeService;
 
     @Autowired
     private FacilityReportingService facilityReportingService;
@@ -349,6 +353,7 @@
         OrganisationUnit unit = getUnit( id );
         mobileModel.setPrograms( programService.getProgramsLWUIT( unit ) );
         mobileModel.setServerCurrentDate( new Date() );
+        mobileModel.setRelationshipTypes( programService.getAllRelationshipTypes() );
         return mobileModel;
     }