← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12624: Patient store, code style

 

------------------------------------------------------------
revno: 12624
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-10-14 11:28:36 +0200
message:
  Patient store, code style
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Notification.java
  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


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

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java	2013-09-27 13:56:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java	2013-10-14 09:28:36 +0000
@@ -69,7 +69,8 @@
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-public abstract class AbstractPersonService implements PersonService
+public abstract class AbstractPersonService 
+    implements PersonService
 {
     // -------------------------------------------------------------------------
     // Dependencies

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Notification.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Notification.java	2013-10-10 05:42:48 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Notification.java	2013-10-14 09:28:36 +0000
@@ -31,7 +31,6 @@
 import java.io.IOException;
 
 import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
-import org.hisp.dhis.api.mobile.model.Model;
 
  /**
  * @author Nguyen Kim Lai

=== 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-10-08 17:16:47 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-10-14 09:28:36 +0000
@@ -349,8 +349,7 @@
     }
 
     @Override
-    public Collection<Patient> getPatientsLikeName( OrganisationUnit organisationUnit, String name, Integer min,
-        Integer max )
+    public Collection<Patient> getPatientsLikeName( OrganisationUnit organisationUnit, String name, Integer min, Integer max )
     {
         return patientStore.getByOrgUnitAndNameLike( organisationUnit, name, min, max );
     }

=== 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-10-11 09:19:08 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-10-14 09:28:36 +0000
@@ -63,6 +63,8 @@
 import java.util.HashSet;
 import java.util.List;
 
+import static org.hisp.dhis.patient.Patient.*;
+
 /**
  * @author Abyot Asalefew Gizaw
  */
@@ -130,7 +132,6 @@
     @Override
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> get( String name, Date birthdate, String gender )
-
     {
         Criteria criteria = getCriteria();
         Conjunction con = Restrictions.conjunction();
@@ -177,6 +178,7 @@
         {
             query.setFirstResult( min ).setMaxResults( max );
         }
+        
         return query.list();
     }
 
@@ -200,6 +202,7 @@
     }
 
     @Override
+    //TODO this method must be changed - cannot retrieve one by one
     public Collection<Patient> getByOrgUnitProgram( OrganisationUnit organisationUnit, Program program, Integer min,
         Integer max )
     {
@@ -234,6 +237,7 @@
     }
 
     @Override
+    //TODO this method must be changed - cannot retrieve one by one
     public Collection<Patient> getByOrgUnitProgramGender( OrganisationUnit organisationUnit, Program program,
         String gender, Integer min, Integer max )
     {
@@ -300,6 +304,7 @@
     }
 
     @Override
+    //TODO this method must be changed - cannot retrieve one by one
     public Collection<Patient> getByProgram( Program program, String gender, Integer min, Integer max )
     {
         List<Patient> patients = new ArrayList<Patient>();
@@ -373,9 +378,9 @@
     }
 
     @Override
+    //TODO this method must be changed - cannot retrieve one by one
     public Collection<Patient> search( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
-        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer statusEnrollment, Integer min,
-        Integer max )
+        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer statusEnrollment, Integer min, Integer max )
     {
         String sql = searchPatientSql( false, searchKeys, orgunits, followup, patientAttributes, null,
             statusEnrollment, min, max );
@@ -495,12 +500,7 @@
             for ( PatientIdentifierType identifierType : identifierTypes )
             {
                 sql += "(select identifier from patientidentifier where patientid=p.patientid and patientidentifiertypeid="
-                    + identifierType.getId()
-                    + " ) as "
-                    + Patient.PREFIX_IDENTIFIER_TYPE
-                    + "_"
-                    + identifierType.getId()
-                    + " ,";
+                    + identifierType.getId() + " ) as " + PREFIX_IDENTIFIER_TYPE + "_" + identifierType.getId() + " ,";
             }
         }
 
@@ -509,8 +509,7 @@
             for ( PatientAttribute patientAttribute : patientAttributes )
             {
                 sql += "(select value from patientattributevalue where patientid=p.patientid and patientattributeid="
-                    + patientAttribute.getId() + " ) as " + Patient.PREFIX_PATIENT_ATTRIBUTE + "_"
-                    + patientAttribute.getId() + " ,";
+                    + patientAttribute.getId() + " ) as " + PREFIX_PATIENT_ATTRIBUTE + "_" + patientAttribute.getId() + " ,";
             }
         }
 
@@ -547,18 +546,19 @@
                 value = keys[2];
             }
 
-            if ( keys[0].equals( Patient.PREFIX_FIXED_ATTRIBUTE ) )
+            if ( keys[0].equals( PREFIX_FIXED_ATTRIBUTE ) )
             {
                 patientWhere += patientOperator;
-                if ( id.equals( Patient.FIXED_ATTR_BIRTH_DATE ) )
+                
+                if ( id.equals( FIXED_ATTR_BIRTH_DATE ) )
                 {
                     patientWhere += " p." + id + value;
                 }
-                else if ( id.equals( Patient.FIXED_ATTR_AGE ) )
+                else if ( id.equals( FIXED_ATTR_AGE ) )
                 {
                     patientWhere += " ((DATE(now()) - DATE(birthdate))/365) " + value;
                 }
-                else if ( id.equals( Patient.FIXED_ATTR_REGISTRATION_DATE ) )
+                else if ( id.equals( FIXED_ATTR_REGISTRATION_DATE ) )
                 {
                     patientWhere += "p." + id + value;
                 }
@@ -568,7 +568,7 @@
                 }
                 patientOperator = " and ";
             }
-            else if ( keys[0].equals( Patient.PREFIX_IDENTIFIER_TYPE ) )
+            else if ( keys[0].equals( PREFIX_IDENTIFIER_TYPE ) )
             {
 
                 String[] keyValues = id.split( " " );
@@ -576,8 +576,7 @@
                 String opt = "";
                 for ( String v : keyValues )
                 {
-                    patientWhere += opt + " lower( p.name ) like '%" + v + "%' or lower(pi.identifier) like '%" + v
-                        + "%' ";
+                    patientWhere += opt + " lower( p.name ) like '%" + v + "%' or lower(pi.identifier) like '%" + v + "%' ";
                     opt = "or";
                 }
 
@@ -586,42 +585,47 @@
                     String otherId = keyValues[0] + "  " + keyValues[1];
                     patientWhere += " or lower( p.name ) like '%" + otherId + "%'  ";
                 }
+                
                 patientWhere += ")";
                 patientOperator = " and ";
                 hasIdentifier = true;
             }
-            else if ( keys[0].equals( Patient.PREFIX_PATIENT_ATTRIBUTE ) )
+            else if ( keys[0].equals( PREFIX_PATIENT_ATTRIBUTE ) )
             {
                 sql += "(select value from patientattributevalue where patientid=p.patientid and patientattributeid="
-                    + id + " ) as " + Patient.PREFIX_PATIENT_ATTRIBUTE + "_" + id + ",";
+                    + id + " ) as " + PREFIX_PATIENT_ATTRIBUTE + "_" + id + ",";
 
                 String[] keyValues = value.split( " " );
                 otherWhere += operator + "(";
                 String opt = "";
+                
                 for ( String v : keyValues )
                 {
-                    otherWhere += opt + " lower(" + Patient.PREFIX_PATIENT_ATTRIBUTE + "_" + id + ") like '%" + v
+                    otherWhere += opt + " lower(" + PREFIX_PATIENT_ATTRIBUTE + "_" + id + ") like '%" + v
                         + "%'";
                     opt = "or";
                 }
+                
                 otherWhere += ")";
-
                 operator = " and ";
             }
-            else if ( keys[0].equals( Patient.PREFIX_PROGRAM ) )
+            else if ( keys[0].equals( PREFIX_PROGRAM ) )
             {
                 sql += "(select programid from programinstance pi where patientid=p.patientid and programid=" + id;
+                
                 if ( statusEnrollment != null )
                 {
                     sql += " and pi.status=" + statusEnrollment;
                 }
-                sql += " limit 1 ) as " + Patient.PREFIX_PROGRAM + "_" + id + ",";
-                otherWhere += operator + Patient.PREFIX_PROGRAM + "_" + id + "=" + id;
+                
+                sql += " limit 1 ) as " + PREFIX_PROGRAM + "_" + id + ",";
+                otherWhere += operator + PREFIX_PROGRAM + "_" + id + "=" + id;
                 operator = " and ";
             }
-            else if ( keys[0].equals( Patient.PREFIX_PROGRAM_INSTANCE ) )
+            else if ( keys[0].equals( PREFIX_PROGRAM_INSTANCE ) )
             {
                 sql += "(select pi." + id + " from programinstance pi where patientid=p.patientid and pi.status=0 ";
+                
                 if ( keys.length == 5 )
                 {
                     sql += " and pi.programid=" + keys[4];
@@ -630,11 +634,12 @@
                 {
                     sql += " limit 1 ";
                 }
-                sql += ") as " + Patient.PREFIX_PROGRAM_INSTANCE + "_" + id + ",";
-                otherWhere += operator + Patient.PREFIX_PROGRAM_INSTANCE + "_" + id + keys[2];
+                
+                sql += ") as " + PREFIX_PROGRAM_INSTANCE + "_" + id + ",";
+                otherWhere += operator + PREFIX_PROGRAM_INSTANCE + "_" + id + keys[2];
                 operator = " and ";
             }
-            else if ( keys[0].equals( Patient.PREFIX_PROGRAM_EVENT_BY_STATUS ) )
+            else if ( keys[0].equals( PREFIX_PROGRAM_EVENT_BY_STATUS ) )
             {
                 isSearchEvent = true;
                 isPriorityEvent = Boolean.parseBoolean( keys[5] );
@@ -654,17 +659,20 @@
                             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 orgunit
                             else if ( !keys[4].equals( "0" ) )
                             {
                                 patientWhere += " and psi.organisationunitid=" + keys[4];
                             }
+                            
                             patientWhere += ")";
                             operatorStatus = " OR ";
                             condition = "";
@@ -680,11 +688,13 @@
                                 patientWhere += " and psi.organisationunitid in( "
                                     + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
                             }
+                            
                             // get events by selected orgunit
                             else if ( !keys[4].equals( "0" ) )
                             {
                                 patientWhere += " and psi.organisationunitid=" + keys[4];
                             }
+                            
                             patientWhere += ")";
                             operatorStatus = " OR ";
                             condition = "";
@@ -693,17 +703,20 @@
                             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 orgunit
                             else if ( !keys[4].equals( "0" ) )
                             {
                                 patientWhere += " and p.organisationunitid=" + keys[4];
                             }
+                            
                             patientWhere += ")";
                             operatorStatus = " OR ";
                             condition = "";
@@ -711,18 +724,21 @@
                         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 not null  and (DATE(now()) - DATE(psi.duedate) > 0) ";
+                                + "' and psi.status is not 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 orgunit
                             else if ( !keys[4].equals( "0" ) )
                             {
                                 patientWhere += " and p.organisationunitid=" + keys[4];
                             }
+                            
                             patientWhere += ")";
                             operatorStatus = " OR ";
                             condition = "";
@@ -730,12 +746,14 @@
                         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 orgunit
                             else if ( !keys[4].equals( "0" ) )
                             {
@@ -753,11 +771,11 @@
                 {
                     patientWhere += ")";
                 }
+                
                 patientWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";
                 patientOperator = " and ";
-
             }
-            else if ( keys[0].equals( Patient.PREFIX_PROGRAM_STAGE ) )
+            else if ( keys[0].equals( PREFIX_PROGRAM_STAGE ) )
             {
                 isSearchEvent = true;
                 patientWhere += patientOperator + "pgi.patientid=p.patientid and psi.programstageid=" + id + " and ";
@@ -799,9 +817,11 @@
         sql = sql.substring( 0, sql.length() - 1 ) + " "; // Removing last comma
 
         String from = " from patient p ";
+        
         if ( isSearchEvent )
         {
             String subSQL = " , psi.programstageinstanceid as programstageinstanceid, pgs.name as programstagename, psi.duedate as duedate ";
+            
             if ( isPriorityEvent )
             {
                 subSQL += ",pgi.followup ";
@@ -812,6 +832,7 @@
             {
                 orderBy = " ORDER BY p.patientid, p.name, duedate asc ";
             }
+            
             sql = sql + subSQL + from + " inner join programinstance pgi on " + " (pgi.patientid=p.patientid) "
                 + " inner join programstageinstance psi on " + " (psi.programinstanceid=pgi.programinstanceid) "
                 + " inner join programstage pgs on (pgs.programstageid=psi.programstageid) ";
@@ -867,13 +888,14 @@
     }
 
     @Override
+    //TODO this method must be changed - cannot retrieve one by one
     public Collection<Patient> getByFullName( String fullName, Integer orgunitId )
     {
         List<Patient> patients = new ArrayList<Patient>();
 
         fullName = fullName.toLowerCase();
-        String sql = "SELECT patientid FROM patient where lower( " + statementBuilder.getPatientFullName() + ") "
-            + "='" + fullName + "'";
+        String sql = "SELECT patientid FROM patient where lower( " + statementBuilder.getPatientFullName() + ") ='" + fullName + "'";
+        
         if ( orgunitId != null && orgunitId != 0 )
         {
             sql += " and organisationunitid=" + orgunitId;
@@ -922,9 +944,7 @@
         {
             for ( OrganisationUnit orgunit : orgunits )
             {
-
-                orgUnitIds
-                    .addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
+                orgUnitIds.addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
                 orgUnitIds.remove( orgunit.getId() );
             }
         }