private void searchPatientByAttributes(
      List<Integer> searchingAttributeId, List<String> searchText) {
    // total = patientAttributeValueService.countSearchPatients( searchingAttributeId, searchText );

    // OrganisationUnit orgUnit = null;

    organisationUnit = (isSelectedOrg) ? organisationUnit : null;
    total = patientService.countSearchPatients(searchText, organisationUnit);
    // Collection<Patient> getPatients( String searchText, Integer min, Integer max );

    this.paging = createPaging(total);

    // patients = patientAttributeValueService.searchPatients( searchingAttributeId, searchText,
    // paging.getStartPos(),paging.getPageSize() );
    patients =
        patientService.searchPatients(
            searchText, organisationUnit, paging.getStartPos(), paging.getPageSize());

    /*
    if ( isSelectedOrg )
    {
        Iterator<Patient> patientIterator = patients.iterator();
        while ( patientIterator.hasNext() )
        {
            Patient patient = patientIterator.next();

            OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );

            if ( patient.getOrganisationUnit().getId() != orgUnit.getId() )
            {
                patientIterator.remove();
            }
        }
        total = patients.size();
        this.paging = createPaging( total );
    }
    */

    Collection<PatientAttributeValue> attributeValues =
        patientAttributeValueService.getPatientAttributeValues(patients);

    for (Patient patient : patients) {
      // programs.addAll( patient.getPrograms() );

      mapPatientOrgunit.put(patient.getId(), getHierarchyOrgunit(patient.getOrganisationUnit()));

      for (PatientAttributeValue attributeValue : attributeValues) {
        mapPatientPatientAttr.put(
            patient.getId() + "-" + attributeValue.getPatientAttribute().getId(),
            attributeValue.getValue());
      }

      // mapPatientPrograms.put( patient.getId(), getProgramsByPatient( patient ) );
    }
  }
  private void searchPatientByNameAndOrgUnit(
      List<String> searchText, OrganisationUnit organisationUnit) {

    total = patientService.countGetPatientsByOrgUnit(organisationUnit);
    this.paging = createPaging(total);

    // Collection<Patient> tempPatients = new ArrayList<Patient>();
    for (String text : searchText) {
      // tPatients( OrganisationUnit organisationUnit, String searchText, int min, int max )

      List<Patient> tempPatients =
          new ArrayList<Patient>(
              patientService.getPatients(
                  organisationUnit, text, paging.getStartPos(), paging.getPageSize()));
      patients.addAll(tempPatients);
    }

    total = patients.size();
    this.paging = createPaging(total);

    Collection<PatientAttributeValue> attributeValues =
        patientAttributeValueService.getPatientAttributeValues(patients);

    for (Patient patient : patients) {
      // programs.addAll( patient.getPrograms() );

      mapPatientOrgunit.put(patient.getId(), getHierarchyOrgunit(patient.getOrganisationUnit()));

      for (PatientAttributeValue attributeValue : attributeValues) {
        mapPatientPatientAttr.put(
            patient.getId() + "-" + attributeValue.getPatientAttribute().getId(),
            attributeValue.getValue());
      }

      // mapPatientPrograms.put( patient.getId(), getProgramsByPatient( patient ) );
    }
  }