← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11934: Add relationship between mother and child.

 

------------------------------------------------------------
revno: 11934
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-06 00:59:57 +0700
message:
  Add relationship between mother and child.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.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/Program.hbm.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addPatientForm.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/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.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/searchPatientCriteria.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java
  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/META-INF/dhis/beans.xml
  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/addProgramForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/program.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.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/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-09-05 17:59:57 +0000
@@ -34,6 +34,7 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
@@ -46,6 +47,7 @@
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientReminder;
+import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.validation.ValidationCriteria;
 
@@ -131,9 +133,17 @@
     private Boolean useBirthDateAsEnrollmentDate;
 
     private Boolean selectEnrollmentDatesInFuture;
-    
+
     private Boolean selectIncidentDatesInFuture;
 
+    private String relationshipText;
+
+    private RelationshipType relationshipType;
+
+    private Boolean relationshipFromA;
+
+    private Program relatedProgram;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -588,4 +598,56 @@
         this.selectIncidentDatesInFuture = selectIncidentDatesInFuture;
     }
 
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getRelationshipText()
+    {
+        return relationshipText;
+    }
+
+    public void setRelationshipText( String relationshipText )
+    {
+        this.relationshipText = relationshipText;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public RelationshipType getRelationshipType()
+    {
+        return relationshipType;
+    }
+
+    public void setRelationshipType( RelationshipType relationshipType )
+    {
+        this.relationshipType = relationshipType;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Program getRelatedProgram()
+    {
+        return relatedProgram;
+    }
+
+    public void setRelatedProgram( Program relatedProgram )
+    {
+        this.relatedProgram = relatedProgram;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Boolean getRelationshipFromA()
+    {
+        return relationshipFromA;
+    }
+
+    public void setRelationshipFromA( Boolean relationshipFromA )
+    {
+        this.relationshipFromA = relationshipFromA;
+    }
+
 }

=== 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-09-02 21:20:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStage.java	2013-09-05 17:59:57 +0000
@@ -90,9 +90,7 @@
     private Boolean displayGenerateEventBox = true;
 
     private Boolean captureCoordinates = false;
-
-    private Boolean relatedPatient = false;
-
+    
     private Boolean displayProvidedOtherFacility;
 
     private Boolean blockEntryForm = false;
@@ -418,14 +416,4 @@
         this.captureCoordinates = captureCoordinates;
     }
 
-    public Boolean getRelatedPatient()
-    {
-        return relatedPatient;
-    }
-
-    public void setRelatedPatient( Boolean relatedPatient )
-    {
-        this.relatedPatient = relatedPatient;
-    }
-
 }

=== 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-09-03 14:59:12 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-09-05 17:59:57 +0000
@@ -223,18 +223,16 @@
         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 = false where selectEnrollmentDatesInFuture is null");
-        executeSql( "update programstage set relatedPatient = false where relatedPatient is null");
+        executeSql( " ");
         executeSql( "update validationcriteria set description = name where description is null or description='' ");
         executeSql( "update programstage set generatedByEnrollmentDate = false where generatedByEnrollmentDate is null ");
         executeSql( "update programstage set blockEntryForm = false where blockEntryForm is null ");
         executeSql( "update programstage set remindCompleted = false where remindCompleted is null ");
         executeSql( "update programstage set displayProvidedOtherFacility = false where displayProvidedOtherFacility is null ");
-        executeSql( "update programstage set selectIncidentDatesInFuture = false where selectIncidentDatesInFuture is null ");
         executeSql( "ALTER TABLE program DROP COLUMN generatedByEnrollmentDate" );
         executeSql( "ALTER TABLE program DROP COLUMN blockEntryForm" );
         executeSql( "ALTER TABLE program DROP COLUMN remindCompleted" );
         executeSql( "ALTER TABLE program DROP COLUMN displayProvidedOtherFacility" );
-        
     }
 
     // -------------------------------------------------------------------------
@@ -313,7 +311,6 @@
                 while ( inputMatcher.find() )
                 {
                     String inputHTML = inputMatcher.group();
-                    inputHTML = inputHTML.replace( ">", "" );
 
                     // -----------------------------------------------------------------
                     // Get HTML input field code

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2013-09-05 17:59:57 +0000
@@ -6,97 +6,112 @@
   >
 
 <hibernate-mapping>
-  <class name="org.hisp.dhis.program.Program" table="program">
+	<class name="org.hisp.dhis.program.Program" table="program">
 
-    <id name="id" column="programid">
-      <generator class="native" />
-    </id>
+		<id name="id" column="programid">
+			<generator class="native" />
+		</id>
     &identifiableProperties;
 
-    <property name="name" column="name" not-null="true" length="230" />
-
-    <property name="description" type="text" />
-
-    <property name="version" />
-
-    <property name="dateOfEnrollmentDescription" type="text" />
-
-    <property name="dateOfIncidentDescription" type="text" />
-
-    <set name="programStages" order-by="mindaysfromstart" cascade="all">
-      <key column="programid" />
-      <one-to-many class="org.hisp.dhis.program.ProgramStage" />
-    </set>
-
-    <set name="organisationUnits" table="program_organisationunits">
-      <key column="programid" foreign-key="fk_program_organisationunits_programid" />
-      <many-to-many column="organisationunitid" class="org.hisp.dhis.organisationunit.OrganisationUnit"
-        foreign-key="fk_program_organisationunits_organisationunitid" />
-    </set>
-
-    <set name="patientValidationCriteria" table="program_criteria">
-      <key column="programid" foreign-key="fk_program_criteria_programid" />
-      <many-to-many column="validationcriteriaid" class="org.hisp.dhis.validation.ValidationCriteria"
-        foreign-key="fk_program_criteria_validationcriteriaid" />
-    </set>
-
-    <property name="type" />
-
-    <property name="displayIncidentDate" />
-    
-    <property name="onlyEnrollOnce" />
-
-    <list name="patientIdentifierTypes" table="program_patientIdentifierTypes">
-      <key column="programid" foreign-key="fk_program_patientIdentifierTypes_programid" />
-      <list-index column="sort_order" base="0" />
-      <many-to-many column="patientidentifiertypeid" class="org.hisp.dhis.patient.PatientIdentifierType"
-        foreign-key="fk_program_patientIdentifierTypes_patientidentifiertypeid" />
-    </list>
-
-    <list name="patientAttributes" table="program_patientAttributes">
-      <key column="programid" foreign-key="fk_program_patientAttributes_programid" />
-      <list-index column="sort_order" base="0" />
-      <many-to-many column="patientattributeid" class="org.hisp.dhis.patient.PatientAttribute"
-        foreign-key="fk_program_patientAttributes_patientattributeid" />
-    </list>
-    <property name="ignoreOverdueEvents" />
-
-	<set name="userRoles" table="program_userroles">
-		<key column="programid" />
-		<many-to-many class="org.hisp.dhis.user.UserAuthorityGroup"
-			column="userroleid" foreign-key="fk_program_userroles"/>
-	</set>
-			
- 	<set name="patientReminders" order-by="daysAllowedSendMessage" cascade="all">
-      <key column="programid" />
-      <one-to-many class="org.hisp.dhis.patient.PatientReminder" />
-    </set>
-    
-    <set name="organisationUnitGroups" table="orgunitgroupprograms">
-	  <key column="programid" />
-	  <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="orgunitgroupid"/>
-	</set>
-	
-	<property name="displayOnAllOrgunit" />
-	
-	<property name="useBirthDateAsIncidentDate" />
-	
-	<property name="useBirthDateAsEnrollmentDate" />
-	
-    <property name="selectEnrollmentDatesInFuture" />
-    
-    <property name="selectIncidentDatesInFuture" />
-    
-	<!-- Access properties -->
-	
-    <many-to-one name="user" class="org.hisp.dhis.user.User" column="userid" foreign-key="fk_program_userid" />
-
-    <property name="publicAccess" length="8" />
-
-    <set name="userGroupAccesses" table="programusergroupaccesses">
-      <key column="programid" />
-      <many-to-many class="org.hisp.dhis.user.UserGroupAccess" column="usergroupaccessid" unique="true" />
-    </set>
-    
-  </class>
+		<property name="name" column="name" not-null="true" length="230" />
+
+		<property name="description" type="text" />
+
+		<property name="version" />
+
+		<property name="dateOfEnrollmentDescription" type="text" />
+
+		<property name="dateOfIncidentDescription" type="text" />
+
+		<set name="programStages" order-by="mindaysfromstart" cascade="all">
+			<key column="programid" />
+			<one-to-many class="org.hisp.dhis.program.ProgramStage" />
+		</set>
+
+		<set name="organisationUnits" table="program_organisationunits">
+			<key column="programid" foreign-key="fk_program_organisationunits_programid" />
+			<many-to-many column="organisationunitid"
+				class="org.hisp.dhis.organisationunit.OrganisationUnit" foreign-key="fk_program_organisationunits_organisationunitid" />
+		</set>
+
+		<set name="patientValidationCriteria" table="program_criteria">
+			<key column="programid" foreign-key="fk_program_criteria_programid" />
+			<many-to-many column="validationcriteriaid"
+				class="org.hisp.dhis.validation.ValidationCriteria" foreign-key="fk_program_criteria_validationcriteriaid" />
+		</set>
+
+		<property name="type" />
+
+		<property name="displayIncidentDate" />
+
+		<property name="onlyEnrollOnce" />
+
+		<list name="patientIdentifierTypes" table="program_patientIdentifierTypes">
+			<key column="programid" foreign-key="fk_program_patientIdentifierTypes_programid" />
+			<list-index column="sort_order" base="0" />
+			<many-to-many column="patientidentifiertypeid"
+				class="org.hisp.dhis.patient.PatientIdentifierType" foreign-key="fk_program_patientIdentifierTypes_patientidentifiertypeid" />
+		</list>
+
+		<list name="patientAttributes" table="program_patientAttributes">
+			<key column="programid" foreign-key="fk_program_patientAttributes_programid" />
+			<list-index column="sort_order" base="0" />
+			<many-to-many column="patientattributeid"
+				class="org.hisp.dhis.patient.PatientAttribute" foreign-key="fk_program_patientAttributes_patientattributeid" />
+		</list>
+		<property name="ignoreOverdueEvents" />
+
+		<set name="userRoles" table="program_userroles">
+			<key column="programid" />
+			<many-to-many class="org.hisp.dhis.user.UserAuthorityGroup"
+				column="userroleid" foreign-key="fk_program_userroles" />
+		</set>
+
+		<set name="patientReminders" order-by="daysAllowedSendMessage"
+			cascade="all">
+			<key column="programid" />
+			<one-to-many class="org.hisp.dhis.patient.PatientReminder" />
+		</set>
+
+		<set name="organisationUnitGroups" table="orgunitgroupprograms">
+			<key column="programid" />
+			<many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup"
+				column="orgunitgroupid" />
+		</set>
+
+		<property name="displayOnAllOrgunit" />
+
+		<property name="useBirthDateAsIncidentDate" />
+
+		<property name="useBirthDateAsEnrollmentDate" />
+
+		<property name="selectEnrollmentDatesInFuture" />
+
+		<property name="selectIncidentDatesInFuture" />
+		
+		<property name="relationshipText" />
+
+		<many-to-one name="relationshipType"
+			class="org.hisp.dhis.relationship.RelationshipType" column="relationshiptypeid"
+			foreign-key="fk_program_relationshipid" />
+
+		<property name="relationshipFromA" />
+		
+		<many-to-one name="relatedProgram" class="org.hisp.dhis.program.Program"
+			column="relatedprogramid" foreign-key="fk_program_relatedprogram" />
+
+		<!-- Access properties -->
+
+		<many-to-one name="user" class="org.hisp.dhis.user.User"
+			column="userid" foreign-key="fk_program_userid" />
+
+		<property name="publicAccess" length="8" />
+
+		<set name="userGroupAccesses" table="programusergroupaccesses">
+			<key column="programid" />
+			<many-to-many class="org.hisp.dhis.user.UserGroupAccess"
+				column="usergroupaccessid" unique="true" />
+		</set>
+
+	</class>
 </hibernate-mapping>

=== 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-09-02 21:20:47 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml	2013-09-05 17:59:57 +0000
@@ -57,8 +57,6 @@
 
 		<property name="captureCoordinates" />
 
-		<property name="relatedPatient" />
-		
 		<property name="generatedByEnrollmentDate" />
 
 		<property name="blockEntryForm" />

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java	2013-09-03 06:39:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java	2013-09-05 17:59:57 +0000
@@ -141,6 +141,25 @@
         this.programId = programId;
     }
 
+    private Integer patientId;
+
+    public void setPatientId( Integer patientId )
+    {
+        this.patientId = patientId;
+    }
+
+    public Integer getPatientId()
+    {
+        return patientId;
+    }
+
+    private Integer relatedProgramId;
+
+    public void setRelatedProgramId( Integer relatedProgramId )
+    {
+        this.relatedProgramId = relatedProgramId;
+    }
+
     private Collection<User> healthWorkers;
 
     public Collection<User> getHealthWorkers()
@@ -211,6 +230,13 @@
         return patientRegistrationForm;
     }
 
+    private Program relatedProgram;
+
+    public Program getRelatedProgram()
+    {
+        return relatedProgram;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -278,6 +304,11 @@
 
         orgunitCountIdentifier = generateOrgunitIdentifier( organisationUnit );
 
+        if ( relatedProgramId != null )
+        {
+            relatedProgram = programService.getProgram( relatedProgramId );
+        }
+
         return SUCCESS;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addPatientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addPatientForm.vm	2013-08-08 06:20:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/addPatientForm.vm	2013-09-05 17:59:57 +0000
@@ -10,7 +10,14 @@
 				,errorElement:"span"
 				,submitHandler: function(form)
 					{
-						validateAddPatient(isContinue);
+						#if($!relatedProgram)
+							var programId = getFieldValue("relatedProgramId");
+							validateAddPatient(programId, true, isContinue);
+						#else
+							var programId = getFieldValue('programIdAddPatient');
+							validateAddPatient(programId, false, isContinue);
+						#end
+						
 					}
 				,beforeValidateHandler: function(form)
 					{
@@ -45,21 +52,37 @@
 
 <h3 id='patientMamagementLink'>
 	<a href="javascript:loadPatientList();">$i18n.getString( 'patient_management' )</a>
+	#if($!relatedProgram)
+		&#8226; <a href="javascript:showPatientDashboardForm($!patientId);">$i18n.getString( 'patient_dashboard' )</a>
+	#end
 	&#8226; $i18n.getString( "add_new_patient" )
 </h3>
 
 <form id="patientForm" name="patientForm" method="post" >
-<input type="hidden" id="representativeId" name="representativeId"/> 
-<input type="hidden" id="relationshipTypeId" name="relationshipTypeId"/>
-<input type="hidden" id="addRelationship" name="addRelationship" value="true">
+
+#if($relatedProgram)
+	<input type='hidden' name="relationshipTypeId" id="relationshipTypeId" value="$relatedProgram.relationshipType.id">
+	<input type='hidden' name="relationshipFromA" id="relationshipFromA" value="$relatedProgram.relationshipFromA" >
+	<input type='hidden' name="relationshipId" id="relationshipId" value="$patientId">
+	<input type='hidden' name="relatedProgramId" id="relatedProgramId" value="$program.id" >
+#else
+	<input type="hidden" id="representativeId" name="representativeId"/> 
+	<input type="hidden" id="relationshipTypeId" name="relationshipTypeId"/>
+	<input type="hidden" id="addRelationship" name="addRelationship" value="true">
+#end
 <table>
 	#parse( "/dhis-web-caseentry/patientForm.vm" )
 	<tr>
 		<td></td>
 		<td colspan='2' id='actionButtons'>
+			#if($!relatedProgram)
+				<input type="submit" class="button" value="$i18n.getString( 'add' )" onclick="isContinue=false;" style="width:70px;" />
+				<input type='button' class="button" value="$i18n.getString( 'cancel' )" onclick="showPatientDashboardForm($!patientId);" style="width:70px;" />
+			#else
 			<input type="submit" class="button" value="$i18n.getString( 'add' )" onclick="isContinue=false;" style="width:70px;" />
 			<input type="submit" class="button" value="$i18n.getString( 'add_and_register_new' )" style="width:140px;" onclick="isContinue=true;"/>
 			<input type='button' class="button" value="$i18n.getString( 'cancel' )" onclick="loadPatientList();" style="width:70px;" />
+			#end
 		</td>
 	</tr>
 </table>

=== 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-09-02 19:05:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-09-05 17:59:57 +0000
@@ -125,10 +125,4 @@
 			disable('validateBtn');
 		}
 	}
-					
-	#if($programStage.relatedPatient=='true')
-		setInnerHTML('patientRelatedStageSpan',"&#8226; <a href='javascript:showAddRelationshipPatient( $programStageInstance.programInstance.patient.id, false, $programStageInstance.id );' id='relatedPatient_$!programStageInstance.id' >" + i18n_add_patient_related_the_selected_event + "</a>");
-	#else
-		setInnerHTML('patientRelatedStageSpan','<br>&nbsp;');
-	#end
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-09-05 17:59:57 +0000
@@ -1726,7 +1726,23 @@
 		{
 			showById('programEnrollmentDiv');
 			var hasDataEntry = getFieldValue('hasDataEntry');
-			var type = jQuery('#tb_'+programInstanceId).attr('programType');
+			var type = jQuery( '#tb_' + programInstanceId ).attr('programType');
+			
+			var program = jQuery( '#tr1_' + programInstanceId )
+			var relationshipText=program.attr('relationshipText');
+			var relatedProgramId=program.attr('relatedProgram');
+			var patientId = getFieldValue('patientId');
+			var selectedProgram = program.attr('programId');
+			
+			if( relationshipText != "")
+			{
+				setInnerHTML('patientRelatedStageSpan',"&#8226; <a href='javascript:showAddPatientForm( " + relatedProgramId + "," + patientId + "," + selectedProgram + " );' id='relatedPatient_$!programStageInstance.id' >" + relationshipText + "</a>");
+			}
+			else
+			{
+				setInnerHTML('patientRelatedStageSpan','');
+			}
+			
 			if(type=='2'){
 				hideById('colorHelpLink');
 				hideById('programInstanceDiv');

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2013-08-27 08:54:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2013-09-05 17:59:57 +0000
@@ -65,7 +65,7 @@
 		removeItem( this.patientId, this.fullName, confirm_delete_patient, 'removePatient.action' );
 	};
 	
-	this.add = function(params,isContinue)
+	this.add = function( programId, related, params,isContinue)
 	{
 		$.ajax({
 		  type: "POST",
@@ -75,11 +75,28 @@
 			if(json.response=='success')
 			{
 				var patientId = json.message.split('_')[0];
-				var programId = getFieldValue('programIdAddPatient');
 				var	dateOfIncident = jQuery('#patientForm [id=dateOfIncident]').val();
 				var enrollmentDate = jQuery('#patientForm [id=enrollmentDate]').val();
-						
-				if( getFieldValue('programIdAddPatient')!='' && enrollmentDate != '')
+					
+				var originalPatientId = getFieldValue('patientId');
+				var relatedPatientId = patientId;
+				if(getFieldValue('relationshipFromA')=='false')
+				{
+					originalPatientId = patientId;
+					relatedPatientId = getFieldValue('patientId');
+				}
+				var relatedPatientId = 
+				jQuery.postJSON( "saveProgramEnrollment.action",
+				{
+					originalPatientId: originalPatientId,
+					relationshipTypeId: getFieldValue('relationshipTypeId'),
+					relatedPatientId: relatedPatientId
+				}, 
+				function( json ) 
+				{
+				});
+					
+				if( programId !='' && enrollmentDate != '')
 				{
 					jQuery.postJSON( "saveProgramEnrollment.action",
 					{
@@ -199,24 +216,29 @@
 // Add Patient
 // -----------------------------------------------------------------------------
 
-function addPatient( isContinue )
+function addPatient( programId, related, isContinue )
 {		
 	var patient = new Patient();
-	var params = 'programId=' + getFieldValue('programIdAddPatient') + '&' + getParamsForDiv('patientForm');
-	patient.add(params);
+	var params = 'programId=' + programId + '&' + getParamsForDiv('patientForm');
+	patient.add(programId,related,params);
     return false;
 }
 
-function showAddPatientForm()
+function showAddPatientForm( programId, patientId, relatedProgramId )
 {
 	hideById('listPatientDiv');
 	hideById('selectDiv');
 	hideById('searchDiv');
 	hideById('migrationPatientDiv');
+	hideById('patientDashboard');
 	
 	jQuery('#loaderDiv').show();
-	jQuery('#editPatientDiv').load('showAddPatientForm.action?programId=' + getFieldValue('programIdAddPatient')
-		, function()
+	jQuery('#editPatientDiv').load('showAddPatientForm.action',
+		{
+			programId: programId,
+			patientId: patientId,
+			relatedProgramId: relatedProgramId
+		}, function()
 		{
 			showById('editPatientDiv');
 			jQuery('#loaderDiv').hide();
@@ -224,9 +246,9 @@
 	
 }
 
-function validateAddPatient( isContinue )
+function validateAddPatient( programId, related, isContinue )
 {	
-	var params = "programId=" + getFieldValue('programIdAddPatient') + "&" + getParamsForDiv('patientForm');
+	var params = "programId=" + programId + "&" + getParamsForDiv('patientForm');
 	$("#patientForm :input").attr("disabled", true);
 	$("#patientForm").find("select").attr("disabled", true);
 	$.ajax({
@@ -234,12 +256,12 @@
 		url: 'validatePatient.action',
 		data: params,
 		success: function(data){
-			addValidationCompleted(data,isContinue);
+			addValidationCompleted( programId, related, data,isContinue);
 		}
 	});	
 }
 
-function addValidationCompleted( data, isContinue )
+function addValidationCompleted( programId, related, data, isContinue )
 {
     var type = jQuery(data).find('message').attr('type');
 	var message = jQuery(data).find('message').text();
@@ -247,7 +269,7 @@
 	if ( type == 'success' )
 	{
 		removeDisabledIdentifier( );
-		addPatient( isContinue );
+		addPatient( programId, related, isContinue );
 	}
 	else
 	{
@@ -269,6 +291,32 @@
 	}
 }
 
+function addRelationship()
+{
+	jQuery('#loaderDiv').show();
+	var params = getParamsForDiv('addRelationshipDiv');
+		params += "&relationshipFromA=" + jQuery('#patientForm option:selected').attr("relationshipFromA");
+	$.ajax({
+		type: "POST",
+		url: 'addRelationshipPatient.action',
+		data: params,
+		success: function( json ) {
+			hideById('addRelationshipDiv');
+			showById('selectDiv');
+			showById('searchDiv');
+			showById('listPatientDiv');
+			jQuery('#loaderDiv').hide();
+
+			if( getFieldValue( 'isShowPatientList' ) == 'false' ){
+				showRelationshipList( getFieldValue('relationshipId') );
+			}
+			else{
+				loadPatientList();
+			}
+		}});
+    return false;
+}
+
 
 // ----------------------------------------------------------------
 // Click Back to main form

=== 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-08-01 07:29:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2013-09-05 17:59:57 +0000
@@ -139,7 +139,13 @@
 						#set( $status = $programStageInstance.getEventStatus() )
 						#if( $status!=1 && $status!=5 && $flag=='false')
 							<tr id='tr1_$programInstance.id' type='$programInstance.program.type'
-								programStageInstanceId='$programStageInstanceId' style='cursor:pointer;'
+								programStageInstanceId='$programStageInstanceId' 
+								relationshipText='$!programInstance.program.relationshipText'
+								relationshipType='$!programInstance.program.relationshipType.id'
+								relationshipSide='$!programInstance.program.relationshipSide'
+								relatedProgram='$!programInstance.program.relatedProgram.id'
+								programId='$programInstance.program.id'
+								style='cursor:pointer;'
 								onclick='javascript:setFieldValue("programIdAddPatient",$programInstance.program.id);loadActiveProgramStageRecords("$programInstance.id", "$programStageInstance.id")' >
 								<td id='td_$programInstance.id'>
 									<a><span id='infor_$programInstance.id'>$programInstance.program.displayName ($format.formatDate($programInstance.enrollmentDate))</span></a>
@@ -148,7 +154,9 @@
 							</tr>
 							#if($programInstance.program.type==1 && $programStageInstance)
 							<tr>
-								<td id='tr2_$programInstance.id' onclick='javascript:loadActiveProgramStageRecords("$programInstance.id", "$programStageInstance.id")' style='cursor:pointer;'>
+								<td id='tr2_$programInstance.id' 
+									onclick='javascript:loadActiveProgramStageRecords("$programInstance.id", "$programStageInstance.id")'
+									style='cursor:pointer;'>
 									<a>&#8226; $programStageInstance.programStage.displayName ($format.formatDate($programStageInstance.dueDate))</a>
 								</td>
 							</tr>
@@ -159,6 +167,10 @@
 					#if($flag=='false')
 					<tr id='tr1_$programInstance.id' type='$programInstance.program.type'
 						programStageInstanceId='$programStageInstanceId' style='cursor:pointer;'
+						relationshipText='$!programInstance.program.relationshipText'
+						relationshipType='$!programInstance.program.relationshipType.id'
+						relationshipSide='$!programInstance.program.relationshipSide'
+						relatedProgram='$!programInstance.program.relatedProgram.id'
 						onclick='javascript:loadActiveProgramStageRecords("$programInstance.id", false)' >
 						<td id='td_$programInstance.id'>
 							<a><span id='infor_$programInstance.id'>$programInstance.program.displayName ($format.formatDate($programInstance.enrollmentDate))</span></a>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-08-30 04:23:39 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-09-05 17:59:57 +0000
@@ -13,7 +13,7 @@
 		</td>
 		<td rowspan='5' valign='bottom'>
 			<input type="button" style='width:130px' id='listPatientBtn' style='260px;' value="$i18n.getString( 'list_all_patients' )" onclick="javascript:listAllPatient();" >
-			<input type="button" style='width:130px' id='addPatientBtn' name='addPatientBtn' class='large-button' value='$i18n.getString( "add_new" )' onclick="showAddPatientForm();" >
+			<input type="button" style='width:130px' id='addPatientBtn' name='addPatientBtn' class='large-button' value='$i18n.getString( "add_new" )' onclick="showAddPatientForm(getFieldValue('programIdAddPatient'),'', '');" >
 			<input type="button" style='width:130px' id='advancedSearchBtn' value='$i18n.getString( "advanced_search" )' onclick="jQuery('#advanced-search').toggle();" >
 		</td>
 	</tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-09-05 17:59:57 +0000
@@ -46,6 +46,8 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageService;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
 
@@ -108,6 +110,13 @@
         this.userGroupService = userGroupService;
     }
 
+    private RelationshipTypeService relationshipTypeService;
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -259,6 +268,34 @@
         this.selectIncidentDatesInFuture = selectIncidentDatesInFuture;
     }
 
+    private String relationshipText;
+
+    public void setRelationshipText( String relationshipText )
+    {
+        this.relationshipText = relationshipText;
+    }
+
+    private Integer relationshipTypeId;
+
+    public void setRelationshipTypeId( Integer relationshipTypeId )
+    {
+        this.relationshipTypeId = relationshipTypeId;
+    }
+
+    private Integer relatedProgramId;
+
+    public void setRelatedProgramId( Integer relatedProgramId )
+    {
+        this.relatedProgramId = relatedProgramId;
+    }
+
+    private Boolean relationshipFromA;
+
+    public void setRelationshipFromA( Boolean relationshipFromA )
+    {
+        this.relationshipFromA = relationshipFromA;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -300,6 +337,20 @@
             program.setIgnoreOverdueEvents( false );
         }
 
+        if ( relatedProgramId != null )
+        {
+            Program relatedProgram = programService.getProgram( relatedProgramId );
+            program.setRelatedProgram( relatedProgram );
+        }
+
+        if ( relationshipTypeId != null )
+        {
+            RelationshipType relationshipType = relationshipTypeService.getRelationshipType( relationshipTypeId );
+            program.setRelationshipType( relationshipType );
+        }
+        program.setRelationshipFromA( relationshipFromA );;
+        program.setRelationshipText( relationshipText );
+
         List<PatientIdentifierType> identifierTypes = new ArrayList<PatientIdentifierType>();
         List<PatientAttribute> patientAttributes = new ArrayList<PatientAttribute>();
         int index = 0;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowAddProgramFormAction.java	2013-09-05 17:59:57 +0000
@@ -30,14 +30,18 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeService;
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
 
@@ -74,14 +78,21 @@
     {
         this.patientAttributeService = patientAttributeService;
     }
-    
+
     private UserGroupService userGroupService;
-    
+
     public void setUserGroupService( UserGroupService userGroupService )
     {
         this.userGroupService = userGroupService;
     }
-    
+
+    private RelationshipTypeService relationshipTypeService;
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -99,14 +110,28 @@
     {
         return availableAttributes;
     }
-    
+
     private List<UserGroup> userGroups;
-    
+
     public List<UserGroup> getUserGroups()
     {
         return userGroups;
     }
 
+    private List<RelationshipType> relationshipTypes;
+
+    public List<RelationshipType> getRelationshipTypes()
+    {
+        return relationshipTypes;
+    }
+
+    private List<Program> programs;
+
+    public List<Program> getPrograms()
+    {
+        return programs;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -117,16 +142,20 @@
 
         availableAttributes = patientAttributeService.getAllPatientAttributes();
 
-        Collection<Program> programs = programService.getAllPrograms();
-        
+        programs = new ArrayList<Program>( programService.getAllPrograms() );
+        Collections.sort( programs, IdentifiableObjectNameComparator.INSTANCE );
+
         for ( Program program : programs )
         {
             availableIdentifierTypes.removeAll( program.getPatientIdentifierTypes() );
             availableAttributes.removeAll( program.getPatientAttributes() );
         }
-        
+
         userGroups = new ArrayList<UserGroup>( userGroupService.getAllUserGroups() );
         
+        relationshipTypes = new ArrayList<RelationshipType>(relationshipTypeService.getAllRelationshipTypes());
+        Collections.sort( relationshipTypes, IdentifiableObjectNameComparator.INSTANCE );
+        
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/ShowUpdateProgramFormAction.java	2013-09-05 17:59:57 +0000
@@ -30,9 +30,11 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.patient.PatientAttribute;
@@ -41,6 +43,8 @@
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
 
@@ -77,14 +81,21 @@
     {
         this.patientAttributeService = patientAttributeService;
     }
-    
+
     private UserGroupService userGroupService;
-    
+
     public void setUserGroupService( UserGroupService userGroupService )
     {
         this.userGroupService = userGroupService;
     }
-    
+
+    private RelationshipTypeService relationshipTypeService;
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -159,7 +170,7 @@
     {
         return availableAttributes;
     }
-    
+
     private List<UserGroup> userGroups;
 
     public List<UserGroup> getUserGroups()
@@ -167,6 +178,20 @@
         return userGroups;
     }
 
+    private List<RelationshipType> relationshipTypes;
+
+    public List<RelationshipType> getRelationshipTypes()
+    {
+        return relationshipTypes;
+    }
+
+    private List<Program> programs;
+
+    public List<Program> getPrograms()
+    {
+        return programs;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -180,16 +205,23 @@
 
         availableAttributes = patientAttributeService.getAllPatientAttributes();
 
-        Collection<Program> programs = programService.getAllPrograms();
+        programs = new ArrayList<Program>( programService.getAllPrograms() );
 
         for ( Program program : programs )
         {
-            availableIdentifierTypes.removeAll( new HashSet<PatientIdentifierType>( program.getPatientIdentifierTypes() ) );
-            availableAttributes.removeAll(  new HashSet<PatientAttribute>( program.getPatientAttributes() ) );
+            availableIdentifierTypes
+                .removeAll( new HashSet<PatientIdentifierType>( program.getPatientIdentifierTypes() ) );
+            availableAttributes.removeAll( new HashSet<PatientAttribute>( program.getPatientAttributes() ) );
         }
-        
+
         userGroups = new ArrayList<UserGroup>( userGroupService.getAllUserGroups() );
-        
+
+        programs.remove( program );
+        Collections.sort( programs, IdentifiableObjectNameComparator.INSTANCE );
+
+        relationshipTypes = new ArrayList<RelationshipType>( relationshipTypeService.getAllRelationshipTypes() );
+        Collections.sort( relationshipTypes, IdentifiableObjectNameComparator.INSTANCE );
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2013-09-05 17:59:57 +0000
@@ -41,6 +41,8 @@
 import org.hisp.dhis.patient.PatientReminder;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
 
@@ -85,6 +87,13 @@
         this.userGroupService = userGroupService;
     }
 
+    private RelationshipTypeService relationshipTypeService;
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -283,6 +292,34 @@
         this.selectIncidentDatesInFuture = selectIncidentDatesInFuture;
     }
 
+    private String relationshipText;
+
+    public void setRelationshipText( String relationshipText )
+    {
+        this.relationshipText = relationshipText;
+    }
+
+    private Integer relationshipTypeId;
+
+    public void setRelationshipTypeId( Integer relationshipTypeId )
+    {
+        this.relationshipTypeId = relationshipTypeId;
+    }
+
+    private Boolean relationshipFromA;
+
+    public void setRelationshipFromA( Boolean relationshipFromA )
+    {
+        this.relationshipFromA = relationshipFromA;
+    }
+
+    private Integer relatedProgramId;
+
+    public void setRelatedProgramId( Integer relatedProgramId )
+    {
+        this.relatedProgramId = relatedProgramId;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -326,6 +363,20 @@
             program.setIgnoreOverdueEvents( false );
         }
 
+        if ( relatedProgramId != null )
+        {
+            Program relatedProgram = programService.getProgram( relatedProgramId );
+            program.setRelatedProgram( relatedProgram );
+        }
+
+        if ( relationshipTypeId != null )
+        {
+            RelationshipType relationshipType = relationshipTypeService.getRelationshipType( relationshipTypeId );
+            program.setRelationshipType( relationshipType );
+        }
+        program.setRelationshipFromA( relationshipFromA );
+        program.setRelationshipText( relationshipText );
+
         List<PatientIdentifierType> identifierTypes = new ArrayList<PatientIdentifierType>();
         List<PatientAttribute> patientAttributes = new ArrayList<PatientAttribute>();
         int index = 0;
@@ -374,6 +425,13 @@
             {
                 reminder.setUserGroup( null );
             }
+
+            if ( relatedProgramId != null )
+            {
+                Program relatedProgram = programService.getProgram( relatedProgramId );
+                program.setRelatedProgram( relatedProgram );
+            }
+
             patientReminders.add( reminder );
         }
         program.setPatientReminders( patientReminders );

=== 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-09-02 21:20:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java	2013-09-05 17:59:57 +0000
@@ -318,7 +318,6 @@
         programStage.setValidCompleteOnly( validCompleteOnly );
         programStage.setAutoGenerateEvent( autoGenerateEvent );
         programStage.setCaptureCoordinates( captureCoordinates );
-        programStage.setRelatedPatient( relatedPatient );
         programStage.setDisplayProvidedOtherFacility( displayProvidedOtherFacility );
         programStage.setBlockEntryForm( blockEntryForm );
         programStage.setRemindCompleted( remindCompleted );

=== 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-09-04 08:56:15 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java	2013-09-05 17:59:57 +0000
@@ -307,7 +307,6 @@
         programStage.setIrregular( irregular );
         programStage.setMinDaysFromStart( minDaysFromStart );
         programStage.setDisplayGenerateEventBox( displayGenerateEventBox );
-        programStage.setRelatedPatient( relatedPatient );
         programStage.setDisplayProvidedOtherFacility( displayProvidedOtherFacility );
         programStage.setBlockEntryForm( blockEntryForm );
         programStage.setRemindCompleted( remindCompleted );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-08-21 12:29:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-09-05 17:59:57 +0000
@@ -181,6 +181,8 @@
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="userGroupService" 
 			ref="org.hisp.dhis.user.UserGroupService" />	
+		<property name="relationshipTypeService" 
+			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.action.program.GetProgramListAction"
@@ -222,6 +224,8 @@
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+		<property name="relationshipTypeService" 
+			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 
 	<bean
@@ -234,6 +238,8 @@
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+		<property name="relationshipTypeService" 
+			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 	<bean id="org.hisp.dhis.patient.action.program.UpdateProgramAction"
 		class="org.hisp.dhis.patient.action.program.UpdateProgramAction"
@@ -245,6 +251,8 @@
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
 		<property name="userGroupService"
 			ref="org.hisp.dhis.user.UserGroupService" />
+		<property name="relationshipTypeService" 
+			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.action.program.ValidateProgramAction"

=== 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-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-09-05 17:59:57 +0000
@@ -451,4 +451,9 @@
 allow_select_enrollment_dates_in_future = Allow seleting enrollment dates in future
 related_patient = Related person
 allow_select_enrollment_date_in_future = Allow to select enrollment date in future
-allow_select_incident_date_in_future = Allow to select incident date in future
\ No newline at end of file
+allow_select_incident_date_in_future = Allow to select incident date in future
+program_related = Program related
+relationship_text = Relationship text
+relationship_type = Relationship type
+relationship_details = Relationship details
+program_related = Program related

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramForm.vm	2013-09-05 17:59:57 +0000
@@ -135,6 +135,46 @@
 		</tr>
 		
 		<tr name='nonAnonymous'>
+			<th colspan="2">$i18n.getString( "program_related" )</th>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("relationship_text")</td>
+			<td><input type='text' id='relationshipText' name='relationshipText' ></td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("relationship_type")</td>
+			<td>
+				<select type='text' id='relationshipTypeId' name='relationshipTypeId' onchange='relationshipTypeOnchange()' >
+					<option value=''>[$i18n.getString("please_select")]</option>
+					#foreach($relationshipType in $relationshipTypes)
+						<option value='$relationshipType.id' aIsToB='$relationshipType.aIsToB' bIsToA='$relationshipType.bIsToA'>$relationshipType.name</option>
+					#end
+				</select>
+			</td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("relationship_details")</td>
+			<td>
+				<select type='text' id='relationshipFromA' name='relationshipFromA'></select>
+			</td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("program_related")</td>
+			<td>
+				<select type='text' id='relatedProgramId' name='relatedProgramId' >
+					<option value=''>[$i18n.getString("please_select")]</option>
+					#foreach($program in $programs)
+						<option value='$program.id'>$program.name</option>
+					#end
+				</select>
+			</td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
 			<th colspan="2">$i18n.getString( "enrollment_details" )</th>
 		</tr>
 		

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/program.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/program.js	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/program.js	2013-09-05 17:59:57 +0000
@@ -60,6 +60,21 @@
 	removeItem( programId, name, i18n_confirm_delete, 'removeProgram.action' );
 }
 
+function relationshipTypeOnchange()
+{
+	clearListById( 'relationshipSide' );
+	var relationshipType = jQuery('#relationshipTypeId option:selected');
+	if( relationshipType.val() != "")
+	{
+		var aIsToB = relationshipType.attr('aIsToB');
+		var bIsToA = relationshipType.attr('bIsToA');
+		
+		var relationshipSide = jQuery("#relationshipFromA");
+		relationshipSide.append( '<option value="false">' + aIsToB + '</option>' );
+		relationshipSide.append( '<option value="true">' + bIsToA + '</option>' );
+	}
+}
+
 function programOnChange()
 {
 	var type = getFieldValue('type');

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm	2013-09-03 14:59:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramForm.vm	2013-09-05 17:59:57 +0000
@@ -148,6 +148,52 @@
 		</tr>
 		
 		<tr name='nonAnonymous'>
+			<th colspan="2">$i18n.getString( "program_related" )</th>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("relationship_text")</td>
+			<td><input type='text' id='relationshipText' name='relationshipText' value='$!program.relationshipText' ></td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("relationship")</td>
+			<td>
+				<select type='text' id='relationshipTypeId' name='relationshipTypeId' onchange='relationshipTypeOnchange()' >
+					<option value=''>[$i18n.getString("please_select")]</option>
+					#foreach($relationshipType in $relationshipTypes)
+						<option value='$relationshipType.id' aIsToB='$relationshipType.aIsToB' bIsToA='$relationshipType.bIsToA' #if($program.relationshipType.id==$relationshipType.id) selected #end >$relationshipType.name</option>
+					#end
+				</select>
+			</td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("relationship_details")</td>
+			<td>
+				<select id='relationshipFromA' name='relationshipFromA'>
+					#if($!program.relationshipType)
+						<option value='false' #if($!program.relationshipFromA=='true') selected #end>$!program.relationshipType.aIsToB</option>
+						<option value='true' #if($!program.relationshipFromA=='false') selected #end>$!program.relationshipType.bIsToA</option>
+					#end
+				</select>
+			</td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
+			<td>$i18n.getString("program_related")</td>
+			<td>
+				<select type='text' id='relatedProgramId' name='relatedProgramId' >
+					<option value=''>[$i18n.getString("please_select")]</option>
+					#set( $relatedProgram = $program.relatedProgram)
+					#foreach($program in $programs)
+						<option value='$program.id' #if($relatedProgram.id==$program.id) selected #end >$program.name</option>
+					#end
+				</select>
+			</td>
+		</tr>
+		
+		<tr name='nonAnonymous'>
 			<th colspan="2">$i18n.getString( "enrollment_details" )</th>
 		</tr>