@Override
  @Transactional
  public Enrollments getEnrollmentsByClientId(
      UUID clientId, String loginUser, Integer startIndex, Integer maxItems) {

    HmisUser hmisUser = daoFactory.getAccountDao().findByUsername(loginUser);
    if (hmisUser == null) throw new AccountNotFoundException();

    List<com.servinglynk.hmis.warehouse.model.v2014.Enrollment> pEnrollments =
        daoFactory.getEnrollmentDao().getEnrollmentsByClientId(clientId, startIndex, maxItems);
    List<com.servinglynk.hmis.warehouse.model.v2014.Enrollment> sharingEnrollments =
        daoFactory
            .getSharingRuleDao()
            .getSharedEnrollments(hmisUser.getId(), hmisUser.getOrganization().getId());
    if (sharingEnrollments.size() > 0) {
      pEnrollments.addAll(sharingEnrollments);
    }

    Enrollments enrollments = new Enrollments();

    for (com.servinglynk.hmis.warehouse.model.v2014.Enrollment pEnrollment : pEnrollments) {
      enrollments.addEnrollment(EnrollmentConveter.entityToModel(pEnrollment));
    }

    long count = daoFactory.getEnrollmentDao().getEnrollmentCount(clientId);
    SortedPagination pagination = new SortedPagination();

    pagination.setFrom(startIndex);
    pagination.setReturned(enrollments.getEnrollments().size());
    pagination.setTotal((int) count);
    enrollments.setPagination(pagination);

    return enrollments;
  }
  @Override
  @Transactional
  public com.servinglynk.hmis.warehouse.core.model.Enrollment
      getEnrollmentByClientIdAndEnrollmentId(UUID enrollmentId, UUID clientId) {
    com.servinglynk.hmis.warehouse.model.v2014.Enrollment pEnrollment =
        daoFactory
            .getEnrollmentDao()
            .getEnrollmentByClientIdAndEnrollmentId(enrollmentId, clientId);
    if (pEnrollment == null) throw new EnrollmentNotFound();

    return EnrollmentConveter.entityToModel(pEnrollment);
  }