use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method getEnrollmentsForUser_filteringForStudies.
@Test
public void getEnrollmentsForUser_filteringForStudies() {
Set<String> callerStudies = ImmutableSet.of("studyA", "studyB");
RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(callerStudies).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
AccountId accountId = AccountId.forExternalId(TEST_APP_ID, "extId");
Account account = Account.create();
account.setId(TEST_USER_ID);
when(mockAccountService.getAccount(accountId)).thenReturn(Optional.of(account));
List<EnrollmentDetail> details = ImmutableList.of();
when(mockEnrollmentDao.getEnrollmentsForUser(TEST_APP_ID, callerStudies, TEST_USER_ID)).thenReturn(details);
List<EnrollmentDetail> retValue = service.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, "externalId:extId");
assertSame(retValue, details);
verify(mockEnrollmentDao).getEnrollmentsForUser(TEST_APP_ID, callerStudies, TEST_USER_ID);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantController method getEnrollments.
@GetMapping("/v3/participants/{userId}/enrollments")
public PagedResourceList<EnrollmentDetail> getEnrollments(@PathVariable String userId) {
UserSession session = getAdministrativeSession();
CAN_EDIT_PARTICIPANTS.checkAndThrow(USER_ID, userId);
// A limitation of Swagger as we use it is that we don't want different collection
// containers for the same kind of entity. Since some APIs can page enrollments,
// this API returns a paged enrollment, despite the fact that there will probably
// never be more than one page of results returned from this API.
List<EnrollmentDetail> details = enrollmentService.getEnrollmentsForUser(session.getAppId(), null, userId);
return new PagedResourceList<>(details, details.size(), true);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class HibernateEnrollmentDaoTest method getEnrollmentsForStudy.
@SuppressWarnings("unchecked")
@Test
public void getEnrollmentsForStudy() {
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, null, 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");
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 EnrollmentControllerTest method getEnrollmentsForStudy.
@Test
public void getEnrollmentsForStudy() {
EnrollmentDetail en1 = new EnrollmentDetail(Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, "user1"), null, null, null);
EnrollmentDetail en2 = new EnrollmentDetail(Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, "user2"), null, null, null);
PagedResourceList<EnrollmentDetail> page = new PagedResourceList<>(ImmutableList.of(en1, en2), 10);
when(mockService.getEnrollmentsForStudy(TEST_APP_ID, TEST_STUDY_ID, ENROLLED, true, 5, 40)).thenReturn(page);
PagedResourceList<EnrollmentDetail> retValue = controller.getEnrollmentsForStudy(TEST_STUDY_ID, "5", "40", "enrolled", "true");
assertSame(retValue, page);
verify(mockService).getEnrollmentsForStudy(TEST_APP_ID, TEST_STUDY_ID, ENROLLED, true, 5, 40);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method getEnrollmentsForUser.
@Test
public void getEnrollmentsForUser() {
// We had a bug where the unparsed userId being passed into this method was
// being passed along, rather than the ID from the retrieved account. The
// userId passed in to this method can be one of a number of identifiers...
// the parameter in this case should not be userId, should be something like
// userIdToken as a cue that it needs to be parsed.
AccountId accountId = AccountId.forExternalId(TEST_APP_ID, "extId");
Account account = Account.create();
account.setId(TEST_USER_ID);
when(mockAccountService.getAccount(accountId)).thenReturn(Optional.of(account));
List<EnrollmentDetail> details = ImmutableList.of();
when(mockEnrollmentDao.getEnrollmentsForUser(TEST_APP_ID, null, TEST_USER_ID)).thenReturn(details);
List<EnrollmentDetail> retValue = service.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, "externalId:extId");
assertEquals(retValue, details);
verify(mockEnrollmentDao).getEnrollmentsForUser(TEST_APP_ID, ImmutableSet.of(), TEST_USER_ID);
}
Aggregations