← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1733: Commit service for patient module.

 

------------------------------------------------------------
revno: 1733
committer: Viet <Viet@Viet-Laptop>
branch nick: trunk
timestamp: Mon 2010-04-05 19:41:21 +0700
message:
  Commit service for patient module.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.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/HibernatePatientIdentifierStore.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/patientattributevalue/DefaultPatientAttributeValueService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java	2010-03-09 12:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java	2010-04-05 12:41:21 +0000
@@ -201,4 +201,14 @@
         return patientIdentifierStore.listPatientByOrganisationUnit( organisationUnit );
     }
 
+    public int countGetPatientsByIdentifier( String identifier )
+    {
+        return patientIdentifierStore.countGetPatientsByIdentifier( identifier );
+    }
+
+    public Collection<Patient> getPatientsByIdentifier( String identifier, int min, int max )
+    {
+        return patientIdentifierStore.getPatientsByIdentifier( identifier, min, max );
+    }
+
 }

=== 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	2010-03-09 12:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2010-04-05 12:41:21 +0000
@@ -31,6 +31,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -38,6 +39,10 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.relationship.Relationship;
+import org.hisp.dhis.relationship.RelationshipService;
+import org.hisp.dhis.relationship.RelationshipType;
+import org.hisp.dhis.relationship.RelationshipTypeService;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -86,6 +91,20 @@
     {
         this.patientIdentifierTypeService = patientIdentifierTypeService;
     }
+    
+    private RelationshipService relationshipService;
+    
+    public void setRelationshipService( RelationshipService relationshipService )
+    {
+        this.relationshipService = relationshipService;
+    }
+    
+    private RelationshipTypeService relationshipTypeService;
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
 
     // -------------------------------------------------------------------------
     // PatientDataValue
@@ -167,16 +186,6 @@
 
     public Collection<Patient> getPatientsByOrgUnit( OrganisationUnit organisationUnit, int min, int max )
     {
-//        Collection<Patient> patients = new ArrayList<Patient>();
-//
-//        for ( PatientIdentifier patientIdentifier : patientIdentifierService
-//            .getPatientIdentifiersByOrgUnit( organisationUnit ) )
-//        {
-//            patients.add( patientIdentifier.getPatient() );
-//        }
-//        
-//        return patients;
-    	
         return  patientIdentifierService.listPatientByOrganisationUnit( organisationUnit ,  min,  max );
     }
 
@@ -269,4 +278,158 @@
     {
         return patientIdentifierService.listPatientByOrganisationUnit( organisationUnit );
     }
+
+    public int countGetPatients( String searchText )
+    {
+        return patientStore.countGetPatientsByNames( searchText )+patientIdentifierService.countGetPatientsByIdentifier( searchText );
+    }
+
+    public Collection<Patient> getPatients( String searchText, int min, int max )
+    {
+        int countPatientName = patientStore.countGetPatientsByNames( searchText );
+        
+        Set<Patient> patients = new HashSet<Patient>();
+        
+        if( max < countPatientName )
+        {
+            patients.addAll(  getPatientsByNames( searchText, min, max ) );
+            
+            min = min - patients.size();
+        }else {
+            if( min <= countPatientName )
+            {
+                patients.addAll(  getPatientsByNames( searchText, min, countPatientName ) );
+                
+                min = 0;
+                max = max - countPatientName;
+                
+                Collection<Patient> patientsByIdentifier = patientIdentifierService.getPatientsByIdentifier( searchText, min, max );
+                
+                patients.addAll( patientsByIdentifier );
+            }else
+            {
+                min = 0;
+                max = max - countPatientName;
+                
+                Collection<Patient> patientsByIdentifier = patientIdentifierService.getPatientsByIdentifier( searchText, min, max );
+                
+                patients.addAll( patientsByIdentifier );
+            }
+        }
+        return patients;
+    }
+
+    public int countnGetPatientsByNames( String name )
+    {
+        return patientStore.countGetPatientsByNames( name );
+    }
+
+    public Collection<Patient> getPatientsByNames( String name, int min, int max )
+    {
+        return patientStore.getPatientsByNames( name, min, max );
+    }
+   
+    public void createPatient( Patient patient, OrganisationUnit orgUnit, Integer representativeId,
+        Integer relationshipTypeId,  List<PatientAttributeValue> patientAttributeValues ) 
+    {
+        
+        patientStore.save( patient );
+
+        Integer.parseInt( "ABC" );
+        
+        for( PatientAttributeValue pav : patientAttributeValues )
+        {
+            patientAttributeValueService.savePatientAttributeValue( pav );
+        }
+        
+        
+        //-------------------------------------------------------------------------
+        // If underAge = true : save representative information.
+        //-------------------------------------------------------------------------
+        
+        if ( patient.isUnderAge() )
+        {
+            if( representativeId != null )
+            {
+                Patient representative = patientStore.get( representativeId );
+                if( representative != null )
+                {
+                    patient.setRepresentative( representative );
+                
+                    Relationship rel = new Relationship();
+                    rel.setPatientA( representative );
+                    rel.setPatientB(  patient );
+                    
+                    if( relationshipTypeId != null )
+                    {
+                        RelationshipType relType = relationshipTypeService.getRelationshipType( relationshipTypeId );
+                        if( relType != null )
+                        {
+                            rel.setRelationshipType( relType );
+                            relationshipService.saveRelationship( rel );
+                        }
+                    }
+                }
+            }
+        }
+        
+    }
+    
+    public void updatePatient( Patient patient, OrganisationUnit orgUnit, Integer representativeId,
+        Integer relationshipTypeId,  List<PatientAttributeValue> valuesForSave,    List<PatientAttributeValue> valuesForUpdate,  Collection<PatientAttributeValue> valuesForDelete ) 
+    {
+        
+        patientStore.update( patient );
+
+        for( PatientAttributeValue av : valuesForSave )
+        {
+            patientAttributeValueService.savePatientAttributeValue( av );
+        }
+        
+        for ( PatientAttributeValue av : valuesForUpdate )
+        {
+            patientAttributeValueService.updatePatientAttributeValue( av );
+        }
+        
+        for ( PatientAttributeValue av : valuesForDelete )
+        {
+            patientAttributeValueService.deletePatientAttributeValue( av );
+        }
+        
+        //-------------------------------------------------------------------------
+        // If underAge = true : save representative information.
+        //-------------------------------------------------------------------------
+        
+        if ( patient.isUnderAge() )
+        {
+          
+            if( representativeId != null  )
+            {
+                if( patient.getRepresentative() == null ||  patient.getRepresentative().getId() != representativeId )
+                {
+                    Patient representative = patientStore.get( representativeId );
+                    
+                    if( representative != null )
+                    {
+                        patient.setRepresentative( representative );
+                    
+                        Relationship rel = new Relationship();
+                        rel.setPatientA( representative );
+                        rel.setPatientB(  patient );
+                        
+                        if( relationshipTypeId != null )
+                        {
+                            RelationshipType relType = relationshipTypeService.getRelationshipType( relationshipTypeId );
+                            if( relType != null )
+                            {
+                                rel.setRelationshipType( relType );
+                                relationshipService.saveRelationship( rel );
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
 }

=== 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	2010-03-09 12:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java	2010-04-05 12:41:21 +0000
@@ -127,4 +127,15 @@
         .setProjection( Projections.distinct( Projections.property( "patient" ) ) ).list();
     }
 
+    public int countGetPatientsByIdentifier( String identifier )
+    {
+        return (Integer)getCriteria( Restrictions.ilike( "identifier", "%" + identifier + "%" ) ).setProjection( Projections.rowCount() ).uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<Patient> getPatientsByIdentifier( String identifier, int min, int max )
+    {
+        return getCriteria( Restrictions.ilike( "identifier", "%" + identifier + "%" ) ).setProjection( Projections.property( "patient" ) ).setFirstResult( min ).setMaxResults( max ).list();
+    }
+
 }

=== 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	2010-03-03 11:02:53 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2010-04-05 12:41:21 +0000
@@ -34,15 +34,19 @@
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Conjunction;
 import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projection;
+import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientStore;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * @author Abyot Asalefew Gizaw
  * @version $Id$
  */
+@Transactional
 public class HibernatePatientStore
     extends HibernateGenericStore<Patient> implements PatientStore
 {    
@@ -97,4 +101,22 @@
         
         return crit.list();
     }
+
+    public int countGetPatientsByNames( String name )
+    {
+        return (Integer)getCriteria( 
+            Restrictions.disjunction().add( Restrictions.ilike( "firstName", "%" + name + "%" ) ).add(
+                Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
+                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) ).setProjection( Projections.rowCount() ).uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<Patient> getPatientsByNames( String name, int min, int max )
+    {
+        return getCriteria( 
+            Restrictions.disjunction().add( Restrictions.ilike( "firstName", "%" + name + "%" ) ).add(
+                Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
+                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) ).setFirstResult( min ).setMaxResults( max ).list(); 
+    }
+    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java	2010-03-04 04:56:15 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java	2010-04-05 12:41:21 +0000
@@ -193,5 +193,16 @@
         return patientAttributeValueStore.getPatient( attribute, value );
     }
 
+    public int countSearchPatientAttributeValue( PatientAttribute patientAttribute, String searchText )
+    {
+        return patientAttributeValueStore.countSearchPatientAttributeValue( patientAttribute, searchText );
+    }
+
+    public Collection<Patient> searchPatientAttributeValue( PatientAttribute patientAttribute,
+        String searchText, int min, int max )
+    {
+        return patientAttributeValueStore.searchPatientAttributeValue( patientAttribute, searchText, min, max );
+    }
+
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2010-03-12 13:25:09 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2010-04-05 12:41:21 +0000
@@ -117,4 +117,18 @@
         return getCriteria( Restrictions.and( Restrictions.eq( "patientAttribute", attribute ), Restrictions.eq( "value", value ) ))
             .setProjection( Projections.property( "patient" ) ).list();
     }
+
+    public int countSearchPatientAttributeValue( PatientAttribute patientAttribute, String searchText )
+    {
+        return (Integer)getCriteria( Restrictions.eq( "patientAttribute", patientAttribute ),
+            Restrictions.ilike( "value", "%" + searchText + "%" ) ).setProjection( Projections.rowCount() ).uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<Patient> searchPatientAttributeValue( PatientAttribute patientAttribute,
+        String searchText, int min, int max )
+    {
+        return getCriteria( Restrictions.eq( "patientAttribute", patientAttribute ),
+            Restrictions.ilike( "value", "%" + searchText + "%" ) ).setProjection( Projections.property( "patient" ) ).setFirstResult( min ).setMaxResults( max ).list();
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2010-03-09 07:55:42 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2010-04-05 12:41:21 +0000
@@ -160,6 +160,10 @@
 			ref="org.hisp.dhis.patient.PatientIdentifierTypeService"/>	
 		<property name="patientAttributeService"
 			ref="org.hisp.dhis.patient.PatientAttributeService" />
+		<property name="relationshipTypeService"
+			ref="org.hisp.dhis.relationship.RelationshipTypeService" />
+		<property name="relationshipService"
+			ref="org.hisp.dhis.relationship.RelationshipService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientIdentifierService" class="org.hisp.dhis.patient.DefaultPatientIdentifierService">