use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentControllerTest method getEnrollmentsForStudyWithDefaults.
@Test
public void getEnrollmentsForStudyWithDefaults() {
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, null, false, 0, 50)).thenReturn(page);
PagedResourceList<EnrollmentDetail> retValue = controller.getEnrollmentsForStudy(TEST_STUDY_ID, null, null, null, null);
assertSame(retValue, page);
verify(mockService).getEnrollmentsForStudy(TEST_APP_ID, TEST_STUDY_ID, null, false, 0, 50);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class StudyParticipantControllerTest method getEnrollmentsForUser.
@Test
public void getEnrollmentsForUser() {
RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(ImmutableSet.of(TEST_STUDY_ID)).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
mockAccountInStudy();
EnrollmentDetail detail = new EnrollmentDetail(null, null, null, null);
List<EnrollmentDetail> list = ImmutableList.of(detail);
when(mockEnrollmentService.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID)).thenReturn(list);
PagedResourceList<EnrollmentDetail> page = controller.getEnrollmentsForUser(TEST_STUDY_ID, TEST_USER_ID);
assertEquals(page.getItems().size(), 1);
verify(mockEnrollmentService).getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class StudyParticipantControllerTest method getActivityEventsForParticipantNotInStudy.
@Test(expectedExceptions = EntityNotFoundException.class, expectedExceptionsMessageRegExp = "Account not found.")
public void getActivityEventsForParticipantNotInStudy() throws Exception {
RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(ImmutableSet.of(TEST_STUDY_ID)).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
doReturn(session).when(controller).getAdministrativeSession();
List<EnrollmentDetail> enrollments = ImmutableList.of(new EnrollmentDetail(Enrollment.create(TEST_APP_ID, "other-study", TEST_USER_ID), null, null, null));
when(mockEnrollmentService.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID)).thenReturn(enrollments);
controller.getRecentActivityEvents(TEST_STUDY_ID, TEST_USER_ID);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class StudyParticipantControllerTest method getParticipantPreventsUnauthorizedHealthCodeRequests.
@Test(expectedExceptions = EntityNotFoundException.class)
public void getParticipantPreventsUnauthorizedHealthCodeRequests() throws Exception {
app.setHealthCodeExportEnabled(false);
Account account = Account.create();
Enrollment en1 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
account.setEnrollments(ImmutableSet.of(en1));
when(mockAccountService.getAccount(any())).thenReturn(Optional.of(account));
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(ImmutableSet.of(TEST_STUDY_ID)).build());
session.setParticipant(new StudyParticipant.Builder().withRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
StudyParticipant participant = new StudyParticipant.Builder().withHealthCode("healthCode").build();
when(mockParticipantService.getParticipant(app, "healthcode:" + TEST_USER_ID, true)).thenReturn(participant);
Enrollment en2 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, "healthcode:" + TEST_USER_ID);
List<EnrollmentDetail> list = ImmutableList.of(new EnrollmentDetail(en2, null, null, null));
when(mockEnrollmentService.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, "healthcode:" + TEST_USER_ID)).thenReturn(list);
controller.getParticipant(TEST_STUDY_ID, "healthcode:" + TEST_USER_ID, true);
}
use of org.sagebionetworks.bridge.models.studies.EnrollmentDetail in project BridgeServer2 by Sage-Bionetworks.
the class StudyParticipantController method getEnrollmentsForUser.
@GetMapping("/v5/studies/{studyId}/participants/{userId}/enrollments")
public PagedResourceList<EnrollmentDetail> getEnrollmentsForUser(@PathVariable String studyId, @PathVariable String userId) {
UserSession session = getAdministrativeSession();
Account account = getValidAccountInStudy(session.getAppId(), studyId, userId);
CAN_EDIT_STUDY_PARTICIPANTS.checkAndThrow(STUDY_ID, studyId);
List<EnrollmentDetail> list = enrollmentService.getEnrollmentsForUser(session.getAppId(), studyId, account.getId());
return new PagedResourceList<>(list, list.size(), true);
}
Aggregations