=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SearchPatientAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SearchPatientAction.java 2012-05-09 02:52:11 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SearchPatientAction.java 2012-07-06 13:10:53 +0000 @@ -37,11 +37,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.paging.ActionPagingSupport; import org.hisp.dhis.patient.Patient; -import org.hisp.dhis.patient.PatientAttribute; -import org.hisp.dhis.patient.PatientAttributeService; import org.hisp.dhis.patient.PatientService; -import org.hisp.dhis.patientattributevalue.PatientAttributeValue; -import org.hisp.dhis.patientattributevalue.PatientAttributeValueService; import org.springframework.beans.factory.annotation.Autowired; /** @@ -61,83 +57,64 @@ @Autowired private PatientService patientService; - @Autowired - private PatientAttributeValueService patientAttributeValueService; - - @Autowired - private PatientAttributeService patientAttributeService; - - // ------------------------------------------------------------------------- - // Input - // ------------------------------------------------------------------------- - - private List searchText = new ArrayList(); - - private Boolean listAll; - - private List searchingAttributeId = new ArrayList(); - - // ------------------------------------------------------------------------- - // Output - // ------------------------------------------------------------------------- - - private Integer total; + // ------------------------------------------------------------------------- + // Input/output + // ------------------------------------------------------------------------- + + private List searchTexts = new ArrayList(); + + private Boolean searchBySelectedOrgunit; + + private boolean listAll; private Collection patients = new ArrayList(); - private Map mapPatientPatientAttr = new HashMap(); - - private Map mapPatientOrgunit = new HashMap(); - - private List patientAttributes = new ArrayList(); - - // ------------------------------------------------------------------------- - // Getters/Setters - // ------------------------------------------------------------------------- - - public List getPatientAttributes() - { - return patientAttributes; - } - - public Map getMapPatientOrgunit() - { - return mapPatientOrgunit; - } - - public void setSearchText( List searchText ) - { - this.searchText = searchText; - } - - public void setListAll( Boolean listAll ) + // ------------------------------------------------------------------------- + // Getters && Setters + // ------------------------------------------------------------------------- + + public void setSearchBySelectedOrgunit( Boolean searchBySelectedOrgunit ) + { + this.searchBySelectedOrgunit = searchBySelectedOrgunit; + } + + public void setSelectedStateManager( SelectedStateManager selectedStateManager ) + { + this.selectedStateManager = selectedStateManager; + } + + public void setPatientService( PatientService patientService ) + { + this.patientService = patientService; + } + + public void setSearchTexts( List searchTexts ) + { + this.searchTexts = searchTexts; + } + + public void setListAll( boolean listAll ) { this.listAll = listAll; } - public Boolean getListAll() - { - return listAll; - } - - public void setSearchingAttributeId( List searchingAttributeId ) - { - this.searchingAttributeId = searchingAttributeId; - } - public Collection getPatients() { return patients; } + private Integer total; + public Integer getTotal() { return total; } - public Map getMapPatientPatientAttr() + private Map mapPatientOrgunit = new HashMap(); + + public Map getMapPatientOrgunit() { - return mapPatientPatientAttr; + return mapPatientOrgunit; } // ------------------------------------------------------------------------- @@ -149,70 +126,33 @@ { OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit(); - // --------------------------------------------------------------------- - // Get all of patients into the selected organisation unit - // --------------------------------------------------------------------- - - if ( listAll != null && listAll ) + // List all patients + if ( listAll ) { - listAllPatient( organisationUnit ); - - return SUCCESS; + total = patientService.countGetPatientsByOrgUnit( organisationUnit ); + this.paging = createPaging( total ); + + patients = new ArrayList( patientService.getPatients( organisationUnit, paging.getStartPos(), + paging.getPageSize() ) ); + } - - // --------------------------------------------------------------------- - // Search patients by attributes - // --------------------------------------------------------------------- - - for ( Integer attributeId : searchingAttributeId ) + // search patients + else if ( searchTexts.size() > 0 ) { - if ( attributeId != null && attributeId > 0 ) + organisationUnit = (searchBySelectedOrgunit) ? organisationUnit : null; + + total = patientService.countSearchPatients( searchTexts, organisationUnit ); + this.paging = createPaging( total ); + patients = patientService.searchPatients( searchTexts, organisationUnit, paging.getStartPos(), + paging.getPageSize() ); + + for ( Patient patient : patients ) { - patientAttributes.add( patientAttributeService.getPatientAttribute( attributeId ) ); + mapPatientOrgunit.put( patient.getId(), getHierarchyOrgunit( patient.getOrganisationUnit() ) ); } } - searchPatientByAttributes( searchingAttributeId, searchText ); - return SUCCESS; - - } - - // ------------------------------------------------------------------------- - // Supporting methods - // ------------------------------------------------------------------------- - - private void listAllPatient( OrganisationUnit organisationUnit ) - { - total = patientService.countGetPatientsByOrgUnit( organisationUnit ); - this.paging = createPaging( total ); - - patients = new ArrayList( patientService.getPatients( organisationUnit, paging.getStartPos(), paging - .getPageSize() ) ); - } - - private void searchPatientByAttributes( List searchingAttributeId, List searchText ) - { - 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() ) ); - - for ( PatientAttributeValue attributeValue : attributeValues ) - { - mapPatientPatientAttr.put( patient.getId() + "-" + attributeValue.getPatientAttribute().getId(), - attributeValue.getValue() ); - } - } } private String getHierarchyOrgunit( OrganisationUnit orgunit ) === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/patient.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/patient.js 2012-06-04 08:37:52 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/patient.js 2012-07-06 13:10:53 +0000 @@ -232,10 +232,24 @@ function searchPatient() { + var params = ''; + jQuery( '#advancedSearchTB tbody tr' ).each( function( i, row ){ + jQuery( this ).find(':input').each( function( idx, item ){ + if( idx == 0){ + params += "searchTexts=" + item.value; + } + else if( idx == 1){ + params += "_" + htmlEncode( item.value.toLowerCase() ); + } + }) + }); + params += '&listAll=false'; + params += '&searchBySelectedOrgunit=' + byId('searchBySelectedOrgunit').checked; + $.ajax({ url: 'searchRegistrationPatient.action', type:"POST", - data: getParamsForDiv( 'advancedSearchTB' ), + data: params, success: function( html ){ statusSearching = 1; setInnerHTML( 'listPatientDiv', html );