← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12634: Made Patient -> ProgramInstance association bidirectional

 

------------------------------------------------------------
revno: 12634
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-10-14 14:41:35 +0200
message:
  Made Patient -> ProgramInstance association bidirectional
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/Patient.hbm.xml


--
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/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2013-09-19 12:43:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2013-10-14 12:41:35 +0000
@@ -38,6 +38,7 @@
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.user.User;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -99,6 +100,8 @@
 
     private Set<PatientIdentifier> identifiers = new HashSet<PatientIdentifier>();
     
+    private Set<ProgramInstance> programInstances = new HashSet<ProgramInstance>();
+    
     private OrganisationUnit organisationUnit;
     
     private Patient representative;
@@ -202,6 +205,16 @@
         this.identifiers = identifiers;
     }
     
+    public Set<ProgramInstance> getProgramInstances()
+    {
+        return programInstances;
+    }
+
+    public void setProgramInstances( Set<ProgramInstance> programInstances )
+    {
+        this.programInstances = programInstances;
+    }
+
     @JsonProperty
     @JsonSerialize(as = BaseIdentifiableObject.class)
     @JsonView({ DetailedView.class, ExportView.class })

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2013-09-19 12:43:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2013-10-14 12:41:35 +0000
@@ -108,7 +108,51 @@
     }
 
     // -------------------------------------------------------------------------
-    // Getters and setters
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public ProgramStageInstance getProgramStageInstanceByStage( int stage )
+    {
+        int count = 1;
+
+        for ( ProgramStageInstance programInstanceStage : programStageInstances )
+        {
+            if ( count == stage )
+            {
+                return programInstanceStage;
+            }
+
+            count++;
+        }
+
+        return null;
+    }
+
+    public ProgramStageInstance getActiveProgramStageInstance()
+    {
+        for ( ProgramStageInstance programStageInstance : programStageInstances )
+        {
+            if ( programStageInstance.getProgramStage().getOpenAfterEnrollment() && !programStageInstance.isCompleted()
+                && ( programStageInstance.getStatus() != null && programStageInstance.getStatus() != ProgramStageInstance.SKIPPED_STATUS ) )
+            {
+                return programStageInstance;
+            }
+        }
+
+        for ( ProgramStageInstance programStageInstance : programStageInstances )
+        {
+            if ( !programStageInstance.isCompleted()
+                &&  ( programStageInstance.getStatus() != null &&  programStageInstance.getStatus() != ProgramStageInstance.SKIPPED_STATUS ) )
+            {
+                return programStageInstance;
+            }
+        }
+
+        return null;
+    }
+        
+    // -------------------------------------------------------------------------
+    // equals and hashCode
     // -------------------------------------------------------------------------
 
     @Override
@@ -196,25 +240,20 @@
         return true;
     }
 
-    /**
-     * @return the id
-     */
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
     public int getId()
     {
         return id;
     }
 
-    /**
-     * @param id the id to set
-     */
     public void setId( int id )
     {
         this.id = id;
     }
 
-    /**
-     * @return the dateOfIncident
-     */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -223,17 +262,11 @@
         return dateOfIncident;
     }
 
-    /**
-     * @param dateOfIncident the dateOfIncident to set
-     */
     public void setDateOfIncident( Date dateOfIncident )
     {
         this.dateOfIncident = dateOfIncident;
     }
 
-    /**
-     * @return the enrollmentDate
-     */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -242,17 +275,11 @@
         return enrollmentDate;
     }
 
-    /**
-     * @param enrollmentDate the enrollmentDate to set
-     */
     public void setEnrollmentDate( Date enrollmentDate )
     {
         this.enrollmentDate = enrollmentDate;
     }
 
-    /**
-     * @return the endDate
-     */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -261,17 +288,11 @@
         return endDate;
     }
 
-    /**
-     * @param endDate the endDate to set
-     */
     public void setEndDate( Date endDate )
     {
         this.endDate = endDate;
     }
 
-    /**
-     * @return the status
-     */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -285,25 +306,16 @@
         this.status = status;
     }
 
-    /**
-     * @return the patient
-     */
     public Patient getPatient()
     {
         return patient;
     }
 
-    /**
-     * @param patient the patient to set
-     */
     public void setPatient( Patient patient )
     {
         this.patient = patient;
     }
 
-    /**
-     * @return the program
-     */
     @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class } )
@@ -313,25 +325,16 @@
         return program;
     }
 
-    /**
-     * @param program the program to set
-     */
     public void setProgram( Program program )
     {
         this.program = program;
     }
 
-    /**
-     * @return the programStageInstances
-     */
     public Set<ProgramStageInstance> getProgramStageInstances()
     {
         return programStageInstances;
     }
 
-    /**
-     * @param programStageInstances the programStageInstances to set
-     */
     public void setProgramStageInstances( Set<ProgramStageInstance> programStageInstances )
     {
         this.programStageInstances = programStageInstances;
@@ -347,9 +350,6 @@
         this.outboundSms = outboundSms;
     }
 
-    /**
-     * @return the followup
-     */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -363,9 +363,6 @@
         this.followup = followup;
     }
 
-    /**
-     * @return the patientComment
-     */
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@@ -388,48 +385,4 @@
     {
         this.messageConversations = messageConversations;
     }
-
-    // -------------------------------------------------------------------------
-    // Convenience method
-    // -------------------------------------------------------------------------
-
-    public ProgramStageInstance getProgramStageInstanceByStage( int stage )
-    {
-        int count = 1;
-
-        for ( ProgramStageInstance programInstanceStage : programStageInstances )
-        {
-            if ( count == stage )
-            {
-                return programInstanceStage;
-            }
-
-            count++;
-        }
-
-        return null;
-    }
-
-    public ProgramStageInstance getActiveProgramStageInstance()
-    {
-        for ( ProgramStageInstance programStageInstance : programStageInstances )
-        {
-            if ( programStageInstance.getProgramStage().getOpenAfterEnrollment() && !programStageInstance.isCompleted()
-                && ( programStageInstance.getStatus() != null && programStageInstance.getStatus() != ProgramStageInstance.SKIPPED_STATUS ) )
-            {
-                return programStageInstance;
-            }
-        }
-
-        for ( ProgramStageInstance programStageInstance : programStageInstances )
-        {
-            if ( !programStageInstance.isCompleted()
-                &&  ( programStageInstance.getStatus() != null &&  programStageInstance.getStatus() != ProgramStageInstance.SKIPPED_STATUS ) )
-            {
-                return programStageInstance;
-            }
-        }
-
-        return null;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/Patient.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/Patient.hbm.xml	2013-09-19 12:43:34 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/Patient.hbm.xml	2013-10-14 12:41:35 +0000
@@ -35,6 +35,11 @@
       <one-to-many class="org.hisp.dhis.patient.PatientIdentifier" />
     </set>
     
+    <set name="programInstances">
+      <key column="patientid" />
+      <one-to-many class="org.hisp.dhis.program.ProgramInstance" />
+    </set>
+    
     <many-to-one name="representative" class="org.hisp.dhis.patient.Patient" column="representativeid"
       foreign-key="fk_representativeid" />