=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/SearchPatientAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/SearchPatientAction.java 2010-10-29 05:33:06 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/SearchPatientAction.java 2010-12-22 07:59:59 +0000 @@ -58,59 +58,76 @@ private OrganisationUnitSelectionManager selectionManager; + private SelectedStateManager selectedStateManager; + + private PatientService patientService; + + private PatientAttributeService patientAttributeService; + + private PatientAttributeValueService patientAttributeValueService; + + private RelationshipService relationshipService; + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String searchText; + + private boolean listAll; + + private Integer searchingAttributeId; + + private Integer sortPatientAttributeId; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private Integer total; + + private Collection patientAttributes; + + private Collection patients = new ArrayList(); + + private Map> mapRelationShip = new HashMap>(); + + private Map mapPatientPatientAttr = new HashMap(); + + // ------------------------------------------------------------------------- + // Getters/Setters + // ------------------------------------------------------------------------- + public void setSelectionManager( OrganisationUnitSelectionManager selectionManager ) { this.selectionManager = selectionManager; } - private SelectedStateManager selectedStateManager; - public void setSelectedStateManager( SelectedStateManager selectedStateManager ) { this.selectedStateManager = selectedStateManager; } - private PatientService patientService; - public void setPatientService( PatientService patientService ) { this.patientService = patientService; } - private PatientAttributeService patientAttributeService; - public void setPatientAttributeService( PatientAttributeService patientAttributeService ) { this.patientAttributeService = patientAttributeService; } - private PatientAttributeValueService patientAttributeValueService; - public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService ) { this.patientAttributeValueService = patientAttributeValueService; } - private RelationshipService relationshipService; - public void setRelationshipService( RelationshipService relationshipService ) { this.relationshipService = relationshipService; } - // ------------------------------------------------------------------------- - // Input/output - // ------------------------------------------------------------------------- - - private OrganisationUnit organisationUnit; - - public OrganisationUnit getOrganisationUnit() - { - return organisationUnit; - } - - private String searchText; - public void setSearchText( String searchText ) { this.searchText = searchText; @@ -121,15 +138,11 @@ return searchText; } - private boolean listAll; - public void setListAll( boolean listAll ) { this.listAll = listAll; } - private Integer searchingAttributeId; - public Integer getSearchingAttributeId() { return searchingAttributeId; @@ -140,36 +153,26 @@ this.searchingAttributeId = searchingAttributeId; } - Collection patientAttributes; - public Collection getPatientAttributes() { return patientAttributes; } - private Collection patients = new ArrayList(); - public Collection getPatients() { return patients; } - private Integer total; - public Integer getTotal() { return total; } - private Map> mapRelationShip = new HashMap>(); - public Map> getMapRelationShip() { return mapRelationShip; } - public Integer sortPatientAttributeId; - public Integer getSortPatientAttributeId() { return sortPatientAttributeId; @@ -180,8 +183,6 @@ this.sortPatientAttributeId = sortPatientAttributeId; } - private Map mapPatientPatientAttr = new HashMap(); - public Map getMapPatientPatientAttr() { return mapPatientPatientAttr; @@ -192,13 +193,6 @@ this.mapPatientPatientAttr = mapPatientPatientAttr; } - PatientAttribute patientAttribute; - - public PatientAttribute getPatientAttribute() - { - return patientAttribute; - } - // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -207,220 +201,143 @@ throws Exception { // --------------------------------------------------------------------- - // Validate selected OrganisationUnit + // Get all of Patient-Attributes // --------------------------------------------------------------------- - if ( sortPatientAttributeId != null ) - { - patientAttribute = patientAttributeService.getPatientAttribute( sortPatientAttributeId ); - } - - organisationUnit = selectionManager.getSelectedOrganisationUnit(); - patientAttributes = patientAttributeService.getAllPatientAttributes(); - if ( listAll ) - { - selectedStateManager.setListAll( listAll ); - + // --------------------------------------------------------------------- + // Get sorting patient-attribute + // --------------------------------------------------------------------- + + PatientAttribute sortingPatientAttribute = null; + if ( sortPatientAttributeId == null ) + { + selectedStateManager.clearSortingAttributeId(); + + } + else + { + sortingPatientAttribute = patientAttributeService.getPatientAttribute( sortPatientAttributeId ); + selectedStateManager.setSortingAttributeId( sortPatientAttributeId ); + } + + // --------------------------------------------------------------------- + // Get and searching patient-attribute + // --------------------------------------------------------------------- + + PatientAttribute searchingPatientAttribute = null; + if ( searchingAttributeId == null ) + { selectedStateManager.clearSearchingAttributeId(); - selectedStateManager.clearSearchTest(); - - total = patientService.countGetPatientsByOrgUnit( organisationUnit ); - - this.paging = createPaging( total ); - patients = new ArrayList( patientService.getPatients( organisationUnit, paging.getStartPos(), - paging.getPageSize() ) ); - - if ( patients != null && patients.size() > 0 ) - { - for ( Patient patient : patients ) - { - mapRelationShip.put( patient.getId(), relationshipService.getRelationshipsForPatient( patient ) ); - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - String value = (attributeValue == null) ? "" : attributeValue.getValue(); - - mapPatientPatientAttr.put( patient, value ); - } - } - } - - searchText = "list_all_patients"; - - return SUCCESS; } - - if ( searchingAttributeId != null && searchText != null ) + else { - selectedStateManager.clearListAll(); - + searchingPatientAttribute = patientAttributeService.getPatientAttribute( searchingAttributeId ); selectedStateManager.setSearchingAttributeId( searchingAttributeId ); - selectedStateManager.setSearchText( searchText ); - - PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( searchingAttributeId ); - - total = patientAttributeValueService.countSearchPatientAttributeValue( patientAttribute, searchText ); - this.paging = createPaging( total ); - - patients = patientAttributeValueService.searchPatients( patientAttribute, searchText, paging.getStartPos(), - paging.getPageSize() ); - - if ( patients != null && patients.size() > 0 ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - patients = patientService.sortPatientsByAttribute( patients, patientAttribute ); - } - - for ( Patient patient : patients ) - { - mapRelationShip.put( patient.getId(), relationshipService.getRelationshipsForPatient( patient ) ); - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - String value = (attributeValue == null) ? "" : attributeValue.getValue(); - - mapPatientPatientAttr.put( patient, value ); - } - } - } - - return SUCCESS; - } - - if ( searchingAttributeId == null && searchText != null ) - { - selectedStateManager.clearListAll(); - selectedStateManager.clearSearchingAttributeId(); - - selectedStateManager.setSearchText( searchText ); - - - total = patientService.countGetPatients( searchText ); - this.paging = createPaging( total ); - patients = patientService.getPatients( searchText, paging.getStartPos(), paging.getPageSize() ); - - if ( patients != null && patients.size() > 0 ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - patients = patientService.sortPatientsByAttribute( patients, patientAttribute ); - } - for ( Patient patient : patients ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - String value = (attributeValue == null) ? "" : attributeValue.getValue(); - - mapPatientPatientAttr.put( patient, value ); - } - } - } - - return SUCCESS; - } - - listAll = selectedStateManager.getListAll(); + } + + // --------------------------------------------------------------------- + // Get all of patient into the selected organisation unit + // --------------------------------------------------------------------- if ( listAll ) { - selectedStateManager.setListAll( listAll ); - - selectedStateManager.clearSearchingAttributeId(); - selectedStateManager.clearSearchTest(); - - total = patientService.countGetPatientsByOrgUnit( organisationUnit ); - this.paging = createPaging( total ); - patients = patientService.getPatients( organisationUnit , paging.getStartPos(), paging.getPageSize() ); - - if ( patients != null && patients.size() > 0 ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - patients = patientService.sortPatientsByAttribute( patients, patientAttribute ); - } - for ( Patient patient : patients ) - { - mapRelationShip.put( patient.getId(), relationshipService.getRelationshipsForPatient( patient ) ); - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - String value = (attributeValue == null) ? "" : attributeValue.getValue(); - - mapPatientPatientAttr.put( patient, value ); - } - } - } - - searchText = "list_all_patients"; - - return SUCCESS; - + searchText = SelectedStateManager.LIST_ALL_PATIENT; + + OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit(); + + listAllPatient( organisationUnit, sortingPatientAttribute ); } - searchingAttributeId = selectedStateManager.getSearchingAttributeId(); - searchText = selectedStateManager.getSearchText(); + // --------------------------------------------------------------------- + // Get patients by searchingAttributeId and searchText + // and sort result by sortingAttributeId + // --------------------------------------------------------------------- - if ( searchingAttributeId != null && searchText != null ) + else if ( searchingPatientAttribute != null && searchText != null ) { - PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( searchingAttributeId ); - - total = patientAttributeValueService.countSearchPatientAttributeValue( patientAttribute, searchText ); - this.paging = createPaging( total ); - patients = patientAttributeValueService.searchPatients( patientAttribute, searchText, paging.getStartPos(), paging.getPageSize() ); - - if ( patients != null && patients.size() > 0 ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - patients = patientService.sortPatientsByAttribute( patients, patientAttribute ); - } - for ( Patient patient : patients ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - String value = (attributeValue == null) ? "" : attributeValue.getValue(); - - mapPatientPatientAttr.put( patient, value ); - } - } - } + searchPatientByAttribute( searchingPatientAttribute, searchText, sortingPatientAttribute ); } + + selectedStateManager.setSearchText( searchText ); - total = patientService.countGetPatients( searchText ); - this.paging = createPaging( total ); - patients =patientService.getPatients( searchText, paging.getStartPos(), paging.getPageSize() ); - - if ( patients != null && patients.size() > 0 ) - { - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - patients = patientService.sortPatientsByAttribute( patients, patientAttribute ); - } - for ( Patient patient : patients ) - { - mapRelationShip.put( patient.getId(), relationshipService.getRelationshipsForPatient( patient ) ); - if ( sortPatientAttributeId != null && patientAttribute != null ) - { - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - String value = (attributeValue == null) ? "" : attributeValue.getValue(); - - mapPatientPatientAttr.put( patient, value ); - } - } - } - return SUCCESS; } + + // ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- + // Support methods + // Support methods + // ------------------------------------------------------------------------- + + private void listAllPatient( OrganisationUnit organisationUnit, PatientAttribute sortingPatientAttribute ) + { + // Get patients by the selected organisation - unit + + total = patientService.countGetPatientsByOrgUnit( organisationUnit ); + + this.paging = createPaging( total ); + + patients = new ArrayList( patientService.getPatients( organisationUnit, paging.getStartPos(), paging + .getPageSize() ) ); + + if ( patients != null && patients.size() > 0 ) + { + for ( Patient patient : patients ) + { + mapRelationShip.put( patient.getId(), relationshipService.getRelationshipsForPatient( patient ) ); + + // Get patient-attribute-values + if ( sortingPatientAttribute != null ) + { + PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( + patient, sortingPatientAttribute ); + String value = (attributeValue == null) ? "" : attributeValue.getValue(); + + mapPatientPatientAttr.put( patient, value ); + } + } + } + } + + private void searchPatientByAttribute( PatientAttribute searchingPatientAttribute, String searchText, + PatientAttribute sortingPatientAttribute ) + { + selectedStateManager.clearListAll(); + + selectedStateManager.setSearchingAttributeId( searchingAttributeId ); + selectedStateManager.setSearchText( searchText ); + + total = patientAttributeValueService.countSearchPatientAttributeValue( searchingPatientAttribute, searchText ); + this.paging = createPaging( total ); + + patients = patientAttributeValueService.searchPatients( searchingPatientAttribute, searchText, paging + .getStartPos(), paging.getPageSize() ); + + if ( patients != null && patients.size() > 0 ) + { + if ( sortingPatientAttribute != null ) + { + patients = patientService.sortPatientsByAttribute( patients, sortingPatientAttribute ); + } + + for ( Patient patient : patients ) + { + mapRelationShip.put( patient.getId(), relationshipService.getRelationshipsForPatient( patient ) ); + if ( sortingPatientAttribute != null ) + { + PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( + patient, sortingPatientAttribute ); + String value = (attributeValue == null) ? "" : attributeValue.getValue(); + + mapPatientPatientAttr.put( patient, value ); + } + } + } + + } + } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ValidateSearchPatientAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ValidateSearchPatientAction.java 2009-09-28 15:11:20 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ValidateSearchPatientAction.java 2010-12-22 07:59:59 +0000 @@ -94,26 +94,13 @@ return INPUT; } - if ( searchText == null ) + if ( searchText == null || searchText.trim().length() == 0 ) { message = i18n.getString( "specify_a_search_criteria" ); return INPUT; } - else - { - searchText = searchText.trim(); - - if ( searchText.length() == 0 ) - { - message = i18n.getString( "specify_a_search_criteria" ); - - return INPUT; - } - - } - // --------------------------------------------------------------------- // Validation success // --------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/state/DefaultSelectedStateManager.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/state/DefaultSelectedStateManager.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/state/DefaultSelectedStateManager.java 2010-12-22 07:59:59 +0000 @@ -48,6 +48,14 @@ implements SelectedStateManager { + public static final String SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID = "selected_searching_attribute_id"; + + public static final String SESSION_KEY_SPECIFIED_SEARCH_TEXT = "specified_search_text"; + + public static final String SESSION_KEY_SELECTED_SORT_ATTRIBUTE_ID = "selected_sort_attribute_id"; + + + public static final String SESSION_KEY_SELECTED_PATIENT_ID = "selected_patient_id"; public static final String SESSION_KEY_SELECTED_PROGRAM_ID = "selected_program_id"; @@ -56,10 +64,6 @@ public static final String SESSION_KEY_LISTALL = "list_all_value"; - public static final String SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID = "selected_searching_attribute_id"; - - public static final String SESSION_KEY_SPECIFIED_SEARCH_TEXT = "specified_search_text"; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -175,16 +179,6 @@ getSession().remove( SESSION_KEY_LISTALL ); } - public void clearSearchTest() - { - getSession().remove( SESSION_KEY_SPECIFIED_SEARCH_TEXT ); - } - - public void clearSearchingAttributeId() - { - getSession().remove( SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID ); - } - public boolean getListAll() { if ( getSession().get( SESSION_KEY_LISTALL ) != null ) @@ -198,34 +192,12 @@ } } - public String getSearchText() - { - return (String) getSession().get( SESSION_KEY_SPECIFIED_SEARCH_TEXT ); - } - - public Integer getSearchingAttributeId() - { - return (Integer) getSession().get( SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID ); - } - @SuppressWarnings( "unchecked" ) public void setListAll( boolean listAll ) { getSession().put( SESSION_KEY_LISTALL, listAll ); } - @SuppressWarnings( "unchecked" ) - public void setSearchText( String searchText ) - { - getSession().put( SESSION_KEY_SPECIFIED_SEARCH_TEXT, searchText ); - } - - @SuppressWarnings( "unchecked" ) - public void setSearchingAttributeId( int searchingAttributeId ) - { - getSession().put( SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID, searchingAttributeId ); - } - // ------------------------------------------------------------------------- // Support methods // ------------------------------------------------------------------------- @@ -236,4 +208,59 @@ return ActionContext.getContext().getSession(); } + // ------------------------------------------------------------------------- + // Search patients by patient-attribute + // ------------------------------------------------------------------------- + + @SuppressWarnings( "unchecked" ) + public void setSearchingAttributeId( int searchingAttributeId ) + { + getSession().put( SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID, searchingAttributeId ); + } + + public Integer getSearchingAttributeId() + { + return (Integer) getSession().get( SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID ); + } + + public void clearSearchingAttributeId() + { + getSession().remove( SESSION_KEY_SELECTED_SEARCHING_ATTRIBUTE_ID ); + } + + @SuppressWarnings( "unchecked" ) + public void setSearchText( String searchText ) + { + getSession().put( SESSION_KEY_SPECIFIED_SEARCH_TEXT, searchText ); + } + + public String getSearchText() + { + return (String) getSession().get( SESSION_KEY_SPECIFIED_SEARCH_TEXT ); + } + + public void clearSearchText() + { + getSession().remove( SESSION_KEY_SPECIFIED_SEARCH_TEXT ); + } + + // ------------------------------------------------------------------------- + // Sort by patient-attribute + // ------------------------------------------------------------------------- + + @SuppressWarnings( "unchecked" ) + public void setSortingAttributeId( int sortAttributeId ) + { + getSession().put( SESSION_KEY_SELECTED_SORT_ATTRIBUTE_ID, sortAttributeId ); + } + + public Integer getSortAttributeId() + { + return (Integer) getSession().get( SESSION_KEY_SELECTED_SORT_ATTRIBUTE_ID ); + } + + public void clearSortingAttributeId() + { + getSession().remove( SESSION_KEY_SELECTED_SORT_ATTRIBUTE_ID ); + } } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/state/SelectedStateManager.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/state/SelectedStateManager.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/state/SelectedStateManager.java 2010-12-22 07:59:59 +0000 @@ -38,41 +38,61 @@ */ public interface SelectedStateManager { - OrganisationUnit getSelectedOrganisationUnit(); + public static String LIST_ALL_PATIENT = "All"; + OrganisationUnit getSelectedOrganisationUnit(); + void setSelectedPatient( Patient patient ); Patient getSelectedPatient(); void clearSelectedPatient(); - + void setSelectedProgram( Program program ); Program getSelectedProgram(); void clearSelectedProgram(); - - void setSelectedProgramStage( ProgramStage programStage ); - - ProgramStage getSelectedProgramStage(); + + void setSelectedProgramStage( ProgramStage programStage ); + + ProgramStage getSelectedProgramStage(); void clearSelectedProgramStage(); - + void setListAll( boolean listAll ); - + boolean getListAll(); - + void clearListAll(); + + + // ------------------------------------------------------------------------- + // Search patients by patient-attribute + // ------------------------------------------------------------------------- + void setSearchingAttributeId( int searchingAttributeId ); - + Integer getSearchingAttributeId(); - + void clearSearchingAttributeId(); + void setSearchText( String searchText ); - + String getSearchText(); - - void clearSearchTest(); + + void clearSearchText(); + + // ------------------------------------------------------------------------- + // Sort by patient-attribute + // ------------------------------------------------------------------------- + + void setSortingAttributeId( int sortAttributeId ); + + Integer getSortAttributeId(); + + void clearSortingAttributeId(); + } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patient.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patient.vm 2010-12-10 04:02:52 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patient.vm 2010-12-22 07:59:59 +0000 @@ -6,18 +6,7 @@   - - - - $i18n.getString( "sort_by" ) - - - + @@ -31,17 +20,30 @@ * - +   + + + + + + + +