← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12274: support search for system identifiers in personController and personService (and patientStore)

 

------------------------------------------------------------
revno: 12274
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-27 13:09:00 +0200
message:
  support search for system identifiers in personController and personService (and patientStore)
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.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-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java	2013-09-23 15:13:58 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java	2013-09-27 11:09:00 +0000
@@ -28,9 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.Date;
-
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
@@ -45,6 +42,9 @@
 import org.hisp.dhis.system.util.DateUtils;
 import org.springframework.jdbc.core.JdbcTemplate;
 
+import java.util.Collection;
+import java.util.Date;
+
 /**
  * @author Abyot Asalefew Gizaw
  * @version $Id$
@@ -85,20 +85,20 @@
             Restrictions.eq( "identifier", identifier ) ).uniqueResult();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<PatientIdentifier> getAll( PatientIdentifierType type, String identifier )
     {
         return getCriteria( Restrictions.eq( "identifierType", type ), Restrictions.eq( "identifier", identifier ) )
             .list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<PatientIdentifier> getByIdentifier( String identifier )
     {
         return getCriteria( Restrictions.ilike( "identifier", "%" + identifier + "%" ) ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<PatientIdentifier> getByType( PatientIdentifierType identifierType )
     {
         return getCriteria( Restrictions.eq( "identifierType", identifierType ) ).list();
@@ -116,7 +116,7 @@
             Restrictions.eq( "patient", patient ) ).uniqueResult();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<PatientIdentifier> getPatientIdentifiers( Patient patient )
     {
         return getCriteria( Restrictions.eq( "patient", patient ) ).list();
@@ -124,6 +124,14 @@
 
     public Patient getPatient( PatientIdentifierType idenType, String value )
     {
+        if ( idenType == null )
+        {
+            // assume system identifier
+            return (Patient) getCriteria(
+                Restrictions.and( Restrictions.eq( "identifier", value ), Restrictions.isNull( "identifierType" ) ) )
+                .setProjection( Projections.property( "patient" ) ).uniqueResult();
+        }
+
         return (Patient) getCriteria(
             Restrictions.and( Restrictions.eq( "identifierType", idenType ), Restrictions.eq( "identifier", value ) ) )
             .setProjection( Projections.property( "patient" ) ).uniqueResult();
@@ -131,16 +139,16 @@
 
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getPatientsByIdentifier( String identifier, Integer min, Integer max )
-    {       
-        if( min != null & max != null )
+    {
+        if ( min != null & max != null )
         {
             return getCriteria( Restrictions.ilike( "identifier", "%" + identifier + "%" ) )
-            .setProjection( Projections.property( "patient" ) ).setFirstResult( min ).setMaxResults( max ).list();
+                .setProjection( Projections.property( "patient" ) ).setFirstResult( min ).setMaxResults( max ).list();
         }
         else
         {
             return getCriteria( Restrictions.ilike( "identifier", "%" + identifier + "%" ) )
-            .setProjection( Projections.property( "patient" ) ).list();
+                .setProjection( Projections.property( "patient" ) ).list();
         }
     }
 
@@ -151,14 +159,14 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<PatientIdentifier> get( Collection<PatientIdentifierType> identifierTypes, Patient patient )
     {
         return getCriteria( Restrictions.in( "identifierType", identifierTypes ), Restrictions.eq( "patient", patient ) )
             .list();
     }
 
-    @SuppressWarnings( "deprecation" )
+    @SuppressWarnings("deprecation")
     public boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier,
         Integer patientId, OrganisationUnit orgunit, Program program, PeriodType periodType )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java	2013-09-27 10:43:38 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java	2013-09-27 11:09:00 +0000
@@ -98,7 +98,7 @@
             Identifier id = new Identifier( identifierType, identifier );
             persons.getPersons().add( personService.getPerson( id ) );
         }
-        if ( programUid != null && gender != null )
+        else if ( programUid != null && gender != null )
         {
             OrganisationUnit organisationUnit = getOrganisationUnit( orgUnitUid );
             Program program = getProgram( programUid );