public void setParameter4Search(
      Organization organization,
      LazyDataSupportMapFilter<HumanDto> humanLazyDataModel,
      HumanDto searchData,
      Integer orgType) {
    Map filter = new HashMap<String, String>();
    filter.put(IHumanDtoService.USER_USERNAME, searchData.getUsername());
    filter.put(IHumanDtoService.USER_EMAIL, searchData.getEmailAddress());
    filter.put(IHumanDtoService.USER_FULLNAME, searchData.getFullName());
    filter.put(IHumanDtoService.USER_TEL, searchData.getTel());
    filter.put(
        IHumanDtoService.USER_GENDER,
        searchData.getGender() == null ? null : searchData.getGender().toString());
    filter.put(IHumanDtoService.ORG_TYPE, orgType.toString());
    if (organization != null) {
      filter.put(IHumanDtoService.USER_PARENT_PATH, organization.getPath());
      filter.put(
          IHumanDtoService.USER_ORGNAZATION_ROOT_ID,
          organization.getRootId() == null ? null : organization.getRootId().toString());
      filter.put(
          IHumanDtoService.USER_ORGNAZATION_ID,
          organization.getOrganizationId() == null
              ? null
              : organization.getOrganizationId().toString());
    }

    if (searchData.getBirthday() != null) {
      filter.put(
          IHumanDtoService.USER_BITHDAY,
          DateTimeUtils.convertDateToString(searchData.getBirthday(), DateTimeUtils.ddMMyyyy));
    }

    humanLazyDataModel.setFilters(filter);
  }
  public List<HumanDto> load(
      int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {

    StringBuffer sql =
        new StringBuffer(
            " SELECT DISTINCT s.human_id,s.organization_id,s.org_root_id,s.first_name,s.last_name,s.full_name,s.avatar_url,s.birthday,s.national_id,s.province_id, "
                + "s.district_id,s.street_id,s.address,s.phone,s.tel,s.email_address,s.possition,s.gender,s.cmt,s.cmt_approve_date,s.cmt_issue_plance_id, "
                + "s.yahoo,s.skype, s.status human_status,s.comments,u.*, u.password as retype_password, s.modified_date  "
                + "from human s LEFT JOIN  users u on s.human_id = u.human_id ");

    this.buildQuery(sql, filters);

    if (sortField != null && sortOrder != SortOrder.UNSORTED) {
      sql.append(" order by  s.")
          .append(sortField)
          .append(" ")
          .append(sortOrder == SortOrder.ASCENDING ? "ASC" : "DESC");
    } else {
      sql.append(" order by  s.modified_date desc");
    }

    Query query = em.createNativeQuery(sql.toString(), HumanDto.class);
    String birthday = (String) filters.get(IHumanDtoService.USER_BITHDAY);
    if (birthday != null) {
      query.setParameter(
          1,
          DateTimeUtils.convertStringToDate(birthday, DateTimeUtils.ddMMyyyy),
          TemporalType.DATE);
    }
    query.setFirstResult(first);
    query.setMaxResults(pageSize);
    return query.getResultList();
  }
  public int counter(Map<String, Object> filters) {
    StringBuffer counter =
        new StringBuffer(
            "select count(DISTINCT(s.human_id)) from human s LEFT JOIN  users u on s.human_id = u.human_id  ");

    this.buildQuery(counter, filters);

    Query counterQuery = em.createNativeQuery(counter.toString());
    String birthday = (String) filters.get(IHumanDtoService.USER_BITHDAY);
    if (birthday != null) {
      counterQuery.setParameter(
          1,
          DateTimeUtils.convertStringToDate(birthday, DateTimeUtils.ddMMyyyy),
          TemporalType.DATE);
    }

    return ((java.math.BigDecimal) counterQuery.getSingleResult()).intValue();
  }