Search in sources :

Example 6 with EnrollmentDetail

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);
}
Also used : EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) Test(org.testng.annotations.Test)

Example 7 with EnrollmentDetail

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);
}
Also used : EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) Test(org.testng.annotations.Test)

Example 8 with EnrollmentDetail

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);
}
Also used : EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) Test(org.testng.annotations.Test)

Example 9 with EnrollmentDetail

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 10 with EnrollmentDetail

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

EnrollmentDetail (org.sagebionetworks.bridge.models.studies.EnrollmentDetail)15 Test (org.testng.annotations.Test)11 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)6 Account (org.sagebionetworks.bridge.models.accounts.Account)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors.toList (java.util.stream.Collectors.toList)2 Resource (javax.annotation.Resource)2 TEST_USER_GROUP (org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP)2 EnrollmentDao (org.sagebionetworks.bridge.dao.EnrollmentDao)2 WhereClauseBuilder (org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder)2 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)2 AND (org.sagebionetworks.bridge.models.SearchTermPredicate.AND)2 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)2 AccountRef (org.sagebionetworks.bridge.models.accounts.AccountRef)2 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)2 EnrollmentFilter (org.sagebionetworks.bridge.models.studies.EnrollmentFilter)2 Component (org.springframework.stereotype.Component)2