← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11545: Add link between an event and an person

 

------------------------------------------------------------
revno: 11545
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-07-31 13:51:17 +0700
message:
  Add link between an event and an person
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddRelationshipPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipPatientForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationshipPatient.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonProgramStage.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStage.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm


--
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-api/src/main/java/org/hisp/dhis/program/ProgramStage.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2013-05-17 03:29:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2013-07-31 06:51:17 +0000
@@ -87,6 +87,8 @@
     private Boolean displayGenerateEventBox = true;
     
     private Boolean captureCoordinates = false;
+    
+    private Boolean relatedPatient = false;
 
     // -------------------------------------------------------------------------
     // Constructors
@@ -348,5 +350,15 @@
     {
         this.captureCoordinates = captureCoordinates;
     }
+
+    public Boolean getRelatedPatient()
+    {
+        return relatedPatient;
+    }
+
+    public void setRelatedPatient( Boolean relatedPatient )
+    {
+        this.relatedPatient = relatedPatient;
+    }
     
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2013-07-04 06:19:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2013-07-31 06:51:17 +0000
@@ -26,16 +26,17 @@
  */
 package org.hisp.dhis.program;
 
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patientcomment.PatientComment;
 import org.hisp.dhis.sms.outbound.OutboundSms;
 
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
 /**
  * @author Abyot Asalefew
  * @version $Id$
@@ -80,6 +81,8 @@
     private String completedUser;
 
     private Date completedDate;
+    
+    private Set<Patient> patients;
 
     // -------------------------------------------------------------------------
     // Constructors
@@ -291,6 +294,16 @@
         this.coordinates = coordinates;
     }
 
+    public Set<Patient> getPatients()
+    {
+        return patients;
+    }
+
+    public void setPatients( Set<Patient> patients )
+    {
+        this.patients = patients;
+    }
+
     public Integer getEventStatus()
     {
         if ( this.status != null )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-07-25 02:32:32 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-07-31 06:51:17 +0000
@@ -222,6 +222,7 @@
         executeSql( "update program set useBirthDateAsIncidentDate = false where useBirthDateAsIncidentDate is null");
         executeSql( "update program set useBirthDateAsEnrollmentDate = false where useBirthDateAsEnrollmentDate is null");
         executeSql( "update program set selectEnrollmentDatesInFuture = true where selectEnrollmentDatesInFuture is null");
+        executeSql( "update programstage set relatedPatient = false where relatedPatient is null");
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml	2013-04-18 09:21:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml	2013-07-31 06:51:17 +0000
@@ -56,6 +56,8 @@
 		<property name="displayGenerateEventBox" />
 
 		<property name="captureCoordinates" />
+		
+		<property name="relatedPatient" />
 
 	</class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml	2013-07-04 06:19:49 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml	2013-07-31 06:51:17 +0000
@@ -50,5 +50,10 @@
      
     <property name="completedDate" />
     
+    <set name="patients" table="programstageinstance_patients">
+      <key column="programstageinstanceid" />
+      <many-to-many class="org.hisp.dhis.patient.Patient" column="patientid"/>
+    </set>
+    
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddRelationshipPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddRelationshipPatientAction.java	2013-05-16 08:06:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddRelationshipPatientAction.java	2013-07-31 06:51:17 +0000
@@ -27,6 +27,9 @@
 package org.hisp.dhis.caseentry.action.patient;
 
 import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -49,10 +52,14 @@
 import org.hisp.dhis.patient.util.PatientIdentifierGenerator;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.user.UserService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -87,6 +94,16 @@
 
     private RelationshipTypeService relationshipTypeService;
 
+    private ProgramStageInstanceService programStageInstanceService;
+
+    private SystemSettingManager systemSettingManager;
+    
+    private UserService userService;
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -95,30 +112,46 @@
 
     private String birthDate;
 
-    private char ageType;
-
     private Integer age;
 
-    private Character dobType;
+    private Boolean verified;
 
     private String gender;
 
-    private String phoneNumber;
+    private String[] phoneNumber;
 
     private String registrationDate;
 
     private boolean underAge;
 
+    private Integer healthWorker;
+
+    private boolean isDead;
+
+    private String deathDate;
+
     private Integer relationshipId;
 
     private Integer relationshipTypeId;
 
     private boolean relationshipFromA;
 
+    private Integer programStageInstanceId;
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
 
+    public void setProgramStageInstanceId( Integer programStageInstanceId )
+    {
+        this.programStageInstanceId = programStageInstanceId;
+    }
+
+    public void setUserService( UserService userService )
+    {
+        this.userService = userService;
+    }
+
     private Patient patient;
 
     public Patient getPatient()
@@ -140,65 +173,119 @@
         // Set FirstName, MiddleName, LastName by FullName
         // ---------------------------------------------------------------------
 
-        fullName = fullName.trim();
-
-        int startIndex = fullName.indexOf( ' ' );
-        int endIndex = fullName.lastIndexOf( ' ' );
-
-        String firstName = fullName.toString();
-        String middleName = "";
-        String lastName = "";
-
-        if ( fullName.indexOf( ' ' ) != -1 )
+        if ( fullName != null )
         {
-            firstName = fullName.substring( 0, startIndex );
-            if ( startIndex == endIndex )
-            {
-                middleName = "";
-                lastName = fullName.substring( startIndex + 1, fullName.length() );
-            }
-            else
-            {
-                middleName = fullName.substring( startIndex + 1, endIndex );
-                lastName = fullName.substring( endIndex + 1, fullName.length() );
-            }
+            fullName = fullName.trim();
+
+            int startIndex = fullName.indexOf( ' ' );
+            int endIndex = fullName.lastIndexOf( ' ' );
+
+            String firstName = fullName.toString();
+            String middleName = "";
+            String lastName = "";
+
+            if ( fullName.indexOf( ' ' ) != -1 )
+            {
+                firstName = fullName.substring( 0, startIndex );
+                if ( startIndex == endIndex )
+                {
+                    middleName = "";
+                    lastName = fullName.substring( startIndex + 1, fullName.length() );
+                }
+                else
+                {
+                    middleName = fullName.substring( startIndex + 1, endIndex );
+                    lastName = fullName.substring( endIndex + 1, fullName.length() );
+                }
+            }
+
+            patient.setFirstName( firstName );
+            patient.setMiddleName( middleName );
+            patient.setLastName( lastName );
         }
 
-        patient.setFirstName( firstName );
-        patient.setMiddleName( middleName );
-        patient.setLastName( lastName );
-
         // ---------------------------------------------------------------------
         // Set Other information for patient
         // ---------------------------------------------------------------------
 
+        String phone = "";
+
+        for ( String _phoneNumber : phoneNumber )
+        {
+            _phoneNumber = (_phoneNumber != null && _phoneNumber.isEmpty() && _phoneNumber.trim().equals(
+                systemSettingManager.getSystemSetting( SystemSettingManager.KEY_PHONE_NUMBER_AREA_CODE ) )) ? null
+                : _phoneNumber;
+            if ( _phoneNumber != null )
+            {
+                phone += _phoneNumber + ";";
+            }
+        }
+
+        phone = (phone.isEmpty()) ? null : phone.substring( 0, phone.length() - 1 );
+
+        patient.setPhoneNumber( phone );
         patient.setGender( gender );
         patient.setIsDead( false );
-        patient.setPhoneNumber( phoneNumber );
         patient.setUnderAge( underAge );
         patient.setOrganisationUnit( organisationUnit );
-
-        if ( dobType == Patient.DOB_TYPE_VERIFIED || dobType == Patient.DOB_TYPE_DECLARED )
-        {
-            birthDate = birthDate.trim();
-            patient.setBirthDate( format.parseDate( birthDate ) );
+        patient.setIsDead( isDead );
+        if ( deathDate != null )
+        {
+            deathDate = deathDate.trim();
+            patient.setDeathDate( format.parseDate( deathDate ) );
+        }
+
+        if ( healthWorker != null )
+        {
+            patient.setHealthWorker( userService.getUser( healthWorker ) );
+        }
+
+        Date _birthDate = new Date();
+        if ( birthDate != null || age != null )
+        {
+            verified = (verified == null) ? false : verified;
+
+            Character dobType = (verified) ? Patient.DOB_TYPE_VERIFIED : Patient.DOB_TYPE_DECLARED;
+
+            if ( !verified && age != null )
+            {
+                dobType = 'A';
+            }
+
+            if ( dobType == Patient.DOB_TYPE_VERIFIED || dobType == Patient.DOB_TYPE_DECLARED )
+            {
+                birthDate = birthDate.trim();
+                patient.setBirthDate( format.parseDate( birthDate ) );
+            }
+            else
+            {
+                patient.setBirthDateFromAge( age.intValue(), Patient.AGE_TYPE_YEAR );
+            }
+
+            _birthDate = patient.getBirthDate();
+            patient.setDobType( dobType );
+        }
+
+        // -----------------------------------------------------------------------------
+        // Registration Date
+        // -----------------------------------------------------------------------------
+
+        if ( registrationDate == null )
+        {
+            patient.setRegistrationDate( new Date() );
         }
         else
         {
-            patient.setBirthDateFromAge( age.intValue(), ageType );
+            patient.setRegistrationDate( format.parseDate( registrationDate ) );
         }
 
-        patient.setDobType( dobType );
-
-        patient.setRegistrationDate( format.parseDate( registrationDate ) );
-
         // ---------------------------------------------------------------------
         // Generate system id with this format :
         // (BirthDate)(Gender)(XXXXXX)(checkdigit)
         // PatientIdentifierType will be null
         // ---------------------------------------------------------------------
 
-        String identifier = PatientIdentifierGenerator.getNewIdentifier( patient.getBirthDate(), patient.getGender() );
+        String identifier = PatientIdentifierGenerator.getNewIdentifier( _birthDate, patient.getGender() );
 
         PatientIdentifier systemGenerateIdentifier = patientIdentifierService.get( null, identifier );
         while ( systemGenerateIdentifier != null )
@@ -249,6 +336,8 @@
 
         patientService.savePatient( patient );
 
+        // Create relationship
+
         if ( relationshipId != null && relationshipTypeId != null )
         {
             Patient relationship = patientService.getPatient( relationshipId );
@@ -327,6 +416,22 @@
             }
         }
 
+        // Save relationship with event
+        
+        if ( programStageInstanceId != null )
+        {
+            ProgramStageInstance programStageInstance = programStageInstanceService
+                .getProgramStageInstance( programStageInstanceId );
+            Set<Patient> patients = programStageInstance.getPatients();
+            if ( patients == null )
+            {
+                patients = new HashSet<Patient>();
+            }
+            patients.add(patient);
+            programStageInstance.setPatients( patients );
+            programStageInstanceService.updateProgramStageInstance( programStageInstance );
+        }
+
         return SUCCESS;
     }
 
@@ -334,6 +439,11 @@
     // Getter/Setter
     // -----------------------------------------------------------------------------
 
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
     public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
     {
         this.patientIdentifierTypeService = patientIdentifierTypeService;
@@ -424,14 +534,9 @@
         this.relationshipId = relationshipId;
     }
 
-    public void setDobType( Character dobType )
-    {
-        this.dobType = dobType;
-    }
-
-    public void setAgeType( char ageType )
-    {
-        this.ageType = ageType;
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
     }
 
     public void setRegistrationDate( String registrationDate )
@@ -439,7 +544,7 @@
         this.registrationDate = registrationDate;
     }
 
-    public void setPhoneNumber( String phoneNumber )
+    public void setPhoneNumber( String[] phoneNumber )
     {
         this.phoneNumber = phoneNumber;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-06-10 09:32:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java	2013-07-31 06:51:17 +0000
@@ -145,6 +145,18 @@
         return customRegistrationForm;
     }
 
+    private Integer programStageInstanceId;
+
+    public Integer getProgramStageInstanceId()
+    {
+        return programStageInstanceId;
+    }
+
+    public void setProgramStageInstanceId( Integer programStageInstanceId )
+    {
+        this.programStageInstanceId = programStageInstanceId;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -154,9 +166,9 @@
     {
         relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
         patient = patientService.getPatient( id );
-        
+
         // Get system identifier
-        
+
         for ( PatientIdentifier identifier : patient.getIdentifiers() )
         {
             if ( identifier.getIdentifierType() == null )
@@ -165,7 +177,7 @@
                 break;
             }
         }
-        
+
         healthWorkers = patient.getOrganisationUnit().getUsers();
         Program program = null;
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-07-31 06:29:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-07-31 06:51:17 +0000
@@ -732,6 +732,12 @@
 			ref="org.hisp.dhis.relationship.RelationshipService" />
 		<property name="relationshipTypeService"
 			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
+		<property name="programStageInstanceService"
+			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+		<property name="systemSettingManager"
+			ref="org.hisp.dhis.setting.SystemSettingManager" />
+		<property name="userService"
+			ref="org.hisp.dhis.user.UserService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.caseentry.action.patient.GetPartnerAction"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-07-25 06:08:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-07-31 06:51:17 +0000
@@ -666,4 +666,5 @@
 default_form_name = Default form name
 custom_form_name = Custom form name
 use_orgunits_from_level = Use organisation units from level
-message = Message
\ No newline at end of file
+message = Message
+add_patient = Add person
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm	2013-06-13 07:36:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipForm.vm	2013-07-31 06:51:17 +0000
@@ -18,7 +18,7 @@
 </h5>
 <h3>
 	&raquo; $i18n.getString( 'seach_available_patient' )
-	&#8226; <a href="javascript:showAddRelationshipPatient( '$patient.id',false )" >$i18n.getString( 'add_new_patient' )</a>
+	&#8226; <a href="javascript:showAddRelationshipPatient( '$patient.id',false,'' )" >$i18n.getString( 'add_new_patient' )</a>
 </h3>
 
 <form id="relationshipSelectForm" name="relationshipSelectForm" method="post" action="showAddRelationshipForm.action">

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipPatientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipPatientForm.vm	2013-03-05 04:09:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addRelationshipPatientForm.vm	2013-07-31 06:51:17 +0000
@@ -51,7 +51,8 @@
 </h3>
 																		
 <form id="patientForm" action="addRelationshipPatient.action" method="get" >
-<input type="hidden" id="relationshipId"  name="relationshipId" value="$patient.id"/> 
+<input type="hidden" id="relationshipId" name="relationshipId" value="$patient.id"/> 
+<input type="hidden" id="programStageInstanceId" name="programStageInstanceId" value="$!programStageInstanceId"/> 
 <table>	
 	<tr>
 		<td class='text-column'><label for="relationship_type">$i18n.getString("relationship_type")<em title="$i18n.getString( "required" )" class="required">*</em></label></td>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-07-16 04:04:23 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-07-31 06:51:17 +0000
@@ -70,6 +70,32 @@
 			<td colspan='3' class='bold'>$key: $programIndicatorsMap.get($key)</td>
 		</tr>
 		#end
+		#if($programStage.relatedPatient=='true')
+		#foreach($patient in $programStageInstance.patients)
+		<tr>
+			<td onclick='showPatientDashboardForm($patient.id)'>
+				#set($value=$!patient.getFullName())
+				#foreach( $identifier in $patient.identifiers)
+					#if($!identifier.identifierType)
+						#set($value=$identifier.identifier)
+					#else
+						#set($systemId=$identifier.identifier)
+					#end
+				#end
+				#if($value=="")
+					#set($value=$systemId)
+				#end
+				
+				<a href='#'>$value</a>
+			</td>
+		</tr>
+		#end
+		<tr>
+			<td>
+				<a href='javascript:showAddRelationshipPatient( $programStageInstance.programInstance.patient.id, false, $programStageInstance.id );' id="relatedPatient_$!programStageInstance.id" >$i18n.getString("add_patient")</a>
+			</td>
+		</tr>
+		#end
 	</table>
 	</table>
 	

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationshipPatient.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationshipPatient.js	2013-07-30 03:56:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/relationshipPatient.js	2013-07-31 06:51:17 +0000
@@ -22,7 +22,7 @@
 // Add Relationship Patient
 // -----------------------------------------------------------------------------
 
-function showAddRelationshipPatient( patientId, isShowPatientList )
+function showAddRelationshipPatient( patientId, isShowPatientList, programStageInstanceId )
 {
 	hideById( 'selectDiv' );
 	hideById( 'searchDiv' );
@@ -36,7 +36,8 @@
 	jQuery('#addRelationshipDiv').load('showAddRelationshipPatient.action',
 		{
 			id:patientId,
-			programId: getFieldValue('programIdAddPatient')
+			programId: getFieldValue('programIdAddPatient'),
+			programStageInstanceId: programStageInstanceId
 		}, function()
 		{
 			showById('addRelationshipDiv');

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2013-07-29 05:32:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2013-07-31 06:51:17 +0000
@@ -210,7 +210,7 @@
 			#end
 			
 			#if( $auth.hasAccess( "dhis-web-caseentry", "showAddRelationshipPatient" ) )			
-				&#8226; <a href="javascript:showAddRelationshipPatient( '$patient.id', false );">$i18n.getString("add_new_patient")</a>
+				&#8226; <a href="javascript:showAddRelationshipPatient( '$patient.id', false, '' );">$i18n.getString("add_new_patient")</a>
 			#end
 		</p>
 		<div class="contentProviderTable">
@@ -219,12 +219,42 @@
 					#if($rel.patientA.id==$patient.id)
 						<tr onclick="showPatientDashboardForm($rel.patientB.id)" title='$i18n.getString( "move_to_dashboard_of" ) $rel.patientB.getFullName()'>
 							<td><a href='#'>$rel.relationshipType.bIsToA</a></td>
-							<td><a href='#'>$rel.patientB.getFullName()</a></td>
+							<td>
+								#set($patient=$rel.patientB)
+								#set($value=$!patient.getFullName())
+								#foreach( $identifier in $patient.identifiers)
+									#if($!identifier.identifierType)
+										#set($value=$identifier.identifier)
+									#else
+										#set($systemId=$identifier.identifier)
+									#end
+								#end
+								#if($value=="")
+									#set($value=$systemId)
+								#end
+								
+								<a href='#'>$value</a>
+							</td>
 						</tr>
 					#else
 						<tr onclick="showPatientDashboardForm($rel.patientA.id)" title='$i18n.getString( "move_to_dashboard_of" ) $rel.patientB.getFullName()'>
 							<td><a href='#'>$rel.relationshipType.aIsToB</a></td>
-							<td><a href='#'>$rel.patientA.getFullName()</a></td>
+							<td><a href='#'>
+								#set($patient=$rel.patientA)
+								#set($value=$!patient.getFullName())
+								#foreach( $identifier in $patient.identifiers)
+									#if($!identifier.identifierType)
+										#set($value=$identifier.identifier)
+									#else
+										#set($systemId=$identifier.identifier)
+									#end
+								#end
+								#if($value=="")
+									#set($value=$systemId)
+								#end
+								
+								<a href='#'>$value</a>
+							</td>
 						</tr>
 					#end
 				#end

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-07-29 09:14:04 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-07-31 06:51:17 +0000
@@ -276,8 +276,9 @@
 		showById('birthDate');
 	#end
 	
+	var phoneNumbers = "";
 	#if( $!patient.phoneNumber )
-		var phoneNumbers = '$!encoder.jsEscape( $patient.phoneNumber , "'" )';
+		phoneNumbers = '$!encoder.jsEscape( $patient.phoneNumber , "'" )';
 		setFieldValue('phoneNumber',phoneNumbers[0]);
 		#if($!customRegistrationForm)
 			for( var i = 1;i<phoneNumbers.length;i++ )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm	2013-06-12 04:19:18 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/relationshipList.vm	2013-07-31 06:51:17 +0000
@@ -5,7 +5,7 @@
 </h5>
 <h3>	
 	&raquo; <a href="javascript:showAddRelationship('$patient.id')" >$i18n.getString( 'seach_available_patient' )</a>
-	&#8226; <a href="javascript:showAddRelationshipPatient( '$patient.id',false )" >$i18n.getString( 'add_new_patient' )</a>
+	&#8226; <a href="javascript:showAddRelationshipPatient( '$patient.id',false,'' )" >$i18n.getString( 'add_new_patient' )</a>
 </h3>
 
 <input type="hidden" id="id" name="id" value="$patient.id">

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonProgramStage.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonProgramStage.vm	2013-03-01 14:09:05 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonProgramStage.vm	2013-07-31 06:51:17 +0000
@@ -3,6 +3,7 @@
     "id": "${programStage.id}",
 	"name": "$!encoder.jsonEncode( ${programStage.name} )",
 	"description": "$!encoder.jsonEncode( ${programStage.description} )",
+	"relatedPatient": "${programStage.relatedPatient}",
 	"minDaysFromStart": "${programStage.minDaysFromStart}",
 	"dataElementCount": "${programStageDataElements.size()}",
 	"standardInterval": "$!programStage.standardInterval",

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java	2013-07-30 03:23:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java	2013-07-31 06:51:17 +0000
@@ -85,7 +85,7 @@
     {
         this.programStageDataElementService = programStageDataElementService;
     }
-    
+
     private UserGroupService userGroupService;
 
     public void setUserGroupService( UserGroupService userGroupService )
@@ -192,7 +192,7 @@
     {
         this.sendTo = sendTo;
     }
-    
+
     private List<Integer> whenToSend = new ArrayList<Integer>();
 
     public void setWhenToSend( List<Integer> whenToSend )
@@ -241,14 +241,21 @@
     {
         this.allowDateInFutures = allowDateInFutures;
     }
-    
+
     private List<Integer> userGroup = new ArrayList<Integer>();
 
     public void setUserGroup( List<Integer> userGroup )
     {
         this.userGroup = userGroup;
     }
-    
+
+    private Boolean relatedPatient;
+
+    public void setRelatedPatient( Boolean relatedPatient )
+    {
+        this.relatedPatient = relatedPatient;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -262,6 +269,7 @@
         validCompleteOnly = (validCompleteOnly == null) ? false : validCompleteOnly;
         displayGenerateEventBox = (displayGenerateEventBox == null) ? false : displayGenerateEventBox;
         captureCoordinates = (captureCoordinates == null) ? false : captureCoordinates;
+        relatedPatient = ( relatedPatient == null ) ? false : relatedPatient;
 
         ProgramStage programStage = new ProgramStage();
         Program program = programService.getProgram( id );
@@ -277,6 +285,7 @@
         programStage.setValidCompleteOnly( validCompleteOnly );
         programStage.setAutoGenerateEvent( autoGenerateEvent );
         programStage.setCaptureCoordinates( captureCoordinates );
+        programStage.setRelatedPatient( relatedPatient );
 
         Set<PatientReminder> patientReminders = new HashSet<PatientReminder>();
         for ( int i = 0; i < daysAllowedSendMessages.size(); i++ )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java	2013-07-30 09:28:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java	2013-07-31 06:51:17 +0000
@@ -76,14 +76,14 @@
     {
         this.programStageDataElementService = programStageDataElementService;
     }
-    
+
     private UserGroupService userGroupService;
-    
+
     public void setUserGroupService( UserGroupService userGroupService )
     {
         this.userGroupService = userGroupService;
     }
-    
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -234,14 +234,21 @@
     {
         this.whenToSend = whenToSend;
     }
-    
+
     private List<Integer> userGroup = new ArrayList<Integer>();
-    
+
     public void setUserGroup( List<Integer> userGroup )
     {
         this.userGroup = userGroup;
     }
 
+    private Boolean relatedPatient;
+
+    public void setRelatedPatient( Boolean relatedPatient )
+    {
+        this.relatedPatient = relatedPatient;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -254,6 +261,8 @@
         autoGenerateEvent = (autoGenerateEvent == null) ? false : autoGenerateEvent;
         validCompleteOnly = (validCompleteOnly == null) ? false : validCompleteOnly;
         displayGenerateEventBox = (displayGenerateEventBox == null) ? false : displayGenerateEventBox;
+        captureCoordinates = (captureCoordinates == null) ? false : captureCoordinates;
+        relatedPatient = (relatedPatient == null) ? false : relatedPatient;
 
         ProgramStage programStage = programStageService.getProgramStage( id );
 
@@ -265,6 +274,8 @@
         programStage.setIrregular( irregular );
         programStage.setMinDaysFromStart( minDaysFromStart );
         programStage.setDisplayGenerateEventBox( displayGenerateEventBox );
+        programStage.setRelatedPatient( relatedPatient );
+
         if ( !programStage.getProgram().isSingleEvent() )
         {
             programStage.setAutoGenerateEvent( autoGenerateEvent );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-07-25 02:32:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-07-31 06:51:17 +0000
@@ -448,4 +448,5 @@
 use_birth_date_as_enrollment_date = Use birthdate as enrollment date
 default_form_name = Default form name
 custom_form_name = Custom form name
-allow_select_enrollment_dates_in_future = Allow seleting enrollment dates in future
\ No newline at end of file
+allow_select_enrollment_dates_in_future = Allow seleting enrollment dates in future
+related_patient = Related patient
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm	2013-07-30 03:23:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm	2013-07-31 06:51:17 +0000
@@ -1,11 +1,11 @@
 <script>
-var program_stage_SMS_reminder_form ="<select type='text' id='userGroup$index' name='userGroup$index' class='userGroup'>";
-#foreach( $group in $userGroups )
-	program_stage_SMS_reminder_form += "<option value='$group.id'>$i18n.getString($group.name)</option>";
-#end
-program_stage_SMS_reminder_form +="</select>";
+	var program_stage_SMS_reminder_form ="<select type='text' id='userGroup$index' name='userGroup$index' class='userGroup'>";
+	#foreach( $group in $userGroups )
+		program_stage_SMS_reminder_form += "<option value='$group.id'>$i18n.getString($group.name)</option>";
+	#end
+	program_stage_SMS_reminder_form +="</select>";
 
-function onchangeUserGroup( id )
+	function onchangeUserGroup( id )
 	{
 		var value = document.getElementById( 'sendTo'+id ).value;
 		hideById( 'tr'+id );
@@ -54,6 +54,11 @@
 		<td><input type="checkbox" id="autoGenerateEvent" name="autoGenerateEvent" value='true' checked /></td>
 	</tr>
 	
+	<tr>
+		<td><label>$i18n.getString( "related_patient" )</em></label></td>
+		<td><input type="checkbox" id="relatedPatient" name="relatedPatient" value='true'/></td>
+	</tr>
+	
 	<tr><th colspan="2">$i18n.getString( "repeatable_program_stage_details" )</th></tr>
 	
 	<tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js	2013-07-29 09:28:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js	2013-07-31 06:51:17 +0000
@@ -55,7 +55,10 @@
 		setInnerHTML( 'nameField', json.programStage.name );	
 		setInnerHTML( 'descriptionField', json.programStage.description );
 		setInnerHTML( 'scheduledDaysFromStartField', json.programStage.minDaysFromStart ); 
-
+		
+		var relatedPatient = (json.programStage.relatedPatient=='true') ? i18n_yes : i18n_no;
+		setInnerHTML( 'relatedPatientField', relatedPatient );  
+		
 		var irregular = (json.programStage.irregular=='true') ? i18n_yes : i18n_no;
 		setInnerHTML( 'irregularField', irregular );  
 		

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStage.vm	2013-06-29 14:16:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programStage.vm	2013-07-31 06:51:17 +0000
@@ -60,6 +60,7 @@
 				</div>				
 				<p><label class="bold">$i18n.getString( "name" ):</label><br><span id="nameField"></span></p>
 				<p><label class="bold">$i18n.getString( "description" ):</label><br><span id="descriptionField"></span></p>				
+				<p><label class="bold">$i18n.getString( "related_patient" ):</label><br><span id="relatedPatientField"></span></p>				
 				<p><label class="bold">$i18n.getString( "scheduled_days_from_start" ):</label><br><span id="scheduledDaysFromStartField"></span></p>
 				<p><label class="bold">$i18n.getString( "auto_generate_event" ):</label><br><span id="autoGenerateEventField"></span></p>
 				<p><label class="bold">$i18n.getString( "irregular" ):</label><br><span id="irregularField"></span></p>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm	2013-07-29 09:28:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm	2013-07-31 06:51:17 +0000
@@ -1,11 +1,11 @@
 <script>
-var program_stage_SMS_reminder_form ="<select type='text' id='userGroup$index' name='userGroup$index' class='userGroup'>";
-#foreach( $group in $userGroups )
-	program_stage_SMS_reminder_form += "<option value='$group.id'>$i18n.getString($group.name)</option>";
-#end
-program_stage_SMS_reminder_form +="</select>";
+	var program_stage_SMS_reminder_form ="<select type='text' id='userGroup$index' name='userGroup$index' class='userGroup'>";
+	#foreach( $group in $userGroups )
+		program_stage_SMS_reminder_form += "<option value='$group.id'>$i18n.getString($group.name)</option>";
+	#end
+	program_stage_SMS_reminder_form +="</select>";
 
-function onchangeUserGroup( id )
+	function onchangeUserGroup( id )
 	{
 		var value = document.getElementById( 'sendTo'+id ).value;
 		hideById( 'tr'+id );
@@ -54,6 +54,11 @@
 				<td><input type="checkbox" id="autoGenerateEvent" name="autoGenerateEvent" value='true' #if( $programStage.autoGenerateEvent && $programStage.autoGenerateEvent=='true' ) checked #end /></td>
 			</tr>
 			
+			<tr>
+				<td><label>$i18n.getString( "related_patient" )</em></label></td>
+				<td><input type="checkbox" id="relatedPatient" name="relatedPatient" value='true' #if( $programStage.relatedPatient=='true') checked #end /></td>
+			</tr>
+			
 			<tr><th colspan="2">$i18n.getString( "repeatable_program_stage_details" )</th></tr>
 	
 			<tr>