use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class HibernateEnrollmentDaoTest method getEnrollmentsForStudyWithArguments.
@SuppressWarnings("unchecked")
@Test
public void getEnrollmentsForStudyWithArguments() {
HibernateEnrollment en1 = new HibernateEnrollment();
en1.setAccountId("id1");
en1.setEnrolledBy("id2");
en1.setWithdrawnBy("id3");
HibernateEnrollment en2 = new HibernateEnrollment();
List<HibernateEnrollment> page = ImmutableList.of(en1, en2);
when(mockHelper.queryCount(any(), any())).thenReturn(20);
when(mockHelper.queryGet(any(), any(), any(), any(), eq(HibernateEnrollment.class))).thenReturn(page);
HibernateAccount account1 = new HibernateAccount();
account1.setLastName("account1");
HibernateAccount account2 = new HibernateAccount();
account2.setLastName("account2");
HibernateAccount account3 = new HibernateAccount();
account3.setLastName("account3");
when(mockHelper.queryGet(eq(REF_QUERY), any(), isNull(), eq(1), eq(HibernateAccount.class))).thenReturn(ImmutableList.of(account1), ImmutableList.of(account2), ImmutableList.of(account3));
PagedResourceList<EnrollmentDetail> retValue = dao.getEnrollmentsForStudy(TEST_APP_ID, TEST_STUDY_ID, ENROLLED, true, 10, 75);
assertEquals(retValue.getTotal(), Integer.valueOf(20));
assertEquals(retValue.getItems().size(), 2);
EnrollmentDetail detail1 = retValue.getItems().get(0);
assertEquals(detail1.getParticipant().getLastName(), "account1");
assertEquals(detail1.getEnrolledBy().getLastName(), "account2");
assertEquals(detail1.getWithdrawnBy().getLastName(), "account3");
// This one is empty
EnrollmentDetail detail2 = retValue.getItems().get(1);
assertNull(detail2.getParticipant());
assertNull(detail2.getEnrolledBy());
assertNull(detail2.getWithdrawnBy());
verify(mockHelper).queryGet(queryCaptor.capture(), paramsCaptor.capture(), eq(10), eq(75), eq(HibernateEnrollment.class));
assertEquals(queryCaptor.getValue(), "SELECT h FROM HibernateEnrollment AS h WHERE h.appId = " + ":appId AND h.studyId = :studyId AND withdrawnOn IS NULL");
assertEquals(paramsCaptor.getValue().get("appId"), TEST_APP_ID);
assertEquals(paramsCaptor.getValue().get("studyId"), TEST_STUDY_ID);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class HibernateEnrollmentDaoTest method getEnrollmentsForStudyExcludesTestUsers.
@SuppressWarnings("unchecked")
@Test
public void getEnrollmentsForStudyExcludesTestUsers() {
HibernateEnrollment en1 = new HibernateEnrollment();
en1.setAccountId("id1");
en1.setEnrolledBy("id2");
en1.setWithdrawnBy("id3");
HibernateEnrollment en2 = new HibernateEnrollment();
List<HibernateEnrollment> page = ImmutableList.of(en1, en2);
when(mockHelper.queryCount(any(), any())).thenReturn(20);
when(mockHelper.queryGet(any(), any(), any(), any(), eq(HibernateEnrollment.class))).thenReturn(page);
HibernateAccount account1 = new HibernateAccount();
account1.setLastName("account1");
HibernateAccount account2 = new HibernateAccount();
account2.setLastName("account2");
HibernateAccount account3 = new HibernateAccount();
account3.setLastName("account3");
when(mockHelper.queryGet(eq(REF_QUERY), any(), isNull(), eq(1), eq(HibernateAccount.class))).thenReturn(ImmutableList.of(account1), ImmutableList.of(account2), ImmutableList.of(account3));
PagedResourceList<EnrollmentDetail> retValue = dao.getEnrollmentsForStudy(TEST_APP_ID, TEST_STUDY_ID, ENROLLED, false, 10, 75);
assertEquals(retValue.getTotal(), Integer.valueOf(20));
assertEquals(retValue.getItems().size(), 2);
EnrollmentDetail detail1 = retValue.getItems().get(0);
assertEquals(detail1.getParticipant().getLastName(), "account1");
assertEquals(detail1.getEnrolledBy().getLastName(), "account2");
assertEquals(detail1.getWithdrawnBy().getLastName(), "account3");
// This one is empty
EnrollmentDetail detail2 = retValue.getItems().get(1);
assertNull(detail2.getParticipant());
assertNull(detail2.getEnrolledBy());
assertNull(detail2.getWithdrawnBy());
verify(mockHelper).queryGet(queryCaptor.capture(), paramsCaptor.capture(), eq(10), eq(75), eq(HibernateEnrollment.class));
assertEquals(queryCaptor.getValue(), "SELECT h FROM HibernateEnrollment AS h INNER JOIN " + "org.sagebionetworks.bridge.hibernate.HibernateAccount AS acct ON acct.id = " + "h.accountId WHERE h.appId = :appId AND h.studyId = :studyId AND withdrawnOn IS NULL " + "AND (:NOTIN1 NOT IN elements(acct.dataGroups))");
assertEquals(paramsCaptor.getValue().get("appId"), TEST_APP_ID);
assertEquals(paramsCaptor.getValue().get("studyId"), TEST_STUDY_ID);
assertEquals(paramsCaptor.getValue().get("NOTIN1"), TEST_USER_GROUP);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class HibernateEnrollmentDaoTest method getEnrollmentsForUser_noStudies.
@SuppressWarnings("unchecked")
@Test
public void getEnrollmentsForUser_noStudies() {
HibernateEnrollment en1 = new HibernateEnrollment();
en1.setAccountId("id1");
en1.setEnrolledBy("id2");
en1.setWithdrawnBy("id3");
HibernateEnrollment en2 = new HibernateEnrollment();
List<HibernateEnrollment> page = ImmutableList.of(en1, en2);
when(mockHelper.queryGet(any(), any(), isNull(), isNull(), eq(HibernateEnrollment.class))).thenReturn(page);
HibernateAccount account1 = new HibernateAccount();
account1.setLastName("account1");
HibernateAccount account2 = new HibernateAccount();
account2.setLastName("account2");
HibernateAccount account3 = new HibernateAccount();
account3.setLastName("account3");
when(mockHelper.queryGet(eq(REF_QUERY), any(), isNull(), eq(1), eq(HibernateAccount.class))).thenReturn(ImmutableList.of(account1), ImmutableList.of(account2), ImmutableList.of(account3));
List<EnrollmentDetail> retValue = dao.getEnrollmentsForUser(TEST_APP_ID, null, TEST_USER_ID);
EnrollmentDetail detail1 = retValue.get(0);
assertEquals(detail1.getParticipant().getLastName(), "account1");
assertEquals(detail1.getEnrolledBy().getLastName(), "account2");
assertEquals(detail1.getWithdrawnBy().getLastName(), "account3");
verify(mockHelper).queryGet(queryCaptor.capture(), paramsCaptor.capture(), isNull(), isNull(), eq(HibernateEnrollment.class));
assertEquals(queryCaptor.getValue(), "FROM HibernateEnrollment WHERE appId = :appId AND accountId = :userId");
assertEquals(paramsCaptor.getValue().get("appId"), TEST_APP_ID);
assertEquals(paramsCaptor.getValue().get("userId"), TEST_USER_ID);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail 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.studies.EnrollmentDetail 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