@Override
 public Long countPatientFilteredByCdt(ImogJunction criterion, String cdtId) {
   CriteriaBuilder builder = em.getCriteriaBuilder();
   CriteriaQuery<Long> query = builder.createQuery(Long.class);
   Root<Patient> root = query.from(Patient.class);
   query.select(builder.count(root));
   Path<Object> join = root.join("centres", JoinType.LEFT).get("id");
   query.where(builder.equal(join, cdtId), DaoUtil.<Patient>toPredicate(criterion, builder, root));
   return em.createQuery(query).getSingleResult();
 }
  @Override
  public List<Patient> listPatientFilteredByCdt(
      int first, int max, String property, boolean asc, ImogJunction criterion, String cdtId) {

    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Patient> query = builder.createQuery(clazz);
    Root<Patient> root = query.from(Patient.class);
    query.select(root);
    Path<Object> join = root.join("centres", JoinType.LEFT).get("id");
    query.where(builder.equal(join, cdtId), DaoUtil.<Patient>toPredicate(criterion, builder, root));
    if (property == null) {
      property = "modified";
    }
    Order o =
        asc
            ? builder.asc(DaoUtil.getCascadeRoot(root, property))
            : builder.desc(DaoUtil.getCascadeRoot(root, property));
    query.orderBy(o, builder.desc(root.<String>get("id")));
    return em.createQuery(query).setFirstResult(first).setMaxResults(max).getResultList();
  }