use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.
the class HibernateEnrollmentDao method getEnrollmentsForUser.
@Override
public List<EnrollmentDetail> getEnrollmentsForUser(String appId, Set<String> studyIds, String userId) {
QueryBuilder builder = new QueryBuilder();
builder.append("FROM HibernateEnrollment WHERE");
builder.append("appId = :appId AND accountId = :userId", "appId", appId, "userId", userId);
if (studyIds != null && !studyIds.isEmpty()) {
builder.append("AND studyId IN :studyIds", "studyIds", studyIds);
}
List<HibernateEnrollment> enrollments = hibernateHelper.queryGet(builder.getQuery(), builder.getParameters(), null, null, HibernateEnrollment.class);
return enrollments.stream().map(enrollment -> {
AccountRef participantRef = nullSafeAccountRef(appId, enrollment.getAccountId());
AccountRef enrolledByRef = nullSafeAccountRef(appId, enrollment.getEnrolledBy());
AccountRef withdrawnByRef = nullSafeAccountRef(appId, enrollment.getWithdrawnBy());
return new EnrollmentDetail(enrollment, participantRef, enrolledByRef, withdrawnByRef);
}).collect(toList());
}
use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.
the class HibernateEnrollmentDao method getEnrollmentsForStudy.
@Override
public PagedResourceList<EnrollmentDetail> getEnrollmentsForStudy(String appId, String studyId, EnrollmentFilter filter, boolean includeTesters, Integer offsetBy, Integer pageSize) {
QueryBuilder builder = new QueryBuilder();
builder.append("FROM HibernateEnrollment AS h");
if (!includeTesters) {
builder.append("INNER JOIN org.sagebionetworks.bridge.hibernate.HibernateAccount AS acct ON acct.id = h.accountId");
}
WhereClauseBuilder where = builder.startWhere(AND);
where.append("h.appId = :appId", "appId", appId);
where.append("h.studyId = :studyId", "studyId", studyId);
where.enrollment(filter, false);
if (!includeTesters) {
where.dataGroups(ImmutableSet.of(TEST_USER_GROUP), "NOT IN");
}
int total = hibernateHelper.queryCount("SELECT COUNT(*) " + builder.getQuery(), builder.getParameters());
List<HibernateEnrollment> enrollments = hibernateHelper.queryGet("SELECT h " + builder.getQuery(), builder.getParameters(), offsetBy, pageSize, HibernateEnrollment.class);
List<EnrollmentDetail> dtos = enrollments.stream().map(enrollment -> {
AccountRef participantRef = nullSafeAccountRef(appId, enrollment.getAccountId());
AccountRef enrolledByRef = nullSafeAccountRef(appId, enrollment.getEnrolledBy());
AccountRef withdrawnByRef = nullSafeAccountRef(appId, enrollment.getWithdrawnBy());
return new EnrollmentDetail(enrollment, participantRef, enrolledByRef, withdrawnByRef);
}).collect(toList());
return new PagedResourceList<>(dtos, total, true);
}
Aggregations