Search in sources :

Example 1 with EnrollmentDetail

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

Example 2 with EnrollmentDetail

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);
}
Also used : 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)

Example 3 with EnrollmentDetail

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

Example 4 with EnrollmentDetail

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

Example 5 with EnrollmentDetail

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

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