=== 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 getPatient( PatientAttribute attribute, String value ); Collection searchPatients( PatientAttribute patientAttribute, String searchText, int min, int max); - + Collection searchPatients( PatientAttribute patientAttribute, String searchText ); Collection searchPatients( List patientAttributeIds, List searchTexts, int min, int max); + Collection searchPatients( List patientAttributeIds, List searchTexts, OrganisationUnit orgunit, int min, int max); + int countSearchPatientAttributeValue( PatientAttribute patientAttribute, String searchText ); int countSearchPatients( List patientAttributeIds, List searchTexts ); + int countSearchPatients( List patientAttributeIds, List searchTexts, OrganisationUnit orgunit ); + void updatePatientAttributeValues( PatientAttributeOption patientAttributeOption); Collection 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 searchPatients( List patientAttributeIds, List searchTexts, int min, int max); + Collection searchPatients( List patientAttributeIds, List searchTexts, OrganisationUnit orgunit, int min, int max); + int countSearchPatientAttributeValue( PatientAttribute patientAttribute, String searchText ); int countSearchPatients( List patientAttributeIds, List searchTexts ); + + int countSearchPatients( List patientAttributeIds, List 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 getPatientAttributeValues( Patient patient, Program program ) { return patientAttributeValueStore.get( patient, program ); } - + public Collection getPatientAttributeValuesWithoutProgram( Patient patient ) { return patientAttributeValueStore.getWithoutProgram( patient ); } + + @Override + public int countSearchPatients( List patientAttributeIds, List searchTexts, + OrganisationUnit orgunit ) + { + return patientAttributeValueStore.countSearchPatients( patientAttributeIds, searchTexts, orgunit ); + } + + @Override + public Collection searchPatients( List patientAttributeIds, List 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 patientAttributeIds, List 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 searchPatients( List patientAttributeIds, List 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 searchingAttributeId = new ArrayList(); + private Boolean searchBySelectedOrgunit; + // ------------------------------------------------------------------------- // Output // ------------------------------------------------------------------------- @@ -120,6 +122,11 @@ this.patientAttributeValueService = patientAttributeValueService; } + public void setSearchBySelectedOrgunit( Boolean searchBySelectedOrgunit ) + { + this.searchBySelectedOrgunit = searchBySelectedOrgunit; + } + public void setSearchText( List 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 searchingAttributeId, List searchText ) + private void searchPatientByAttributes( List searchingAttributeId, List 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 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 @@ - $i18n.getString( "total_result" ) + $i18n.getString( "total_result" ):     $!total === 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 @@ - + + $i18n.getString('search_by_selected_unit') + + + + + === 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 @@
- - - - - + +
- $i18n.getString('search_in') - - -
@@ -46,7 +34,12 @@         + + $i18n.getString('search_by_selected_unit') + +