@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;
  }
  @Transactional
  public Sexualorientations getAllEnrollmentSexualorientations(
      UUID enrollmentId, Integer startIndex, Integer maxItems) {
    Sexualorientations sexualorientations = new Sexualorientations();
    List<com.servinglynk.hmis.warehouse.model.v2014.Sexualorientation> entities =
        daoFactory
            .getSexualorientationDao()
            .getAllEnrollmentSexualorientations(enrollmentId, startIndex, maxItems);
    for (com.servinglynk.hmis.warehouse.model.v2014.Sexualorientation entity : entities) {
      sexualorientations.addSexualorientation(SexualorientationConverter.entityToModel(entity));
    }
    long count =
        daoFactory.getSexualorientationDao().getEnrollmentSexualorientationsCount(enrollmentId);
    SortedPagination pagination = new SortedPagination();

    pagination.setFrom(startIndex);
    pagination.setReturned(sexualorientations.getSexualorientations().size());
    pagination.setTotal((int) count);
    sexualorientations.setPagination(pagination);
    return sexualorientations;
  }