=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2013-12-10 08:18:47 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2013-12-10 08:51:03 +0000 @@ -504,27 +504,11 @@ String id = keys[1]; String value = ""; - Integer orgUnitId = -1; - if ( keys.length >= 3 ) { value = keys[2]; } - if ( keys.length > 4 ) - { - try - { - orgUnitId = Integer.parseInt( keys[4] ); - } - catch ( NumberFormatException e ) - { - // handle as uid - OrganisationUnit ou = organisationUnitService.getOrganisationUnit( keys[4] ); - orgUnitId = ou.getId(); - } - } - if ( keys[0].equals( PREFIX_FIXED_ATTRIBUTE ) ) { patientWhere += patientOperator; @@ -643,7 +627,7 @@ // get events by selected orgunit else if ( !keys[4].equals( "0" ) ) { - patientWhere += " and psi.organisationunitid=" + keys[4]; + patientWhere += " and psi.organisationunitid=" + getOrgUnitId( keys ); } patientWhere += ")"; @@ -665,7 +649,7 @@ // get events by selected orgunit else if ( !keys[4].equals( "0" ) ) { - patientWhere += " and psi.organisationunitid=" + keys[4]; + patientWhere += " and psi.organisationunitid=" + getOrgUnitId( keys ); } patientWhere += ")"; @@ -687,7 +671,7 @@ // get events by selected orgunit else if ( !keys[4].equals( "0" ) ) { - patientWhere += " and p.organisationunitid=" + orgUnitId; + patientWhere += " and p.organisationunitid=" + getOrgUnitId( keys ); } patientWhere += ")"; @@ -709,7 +693,7 @@ // get events by selected orgunit else if ( !keys[4].equals( "0" ) ) { - patientWhere += " and p.organisationunitid=" + orgUnitId; + patientWhere += " and p.organisationunitid=" + getOrgUnitId( keys ); } patientWhere += ")"; @@ -730,7 +714,7 @@ // get events by selected orgunit else if ( !keys[4].equals( "0" ) ) { - patientWhere += " and p.organisationunitid=" + keys[4]; + patientWhere += " and p.organisationunitid=" + getOrgUnitId( keys ); } patientWhere += ")"; operatorStatus = " OR "; @@ -844,6 +828,22 @@ return sql; } + private Integer getOrgUnitId( String[] keys ) + { + Integer orgUnitId; + try + { + orgUnitId = Integer.parseInt( keys[4] ); + } + catch ( NumberFormatException e ) + { + // handle as uid + OrganisationUnit ou = organisationUnitService.getOrganisationUnit( keys[4] ); + orgUnitId = ou.getId(); + } + return orgUnitId; + } + private Collection getOrgunitChildren( Collection orgunits ) { Collection orgUnitIds = new HashSet();