← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7034: (patient) Add options to search patients by selected orgunit.

 

------------------------------------------------------------
revno: 7034
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-05-24 20:53:25 +0700
message:
  (patient) Add options to search patients by selected orgunit.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStore.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/listPatient.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm


--
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/patientattributevalue/PatientAttributeValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueService.java	2012-03-27 01:29:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueService.java	2012-05-24 13:53:25 +0000
@@ -30,6 +30,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeOption;
@@ -76,15 +77,19 @@
     Collection<Patient> getPatient( PatientAttribute attribute, String value );
     
     Collection<Patient> searchPatients( PatientAttribute patientAttribute, String searchText, int min, int max);
-        
+    
     Collection<Patient> searchPatients( PatientAttribute patientAttribute, String searchText );
 
     Collection<Patient> searchPatients( List<Integer> patientAttributeIds, List<String> searchTexts, int min, int max);
 
+    Collection<Patient> searchPatients( List<Integer> patientAttributeIds, List<String> searchTexts, OrganisationUnit orgunit, int min, int max);
+
     int countSearchPatientAttributeValue(  PatientAttribute patientAttribute, String searchText );
     
     int countSearchPatients( List<Integer> patientAttributeIds, List<String> searchTexts );
     
+    int countSearchPatients( List<Integer> patientAttributeIds, List<String> searchTexts, OrganisationUnit orgunit );
+    
     void updatePatientAttributeValues( PatientAttributeOption patientAttributeOption);
     
     Collection<PatientAttributeValue> getPatientAttributeValues( Patient patient, Program program );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStore.java	2012-03-27 01:29:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueStore.java	2012-05-24 13:53:25 +0000
@@ -30,6 +30,7 @@
 import java.util.List;
 
 import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeOption;
@@ -70,9 +71,13 @@
 
     Collection<Patient> searchPatients( List<Integer> patientAttributeIds, List<String> searchTexts, int min, int max);
 
+    Collection<Patient> searchPatients( List<Integer> patientAttributeIds, List<String> searchTexts, OrganisationUnit orgunit, int min, int max);
+
     int countSearchPatientAttributeValue(  PatientAttribute patientAttribute, String searchText );
     
     int countSearchPatients( List<Integer> patientAttributeIds, List<String> searchTexts );
+
+    int countSearchPatients( List<Integer> patientAttributeIds, List<String> searchTexts, OrganisationUnit orgunit );
     
     void updatePatientAttributeValues( PatientAttributeOption patientAttributeOption);
 

=== 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	2012-03-27 01:29:30 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java	2012-05-24 13:53:25 +0000
@@ -36,6 +36,7 @@
 import java.util.TreeMap;
 import java.util.Map.Entry;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeOption;
@@ -246,14 +247,28 @@
     {
         patientAttributeValueStore.updatePatientAttributeValues( patientAttributeOption );
     }
-    
+
     public Collection<PatientAttributeValue> getPatientAttributeValues( Patient patient, Program program )
     {
         return patientAttributeValueStore.get( patient, program );
     }
-    
+
     public Collection<PatientAttributeValue> getPatientAttributeValuesWithoutProgram( Patient patient )
     {
         return patientAttributeValueStore.getWithoutProgram( patient );
     }
+
+    @Override
+    public int countSearchPatients( List<Integer> patientAttributeIds, List<String> searchTexts,
+        OrganisationUnit orgunit )
+    {
+        return patientAttributeValueStore.countSearchPatients( patientAttributeIds, searchTexts, orgunit );
+    }
+
+    @Override
+    public Collection<Patient> searchPatients( List<Integer> patientAttributeIds, List<String> searchTexts,
+        OrganisationUnit orgunit, int min, int max )
+    {
+        return patientAttributeValueStore.searchPatients( patientAttributeIds, searchTexts, orgunit, 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	2012-05-03 10:18:41 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2012-05-24 13:53:25 +0000
@@ -33,6 +33,7 @@
 import org.hibernate.criterion.Projections;
 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.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeOption;
@@ -334,4 +335,52 @@
 
     }
 
+    @Override
+    public int countSearchPatients( List<Integer> patientAttributeIds, List<String> searchTexts,
+        OrganisationUnit orgunit )
+    {
+        String hql = "SELECT COUNT( DISTINCT p ) FROM Patient as p WHERE p in ";
+        String end = "";
+
+        int index = 0;
+        for ( Integer patientAttributeId : patientAttributeIds )
+        {
+            end += ")";
+
+            hql += createHQL( patientAttributeId, searchTexts.get( index ), index, patientAttributeIds.size() );
+
+            index++;
+        }
+
+        Query query = getQuery( hql + end + " AND p.organisationUnit.id=" + orgunit.getId() );
+
+        Number rs = (Number) query.uniqueResult();
+
+        return (rs != null) ? rs.intValue() : 0;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Collection<Patient> searchPatients( List<Integer> patientAttributeIds, List<String> searchTexts,
+        OrganisationUnit orgunit, int min, int max )
+    {
+        String hql = "SELECT DISTINCT p FROM Patient as p WHERE p in ";
+        String end = "";
+        
+        int index = 0;
+        for ( Integer patientAttributeId : patientAttributeIds )
+        {
+            end += ")";
+
+            hql += createHQL( patientAttributeId, searchTexts.get( index ), index, patientAttributeIds.size() );
+
+            index++;
+        }
+
+        hql += " ORDER BY p.id ASC";
+
+        Query query = getQuery( hql + end + " AND p.organisationUnit.id=" + orgunit.getId() ).setFirstResult( min ).setMaxResults( max );
+
+        return query.list();
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java	2012-05-24 10:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java	2012-05-24 13:53:25 +0000
@@ -72,6 +72,8 @@
 
     private List<Integer> searchingAttributeId = new ArrayList<Integer>();
 
+    private Boolean searchBySelectedOrgunit;
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -120,6 +122,11 @@
         this.patientAttributeValueService = patientAttributeValueService;
     }
 
+    public void setSearchBySelectedOrgunit( Boolean searchBySelectedOrgunit )
+    {
+        this.searchBySelectedOrgunit = searchBySelectedOrgunit;
+    }
+
     public void setSearchText( List<String> searchText )
     {
         this.searchText = searchText;
@@ -162,7 +169,7 @@
     public String execute()
         throws Exception
     {
-        OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
+        OrganisationUnit selectOrgunit = selectedStateManager.getSelectedOrganisationUnit();
 
         // ---------------------------------------------------------------------
         // Get all of patients into the selected organisation unit
@@ -170,7 +177,7 @@
 
         if ( listAll != null && listAll )
         {
-            listAllPatient( organisationUnit );
+            listAllPatient( selectOrgunit );
 
             return SUCCESS;
         }
@@ -186,11 +193,10 @@
                 patientAttributes.add( patientAttributeService.getPatientAttribute( attributeId ) );
             }
         }
-
-        searchPatientByAttributes( searchingAttributeId, searchText );
+        searchBySelectedOrgunit = (searchBySelectedOrgunit == null) ? false : searchBySelectedOrgunit;
+        searchPatientByAttributes( searchingAttributeId, searchText, selectOrgunit, searchBySelectedOrgunit );
 
         return SUCCESS;
-
     }
 
     // -------------------------------------------------------------------------
@@ -206,21 +212,33 @@
             .getPageSize() ) );
     }
 
-    private void searchPatientByAttributes( List<Integer> searchingAttributeId, List<String> searchText )
+    private void searchPatientByAttributes( List<Integer> searchingAttributeId, List<String> searchText,
+        OrganisationUnit orgunit, Boolean searchBySelectedOrgunit )
     {
-        total = patientAttributeValueService.countSearchPatients( searchingAttributeId, searchText );
-
-        this.paging = createPaging( total );
-
-        patients = patientAttributeValueService.searchPatients( searchingAttributeId, searchText, paging.getStartPos(),
-            paging.getPageSize() );
+        if ( searchBySelectedOrgunit )
+        {
+            total = patientAttributeValueService.countSearchPatients( searchingAttributeId, searchText, orgunit );
+            this.paging = createPaging( total );
+            patients = patientAttributeValueService.searchPatients( searchingAttributeId, searchText, orgunit, paging
+                .getStartPos(), paging.getPageSize() );
+        }
+        else
+        {
+            total = patientAttributeValueService.countSearchPatients( searchingAttributeId, searchText );
+            this.paging = createPaging( total );
+            patients = patientAttributeValueService.searchPatients( searchingAttributeId, searchText, paging
+                .getStartPos(), paging.getPageSize() );
+        }
 
         Collection<PatientAttributeValue> attributeValues = patientAttributeValueService
             .getPatientAttributeValues( patients );
 
         for ( Patient patient : patients )
         {
-            mapPatientOrgunit.put( patient.getId(), getHierarchyOrgunit( patient.getOrganisationUnit() ) );
+            if ( !searchBySelectedOrgunit )
+            {
+                mapPatientOrgunit.put( patient.getId(), getHierarchyOrgunit( patient.getOrganisationUnit() ) );
+            }
 
             for ( PatientAttributeValue attributeValue : attributeValues )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-05-24 05:21:12 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-05-24 13:53:25 +0000
@@ -340,4 +340,5 @@
 delete_favorite=Delete favorite
 are_you_sure=Are you sure?
 loading = Loading
-save_favorite = Save favorite
\ No newline at end of file
+save_favorite = Save favorite
+search_by_selected_unit = Search by selected unit 
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js	2012-05-03 07:59:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js	2012-05-24 13:53:25 +0000
@@ -108,7 +108,8 @@
 		$('#contentDiv').load( 'searchPatient.action', 
 			{
 				searchingAttributeId: getFieldValue('searchingAttributeId'), 
-				searchText: getFieldValue('searchText')
+				searchText: getFieldValue('searchText'),
+				searchBySelectedOrgunit: byId('searchBySelectedOrgunit').checked
 			},
 			function()
 			{

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/listPatient.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/listPatient.vm	2012-04-17 04:39:03 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/listPatient.vm	2012-05-24 13:53:25 +0000
@@ -13,7 +13,7 @@
 	</tr>	
 	
 	<tr>
-		<td class='text-column' >$i18n.getString( "total_result" )</td>
+		<td class='text-column' >$i18n.getString( "total_result" ):</td>
 		<td>&nbsp;</td>
 		<td>&nbsp;</td>
 		<td>$!total</td>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm	2012-05-23 16:19:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm	2012-05-24 13:53:25 +0000
@@ -37,7 +37,13 @@
 					</td>	
 					<td></td>
 					<td><input type="button" value='+' onclick='addAttributeOption();'>
-						<input type="button" value='$i18n.getString( "search" )' onclick='searchAdvancedPatients();'>
+						<td>
+							$i18n.getString('search_by_selected_unit')
+							<input type='checkbox' id='searchBySelectedOrgunit' name='searchBySelectedOrgunit' value='true' />
+						</td>
+						<td>
+							<input type="button" value='$i18n.getString( "search" )' onclick='searchAdvancedPatients();'>
+						</td>
 					</td>
 				</tr>
 			</tbody>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2012-05-24 10:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2012-05-24 13:53:25 +0000
@@ -16,18 +16,6 @@
 
 <div id='searchPatientDiv'>
 	<table id='advancedSearchTB'>	
-		<tr>
-			<td>
-				$i18n.getString('search_in')
-			</td>
-			<td>
-				<select id='facilityLB' name='facilityLB' style="width:20.4em" >
-					<option value='1'>$i18n.getString('all_levels')</option>
-					<option value='2'>$i18n.getString("selected_orgunit")</option>
-					<option value='3'>$i18n.getString("include_level_above")</option>
-				</select>
-			</td>
-		</tr>
 		<tbody>
 			<tr id='advSearchBox0'>	       
 				<td id='searchingAttributeIdTD'>
@@ -46,7 +34,12 @@
 					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 				</td>	
 				<td></td>
-				<td><input type="button" value='+' onclick='addAttributeOption();'>
+				<td><input type="button" value='+' onclick='addAttributeOption();'> </td>
+				<td>
+					$i18n.getString('search_by_selected_unit')
+					<input type='checkbox' id='searchBySelectedOrgunit' name='searchBySelectedOrgunit' value='true' />
+				</td>
+				<td>
 					<input type="button" value='$i18n.getString( "search" )' onclick='searchAdvancedPatients();'>
 				</td>
 				<td>&nbsp;</td>