← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11944: add uid, code, created and lastUpdated to patient

 

------------------------------------------------------------
revno: 11944
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-06 10:24:36 +0200
message:
  add uid, code, created and lastUpdated to patient
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/Patient.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidateAddRelationshipPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-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-06 05:27:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2013-09-06 08:24:36 +0000
@@ -28,11 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.user.User;
 
-import java.io.Serializable;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashSet;
@@ -42,7 +42,7 @@
  * @author Abyot Asalefew Gizaw
  */
 public class Patient
-    implements Serializable
+    extends BaseIdentifiableObject
 {
     /**
      * Determines if a de-serialized file is compatible with this class.
@@ -73,8 +73,6 @@
     public static String FIXED_ATTR_INTERGER_AGE = "integerValueOfAge";
     public static String FIXED_ATTR_REGISTRATION_DATE = "registrationDate";
 
-    private Integer id;
-
     private String firstName;
 
     private String middleName;
@@ -127,7 +125,7 @@
         final int prime = 31;
         int result = 1;
 
-        result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + ((uid == null) ? 0 : uid.hashCode());
         result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
         result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
         result = prime * result + ((gender == null) ? 0 : gender.hashCode());
@@ -222,11 +220,6 @@
     // Getters and setters
     // -------------------------------------------------------------------------
 
-    public Integer getId()
-    {
-        return id;
-    }
-
     public Set<PatientAttribute> getAttributes()
     {
         return attributes;
@@ -247,11 +240,6 @@
         this.attributes = attributes;
     }
 
-    public void setId( Integer id )
-    {
-        this.id = id;
-    }
-
     public String getFirstName()
     {
         return firstName;
@@ -404,7 +392,7 @@
         {
             return "< 1 yr";
         }
-        
+
         return age + " yr";
     }
 
@@ -568,12 +556,12 @@
     {
         switch ( dobType )
         {
-        case DOB_TYPE_VERIFIED:
-            return "Verified";
-        case DOB_TYPE_DECLARED:
-            return "Declared";
-        default:
-            return "Approxiated";
+            case DOB_TYPE_VERIFIED:
+                return "Verified";
+            case DOB_TYPE_DECLARED:
+                return "Declared";
+            default:
+                return "Approxiated";
         }
     }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-09-06 08:24:36 +0000
@@ -28,15 +28,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
 import org.hisp.dhis.common.GenericStore;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
 /**
  * @author Abyot Asalefew Gizaw
  * @version $Id$

=== 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-09-06 07:54:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2013-09-06 08:24:36 +0000
@@ -28,20 +28,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-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$
  */
 public class ProgramStageInstance
     extends BaseIdentifiableObject

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2013-08-29 11:59:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2013-09-06 08:24:36 +0000
@@ -28,9 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Map;
-import java.util.UUID;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
@@ -40,6 +37,9 @@
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 
+import java.util.Map;
+import java.util.UUID;
+
 /**
  * @author bobj
  */
@@ -53,10 +53,11 @@
         "organisationunit", "orgunitgroup", "orgunitgroupset", "dataelementcategoryoption", "dataelementgroup", "sqlview",
         "dataelement", "dataelementgroupset", "dataelementcategory", "categorycombo", "categoryoptioncombo", "map", "mapview",
         "reporttable", "report", "messageconversation", "message", "userinfo", "usergroup", "userrole", "maplegend",
-        "maplegendset", "maplayer", "section", "optionset", "program", "programinstance", "programstage", "programstageinstance"
+        "maplegendset", "maplayer", "section", "optionset", "program", "programinstance", "programstage", "programstageinstance",
+        "patient"
     };
-    
-    private static final Map<String, String> TABLE_ID_MAP = DimensionalObjectUtils.asMap( 
+
+    private static final Map<String, String> TABLE_ID_MAP = DimensionalObjectUtils.asMap(
         "dataelementcategoryoption", "categoryoptionid",
         "dataelementcategory", "categoryid" );
 
@@ -79,11 +80,11 @@
             try
             {
                 log.debug( "Checking table: " + table );
-                
+
                 int count = 0;
-                
+
                 SqlRowSet resultSet = jdbcTemplate.queryForRowSet( "SELECT * from " + table + " WHERE uid IS NULL" );
-                
+
                 while ( resultSet.next() )
                 {
                     ++count;
@@ -92,7 +93,7 @@
                     String sql = "update " + table + " set uid = '" + CodeGenerator.generateCode() + "' where " + idColumn + " = " + id;
                     jdbcTemplate.update( sql );
                 }
-                
+
                 if ( count > 0 )
                 {
                     log.info( count + " uids set on " + table );
@@ -101,9 +102,9 @@
                 count = 0;
 
                 resultSet = jdbcTemplate.queryForRowSet( "SELECT * from " + table + " WHERE lastUpdated IS NULL" );
-                
+
                 String timestamp = DateUtils.getLongDateString();
-                
+
                 while ( resultSet.next() )
                 {
                     ++count;
@@ -112,7 +113,7 @@
                     String sql = "update " + table + " set lastupdated = '" + timestamp + "' where " + idColumn + " = " + id;
                     jdbcTemplate.update( sql );
                 }
-                
+
                 if ( count > 0 )
                 {
                     log.info( count + " last updated set on " + table );
@@ -121,7 +122,7 @@
                 count = 0;
 
                 resultSet = jdbcTemplate.queryForRowSet( "SELECT * from " + table + " WHERE created IS NULL" );
-                
+
                 while ( resultSet.next() )
                 {
                     ++count;
@@ -130,7 +131,7 @@
                     String sql = "update " + table + " set created = '" + timestamp + "' where " + idColumn + " = " + id;
                     jdbcTemplate.update( sql );
                 }
-                
+
                 if ( count > 0 )
                 {
                     log.info( count + " timestamps set on " + table );
@@ -139,27 +140,27 @@
             catch ( Exception ex )
             {
                 log.error( "Problem updating: " + table + ", id column: " + getIdColumn( table ), ex );
-                
+
                 throw ex;
             }
         }
 
         log.debug( "Identifiable properties updated" );
-        
+
         createUidConstraints();
 
         log.debug( "Identifiable constraints updated" );
-        
+
         createOrgUnitUuids();
-        
-        log.debug( "Organisation unit uuids updated" );        
+
+        log.debug( "Organisation unit uuids updated" );
     }
 
     private String getIdColumn( String table )
     {
-        return TABLE_ID_MAP.containsKey( table ) ? TABLE_ID_MAP.get( table ) : ( table + "id" );        
+        return TABLE_ID_MAP.containsKey( table ) ? TABLE_ID_MAP.get( table ) : (table + "id");
     }
-    
+
     private void createUidConstraints()
     {
         for ( String table : tables )
@@ -176,7 +177,7 @@
             }
         }
     }
-    
+
     private void createOrgUnitUuids()
     {
         try

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml	2013-04-19 10:20:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml	2013-09-06 08:24:36 +0000
@@ -4,7 +4,6 @@
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
   [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
   >
-
 <hibernate-mapping>
   <class name="org.hisp.dhis.dataelement.DataElement" table="dataelement">
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-09-06 08:24:36 +0000
@@ -28,14 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
@@ -52,6 +44,14 @@
 import org.hisp.dhis.system.grid.ListGrid;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 /**
  * @author Abyot Asalefew Gizaw
  * @version $Id$
@@ -465,7 +465,7 @@
         if ( representativeId == null )
             return false;
 
-        return patient.getRepresentative() == null || !patient.getRepresentative().getId().equals( representativeId );
+        return patient.getRepresentative() == null || !(patient.getRepresentative().getId() == representativeId);
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-09-06 05:27:42 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-09-06 08:24:36 +0000
@@ -28,14 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-
 import org.apache.commons.lang.StringUtils;
 import org.hibernate.Criteria;
 import org.hibernate.Query;
@@ -44,6 +36,7 @@
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -62,13 +55,20 @@
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+
 /**
  * @author Abyot Asalefew Gizaw
- * @version $Id$
  */
 @Transactional
 public class HibernatePatientStore
-    extends HibernateGenericStore<Patient>
+    extends HibernateIdentifiableObjectStore<Patient>
     implements PatientStore
 {
     // -------------------------------------------------------------------------
@@ -107,8 +107,8 @@
         return getCriteria( Restrictions.eq( "gender", gender ) ).list();
     }
 
+    @Override
     @SuppressWarnings( "unchecked" )
-    @Override
     public Collection<Patient> getByBirthDate( Date birthDate )
     {
         return getCriteria( Restrictions.eq( "birthDate", birthDate ) ).list();
@@ -147,8 +147,8 @@
         return patients;
     }
 
+    @Override
     @SuppressWarnings( "unchecked" )
-    @Override
     public Collection<Patient> get( String firstName, String middleName, String lastName, Date birthdate, String gender )
 
     {
@@ -173,8 +173,8 @@
         return crit.list();
     }
 
+    @Override
     @SuppressWarnings( "unchecked" )
-    @Override
     public Collection<Patient> getByOrgUnit( OrganisationUnit organisationUnit, Integer min, Integer max )
     {
         String hql = "select p from Patient p where p.organisationUnit = :organisationUnit order by p.id DESC";
@@ -189,8 +189,8 @@
         return query.list();
     }
 
+    @Override
     @SuppressWarnings( "unchecked" )
-    @Override
     public Collection<Patient> getByOrgUnitProgram( OrganisationUnit organisationUnit, Program program, Integer min,
         Integer max )
     {
@@ -238,8 +238,8 @@
         return rs != null ? rs.intValue() : 0;
     }
 
+    @Override
     @SuppressWarnings( "unchecked" )
-    @Override
     public Collection<Patient> getRepresentatives( Patient patient )
     {
         String hql = "select distinct p from Patient p where p.representative = :representative order by p.id DESC";
@@ -425,7 +425,7 @@
                 {
                     patientWhere += " ((DATE(now()) - DATE(birthdate))/365) " + value;
                 }
-                else if(id.equals( Patient.FIXED_ATTR_REGISTRATION_DATE ))
+                else if ( id.equals( Patient.FIXED_ATTR_REGISTRATION_DATE ) )
                 {
                     patientWhere += "p." + id + value;
                 }
@@ -481,103 +481,103 @@
                     int statusEvent = Integer.parseInt( keys[index] );
                     switch ( statusEvent )
                     {
-                    case ProgramStageInstance.COMPLETED_STATUS:
-                        patientWhere += condition + operatorStatus
-                            + "( psi.executiondate is not null and  psi.executiondate>='" + keys[2]
-                            + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=true ";
-                        // get events by orgunit children
-                        if ( keys[4].equals( "-1" ) )
-                        {
-                            patientWhere += " and psi.organisationunitid in( "
-                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                        }
-                        // get events by selected
-                        else if ( !keys[4].equals( "0" ) )
-                        {
-                            patientWhere += " and psi.organisationunitid=" + keys[4];
-                        }
-                        patientWhere += ")";
-                        operatorStatus = " OR ";
-                        condition = "";
-                        continue;
-                    case ProgramStageInstance.VISITED_STATUS:
-                        patientWhere += condition + operatorStatus
-                            + "( psi.executiondate is not null and psi.executiondate>='" + keys[2]
-                            + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=false ";
+                        case ProgramStageInstance.COMPLETED_STATUS:
+                            patientWhere += condition + operatorStatus
+                                + "( psi.executiondate is not null and  psi.executiondate>='" + keys[2]
+                                + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=true ";
+                            // get events by orgunit children
+                            if ( keys[4].equals( "-1" ) )
+                            {
+                                patientWhere += " and psi.organisationunitid in( "
+                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                            }
+                            // get events by selected
+                            else if ( !keys[4].equals( "0" ) )
+                            {
+                                patientWhere += " and psi.organisationunitid=" + keys[4];
+                            }
+                            patientWhere += ")";
+                            operatorStatus = " OR ";
+                            condition = "";
+                            continue;
+                        case ProgramStageInstance.VISITED_STATUS:
+                            patientWhere += condition + operatorStatus
+                                + "( psi.executiondate is not null and psi.executiondate>='" + keys[2]
+                                + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=false ";
 
-                        // get events by orgunit children
-                        if ( keys[4].equals( "-1" ) )
-                        {
-                            patientWhere += " and psi.organisationunitid in( "
-                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                        }
-                        // get events by selected
-                        else if ( !keys[4].equals( "0" ) )
-                        {
-                            patientWhere += " and psi.organisationunitid=" + keys[4];
-                        }
-                        patientWhere += ")";
-                        operatorStatus = " OR ";
-                        condition = "";
-                        continue;
-                    case ProgramStageInstance.FUTURE_VISIT_STATUS:
-                        patientWhere += condition + operatorStatus + "( psi.executiondate is null and psi.duedate>='"
-                            + keys[2] + "' and psi.duedate<='" + keys[3]
-                            + "' and psi.status is null and (DATE(now()) - DATE(psi.duedate) <= 0) ";
-                        // get events by orgunit children
-                        if ( keys[4].equals( "-1" ) )
-                        {
-                            patientWhere += " and p.organisationunitid in( "
-                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                        }
-                        // get events by selected
-                        else if ( !keys[4].equals( "0" ) )
-                        {
-                            patientWhere += " and p.organisationunitid=" + keys[4];
-                        }
-                        patientWhere += ")";
-                        operatorStatus = " OR ";
-                        condition = "";
-                        continue;
-                    case ProgramStageInstance.LATE_VISIT_STATUS:
-                        patientWhere += condition + operatorStatus + "( psi.executiondate is null and  psi.duedate>='"
-                            + keys[2] + "' and psi.duedate<='" + keys[3]
-                            + "' and psi.status is null  and (DATE(now()) - DATE(psi.duedate) > 0) ";
-                        // get events by orgunit children
-                        if ( keys[4].equals( "-1" ) )
-                        {
-                            patientWhere += " and p.organisationunitid in( "
-                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                        }
-                        // get events by selected
-                        else if ( !keys[4].equals( "0" ) )
-                        {
-                            patientWhere += " and p.organisationunitid=" + keys[4];
-                        }
-                        patientWhere += ")";
-                        operatorStatus = " OR ";
-                        condition = "";
-                        continue;
-                    case ProgramStageInstance.SKIPPED_STATUS:
-                        patientWhere += condition + operatorStatus + "( psi.status=5 and  psi.duedate>='" + keys[2]
-                            + "' and psi.duedate<='" + keys[3] + "' ";
-                        // get events by orgunit children
-                        if ( keys[4].equals( "-1" ) )
-                        {
-                            patientWhere += " and psi.organisationunitid in( "
-                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                        }
-                        // get events by selected
-                        else if ( !keys[4].equals( "0" ) )
-                        {
-                            patientWhere += " and p.organisationunitid=" + keys[4];
-                        }
-                        patientWhere += ")";
-                        operatorStatus = " OR ";
-                        condition = "";
-                        continue;
-                    default:
-                        continue;
+                            // get events by orgunit children
+                            if ( keys[4].equals( "-1" ) )
+                            {
+                                patientWhere += " and psi.organisationunitid in( "
+                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                            }
+                            // get events by selected
+                            else if ( !keys[4].equals( "0" ) )
+                            {
+                                patientWhere += " and psi.organisationunitid=" + keys[4];
+                            }
+                            patientWhere += ")";
+                            operatorStatus = " OR ";
+                            condition = "";
+                            continue;
+                        case ProgramStageInstance.FUTURE_VISIT_STATUS:
+                            patientWhere += condition + operatorStatus + "( psi.executiondate is null and psi.duedate>='"
+                                + keys[2] + "' and psi.duedate<='" + keys[3]
+                                + "' and psi.status is null and (DATE(now()) - DATE(psi.duedate) <= 0) ";
+                            // get events by orgunit children
+                            if ( keys[4].equals( "-1" ) )
+                            {
+                                patientWhere += " and p.organisationunitid in( "
+                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                            }
+                            // get events by selected
+                            else if ( !keys[4].equals( "0" ) )
+                            {
+                                patientWhere += " and p.organisationunitid=" + keys[4];
+                            }
+                            patientWhere += ")";
+                            operatorStatus = " OR ";
+                            condition = "";
+                            continue;
+                        case ProgramStageInstance.LATE_VISIT_STATUS:
+                            patientWhere += condition + operatorStatus + "( psi.executiondate is null and  psi.duedate>='"
+                                + keys[2] + "' and psi.duedate<='" + keys[3]
+                                + "' and psi.status is null  and (DATE(now()) - DATE(psi.duedate) > 0) ";
+                            // get events by orgunit children
+                            if ( keys[4].equals( "-1" ) )
+                            {
+                                patientWhere += " and p.organisationunitid in( "
+                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                            }
+                            // get events by selected
+                            else if ( !keys[4].equals( "0" ) )
+                            {
+                                patientWhere += " and p.organisationunitid=" + keys[4];
+                            }
+                            patientWhere += ")";
+                            operatorStatus = " OR ";
+                            condition = "";
+                            continue;
+                        case ProgramStageInstance.SKIPPED_STATUS:
+                            patientWhere += condition + operatorStatus + "( psi.status=5 and  psi.duedate>='" + keys[2]
+                                + "' and psi.duedate<='" + keys[3] + "' ";
+                            // get events by orgunit children
+                            if ( keys[4].equals( "-1" ) )
+                            {
+                                patientWhere += " and psi.organisationunitid in( "
+                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                            }
+                            // get events by selected
+                            else if ( !keys[4].equals( "0" ) )
+                            {
+                                patientWhere += " and p.organisationunitid=" + keys[4];
+                            }
+                            patientWhere += ")";
+                            operatorStatus = " OR ";
+                            condition = "";
+                            continue;
+                        default:
+                            continue;
                     }
                 }
                 if ( condition.isEmpty() )
@@ -598,20 +598,20 @@
                 int statusEvent = Integer.parseInt( keys[2] );
                 switch ( statusEvent )
                 {
-                case ProgramStageInstance.COMPLETED_STATUS:
-                    patientWhere += "psi.completed=true";
-                    break;
-                case ProgramStageInstance.VISITED_STATUS:
-                    patientWhere += "psi.executiondate is not null and psi.completed=false";
-                    break;
-                case ProgramStageInstance.FUTURE_VISIT_STATUS:
-                    patientWhere += "psi.executiondate is null and psi.duedate >= now()";
-                    break;
-                case ProgramStageInstance.LATE_VISIT_STATUS:
-                    patientWhere += "psi.executiondate is null and psi.duedate < now()";
-                    break;
-                default:
-                    break;
+                    case ProgramStageInstance.COMPLETED_STATUS:
+                        patientWhere += "psi.completed=true";
+                        break;
+                    case ProgramStageInstance.VISITED_STATUS:
+                        patientWhere += "psi.executiondate is not null and psi.completed=false";
+                        break;
+                    case ProgramStageInstance.FUTURE_VISIT_STATUS:
+                        patientWhere += "psi.executiondate is null and psi.duedate >= now()";
+                        break;
+                    case ProgramStageInstance.LATE_VISIT_STATUS:
+                        patientWhere += "psi.executiondate is null and psi.duedate < now()";
+                        break;
+                    default:
+                        break;
                 }
 
                 patientWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";
@@ -675,12 +675,12 @@
         {
             sql += statementBuilder.limitRecord( min, max );
         }
-        
+
         return sql;
     }
 
+    @Override
     @SuppressWarnings( "unchecked" )
-    @Override
     public Collection<Patient> getByPhoneNumber( String phoneNumber, Integer min, Integer max )
     {
         String hql = "select p from Patient p where p.phoneNumber like '%" + phoneNumber + "%'";
@@ -734,6 +734,7 @@
         criteria.createAlias( "organisationUnit", "orgunit" );
         criteria.setProjection( Projections.distinct( Projections.projectionList().add(
             Projections.property( "orgunit.id" ), "orgunitid" ) ) );
+
         return criteria.list();
     }
 
@@ -743,38 +744,40 @@
 
     private Collection<Integer> getOrgunitChildren( Collection<OrganisationUnit> orgunits )
     {
-        Collection<Integer> orgunitIds = new HashSet<Integer>();
+        Collection<Integer> orgUnitIds = new HashSet<Integer>();
+
         if ( orgunits != null )
         {
             for ( OrganisationUnit orgunit : orgunits )
             {
 
-                orgunitIds
-                    .addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
-                orgunitIds.remove( orgunit.getId() );
+                orgUnitIds.addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
+                orgUnitIds.remove( orgunit.getId() );
             }
         }
 
-        if ( orgunitIds.size() == 0 )
+        if ( orgUnitIds.size() == 0 )
         {
-            orgunitIds.add( 0 );
+            orgUnitIds.add( 0 );
         }
-        return orgunitIds;
+
+        return orgUnitIds;
     }
 
     private Collection<Integer> getOrganisationUnitIds( Collection<OrganisationUnit> orgunits )
     {
-        Collection<Integer> orgunitIds = new HashSet<Integer>();
-        for ( OrganisationUnit orgunit : orgunits )
-        {
-            orgunitIds.add( orgunit.getId() );
-        }
-
-        if ( orgunitIds.size() == 0 )
-        {
-            orgunitIds.add( 0 );
-        }
-        return orgunitIds;
+        Collection<Integer> orgUnitIds = new HashSet<Integer>();
+
+        for ( OrganisationUnit orgUnit : orgunits )
+        {
+            orgUnitIds.add( orgUnit.getId() );
+        }
+
+        if ( orgUnitIds.size() == 0 )
+        {
+            orgUnitIds.add( 0 );
+        }
+
+        return orgUnitIds;
     }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-08-27 03:31:40 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-09-06 08:24:36 +0000
@@ -35,9 +35,9 @@
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.jdbc.StatementBuilder;
@@ -88,7 +88,7 @@
  * @author Abyot Asalefew
  */
 public class HibernateProgramStageInstanceStore
-    extends HibernateGenericStore<ProgramStageInstance>
+    extends HibernateIdentifiableObjectStore<ProgramStageInstance>
     implements ProgramStageInstanceStore
 {
     // -------------------------------------------------------------------------
@@ -155,7 +155,7 @@
     // Implemented methods
     // -------------------------------------------------------------------------
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public ProgramStageInstance get( ProgramInstance programInstance, ProgramStage programStage )
     {
         List<ProgramStageInstance> list = new ArrayList<ProgramStageInstance>( getCriteria(
@@ -165,44 +165,44 @@
         return list.isEmpty() ? null : list.get( list.size() - 1 );
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( ProgramStage programStage )
     {
         return getCriteria( Restrictions.eq( "programStage", programStage ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Collection<ProgramInstance> programInstances )
     {
         return getCriteria( Restrictions.in( "programInstance", programInstances ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Date dueDate )
     {
         return getCriteria( Restrictions.eq( "dueDate", dueDate ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Date dueDate, Boolean completed )
     {
         return getCriteria( Restrictions.eq( "dueDate", dueDate ), Restrictions.eq( "completed", completed ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Date startDate, Date endDate )
     {
         return (getCriteria( Restrictions.ge( "dueDate", startDate ), Restrictions.le( "dueDate", endDate ) )).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Date startDate, Date endDate, Boolean completed )
     {
         return (getCriteria( Restrictions.ge( "dueDate", startDate ), Restrictions.le( "dueDate", endDate ),
             Restrictions.eq( "completed", completed ) )).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, Boolean completed )
     {
         String hql = "from ProgramStageInstance psi where psi.organisationUnit = :unit";
@@ -242,7 +242,7 @@
         return q.list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<ProgramStageInstance> get( Patient patient, Boolean completed )
     {
         String hql = "from ProgramStageInstance where programInstance.patient = :patient and completed = :completed";
@@ -251,13 +251,13 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<ProgramStageInstance> get( ProgramStage programStage, OrganisationUnit organisationUnit )
     {
         return getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.eq( "organisationUnit", organisationUnit ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<ProgramStageInstance> get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate,
         Date endDate, int min, int max )
     {
@@ -464,7 +464,7 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<ProgramStageInstance> getStatisticalProgramStageDetailsReport( ProgramStage programStage,
         Collection<Integer> orgunitIds, Date startDate, Date endDate, int status, Integer min, Integer max )
     {
@@ -719,7 +719,7 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Program program, Collection<Integer> orgunitIds, Date startDate,
         Date endDate, Boolean completed )
     {
@@ -787,7 +787,7 @@
         return grid;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<ProgramStageInstance> get( Patient patient )
     {
         return getCriteria().createAlias( "patients", "patient" )
@@ -2155,7 +2155,7 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<Integer> getOrgunitIds( Date startDate, Date endDate )
     {
         Criteria criteria = getCriteria();

=== 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-04-19 03:31:52 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patient/hibernate/Patient.hbm.xml	2013-09-06 08:24:36 +0000
@@ -1,14 +1,16 @@
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
-  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
-
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
+  [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+  >
 <hibernate-mapping>
   <class name="org.hisp.dhis.patient.Patient" table="patient">
 
     <id name="id" column="patientid">
       <generator class="native" />
     </id>
+    &identifiableProperties;
 
     <property name="firstName" column="firstname" length="50" />
 
@@ -44,7 +46,8 @@
 
     <set name="attributes" table="patient_attributes">
       <key column="patientid" foreign-key="fk_patient_attributes_patientid" />
-      <many-to-many class="org.hisp.dhis.patient.PatientAttribute" column="patientattributeid" foreign-key="fk_patient_patientattributeid" />
+      <many-to-many class="org.hisp.dhis.patient.PatientAttribute" column="patientattributeid"
+        foreign-key="fk_patient_patientattributeid" />
     </set>
 
     <many-to-one name="representative" class="org.hisp.dhis.patient.Patient" column="representativeid"
@@ -52,8 +55,8 @@
 
     <many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid"
       foreign-key="fk_patient_organisationunitid" />
- 	
- 	<many-to-one name="healthWorker" column="healthworkerid" class="org.hisp.dhis.user.User" foreign-key="fk_user_patientid" />
-    
+
+    <many-to-one name="healthWorker" column="healthworkerid" class="org.hisp.dhis.user.User" foreign-key="fk_user_patientid" />
+
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidateAddRelationshipPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidateAddRelationshipPatientAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidateAddRelationshipPatientAction.java	2013-09-06 08:24:36 +0000
@@ -28,13 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
+import com.opensymphony.xwork2.Action;
 import org.apache.commons.lang.StringUtils;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.i18n.I18n;
@@ -49,7 +43,11 @@
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
 
-import com.opensymphony.xwork2.Action;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 public class ValidateAddRelationshipPatientAction
     implements Action
@@ -164,8 +162,8 @@
         int endIndex = fullName.lastIndexOf( ' ' );
 
         String firstName = fullName.substring( 0, startIndex );
-        String middleName = "";
-        String lastName = "";
+        String middleName;
+        String lastName;
 
         if ( startIndex == endIndex )
         {
@@ -192,7 +190,7 @@
                 boolean flagDuplicate = false;
                 for ( Patient p : patients )
                 {
-                    if ( id == null || (id != null && p.getId().intValue() != id.intValue()) )
+                    if ( id == null || (id != null && p.getId() != id) )
                     {
                         flagDuplicate = true;
                         Collection<PatientAttributeValue> patientAttributeValues = patientAttributeValueService
@@ -221,7 +219,7 @@
         }
         else
         {
-            p.setBirthDateFromAge( age.intValue(), ageType );
+            p.setBirthDateFromAge( age, ageType );
         }
 
         HttpServletRequest request = ServletActionContext.getRequest();
@@ -230,8 +228,9 @@
 
         if ( identifiers != null && identifiers.size() > 0 )
         {
-            String value = null;
+            String value;
             String idDuplicate = "";
+
             for ( PatientIdentifierType idType : identifiers )
             {
                 // If underAge is TRUE : Only check duplicate on
@@ -243,7 +242,7 @@
                     {
                         PatientIdentifier identifier = patientIdentifierService.get( idType, value );
                         if ( identifier != null
-                            && (id == null || identifier.getPatient().getId().intValue() != id.intValue()) )
+                            && (id == null || identifier.getPatient().getId() != id) )
                         {
                             idDuplicate += idType.getName() + ", ";
                         }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2013-09-02 18:49:20 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java	2013-09-06 08:24:36 +0000
@@ -28,12 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
+import com.opensymphony.xwork2.Action;
 import org.apache.commons.lang.StringUtils;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.i18n.I18n;
@@ -50,11 +45,13 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.validation.ValidationCriteria;
 
-import com.opensymphony.xwork2.Action;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author Abyot Asalefew Gizaw
- * @version $Id$
  */
 public class ValidatePatientAction
     implements Action
@@ -159,7 +156,7 @@
                     boolean flagDuplicate = false;
                     for ( Patient p : patients )
                     {
-                        if ( id == null || (id != null && p.getId().intValue() != id.intValue()) )
+                        if ( id == null || (id != null && p.getId() != id) )
                         {
                             flagDuplicate = true;
                             Collection<PatientAttributeValue> patientAttributeValues = patientAttributeValueService
@@ -220,7 +217,7 @@
                         PatientIdentifier identifier = patientIdentifierService.get( idType, value );
 
                         if ( identifier != null
-                            && (id == null || identifier.getPatient().getId().intValue() != id.intValue()) )
+                            && (id == null || identifier.getPatient().getId() != id) )
                         {
                             idDuplicate += idType.getName() + ", ";
                         }
@@ -254,7 +251,7 @@
         }
         else if ( age != null )
         {
-            p.setBirthDateFromAge( age.intValue(), Patient.AGE_TYPE_YEAR );
+            p.setBirthDateFromAge( age, Patient.AGE_TYPE_YEAR );
         }
 
         if ( programId != null )