← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1949: Added Service to get ProgramInstances by Orgunit; Changed accordingly in MultiDataEntry&SummaryRe...

 

------------------------------------------------------------
revno: 1949
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-10-25 16:42:04 +0530
message:
  Added Service to get ProgramInstances by Orgunit; Changed accordingly in MultiDataEntry&SummaryReport
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.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/program/ProgramInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java	2009-11-13 15:59:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java	2010-10-25 11:12:04 +0000
@@ -28,6 +28,7 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 
 /**
@@ -66,4 +67,5 @@
 
     Collection<ProgramInstance> getProgramInstances( Patient patient, Program program, boolean completed );
 
+    Collection<ProgramInstance> getProgramInstances( Program program, OrganisationUnit organisationUnit );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java	2009-10-29 16:22:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java	2010-10-25 11:12:04 +0000
@@ -29,6 +29,7 @@
 import java.util.Collection;
 
 import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 
 /**
@@ -57,4 +58,6 @@
     Collection<ProgramInstance> get( Patient patient, Program program );
     
     Collection<ProgramInstance> get( Patient patient, Program program, boolean completed );
+    
+    Collection<ProgramInstance> get( Program program, OrganisationUnit organisationUnit );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2009-11-19 18:43:20 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2010-10-25 11:12:04 +0000
@@ -28,6 +28,7 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -123,4 +124,10 @@
     {
         return programInstanceStore.get( patient, program, completed );
     }
+
+    public Collection<ProgramInstance> getProgramInstances( Program program, OrganisationUnit organisationUnit )
+    {
+        return programInstanceStore.get( program, organisationUnit );
+    }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2009-10-29 16:22:42 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2010-10-25 11:12:04 +0000
@@ -31,6 +31,7 @@
 
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
@@ -98,4 +99,12 @@
         return getCriteria( Restrictions.eq( "patient", patient ), Restrictions.eq( "program", program ),
             Restrictions.eq( "completed", completed ) ).list();
     }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<ProgramInstance> get( Program program, OrganisationUnit organisationUnit )
+    {
+        return getCriteria( Restrictions.eq( "program", program ), Restrictions.isNull( "endDate" ) ).createAlias( "patient", "patient" )
+        .add( Restrictions.eq( "patient.organisationUnit", organisationUnit ) ).list();
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2010-10-20 13:34:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2010-10-25 11:12:04 +0000
@@ -204,23 +204,10 @@
         selectedStateManager.setSelectedProgram( program );
         
         // ---------------------------------------------------------------------
-        // Getting the list of Patients that are related to selected OrganisationUnit
-        // ---------------------------------------------------------------------
-        
-        patientListByOrgUnit = new ArrayList<Patient>();
-        
-        patientListByOrgUnit.addAll( patientService.getPatients( organisationUnit ) );
-        
-        if( sortPatientAttributeId != null )
-        {
-            sortingAttribute = patientAttributeService.getPatientAttribute( sortPatientAttributeId );
-        }
-        
-        // ---------------------------------------------------------------------
         // Program instances for the selected program
         // ---------------------------------------------------------------------
         
-        Collection<ProgramInstance> selectedProgramInstances = programInstanceService.getProgramInstances( program );
+        Collection<ProgramInstance> selectedProgramInstances = programInstanceService.getProgramInstances( program, organisationUnit );
         
         Collection<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
 
@@ -228,13 +215,6 @@
         {
             Patient patient = programInstance.getPatient();
             
-            //taking patient present in selected orgunit
-            if ( !patientListByOrgUnit.contains( patient ) || programInstance.getEndDate() != null )
-            {
-                patientListByOrgUnit.remove( patient );
-                continue;
-            }
-            
             if ( !programInstance.isCompleted() )
             {
                 programInstanceMap.put( patient, programInstance );
@@ -244,21 +224,21 @@
                 PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( patient, sortingAttribute );
                 
                 patinetAttributeValueMap.put( patient, patientAttributeValue );
-                
-                System.out.println( patient.getFullName() );
-            }
-            else
-            {
-                patientListByOrgUnit.remove( patient );
             }
 
             programStageInstances.addAll( programInstance.getProgramStageInstances() );
         }
         
+        // ---------------------------------------------------------------------
         // Sorting PatientList by slected Patient Attribute
+        // ---------------------------------------------------------------------
+
+        patientListByOrgUnit = new ArrayList<Patient>();
         
         if( sortPatientAttributeId != null )
         {
+            sortingAttribute = patientAttributeService.getPatientAttribute( sortPatientAttributeId );
+            
             patientListByOrgUnit = patientService.sortPatientsByAttribute( programInstanceMap.keySet(), sortingAttribute );
         }
         else
@@ -266,10 +246,8 @@
             patientListByOrgUnit = programInstanceMap.keySet();
         }
 
-        System.out.println("sortPatientAttributeId : "+sortPatientAttributeId);
         colorMap = programStageInstanceService.colorProgramStageInstances( programStageInstances );
 
-
         return SUCCESS;
     }    
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java	2010-10-20 13:34:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java	2010-10-25 11:12:04 +0000
@@ -35,7 +35,6 @@
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
@@ -188,28 +187,16 @@
 
         programs = programService.getPrograms( organisationUnit );
 
-        // Getting the list of Patients that are related to selected OrganisationUnit
-        
-        Collection<Patient> patientListByOrgUnit = new ArrayList<Patient>();
-        patientListByOrgUnit.addAll( patientService.getPatients( organisationUnit ) );
-        
         // ---------------------------------------------------------------------
         // Program instances for the selected program
         // ---------------------------------------------------------------------
-        
-        Collection<ProgramInstance> selectedProgramInstances = programInstanceService.getProgramInstances( program );
+
+        Collection<ProgramInstance> selectedProgramInstances = programInstanceService.getProgramInstances( program, organisationUnit );
 
         Collection<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
 
         for ( ProgramInstance programInstance : selectedProgramInstances )
         {
-        	Patient patient = programInstance.getPatient();
-            //taking patient present in selected orgunit
-            if ( !patientListByOrgUnit.contains( patient ) || programInstance.getEndDate() != null )
-            {
-                continue;
-            }
-            
             if ( !programInstance.isCompleted() )
             {
                 programInstances.add( programInstance );


Follow ups