Search in sources :

Example 96 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentServiceTest method addEnrollment_updatesRequestContext.

@Test
public void addEnrollment_updatesRequestContext() {
    RequestContext.set(new RequestContext.Builder().withCallerUserId("123").withOrgSponsoredStudies(ImmutableSet.of(TEST_STUDY_ID)).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
    Account account = Account.create();
    account.setId(TEST_USER_ID);
    Study study = Study.create();
    study.setPhase(RECRUITMENT);
    when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenReturn(study);
    Enrollment en = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    en.setExternalId("externalId");
    service.addEnrollment(account, en, true);
    assertEquals(account.getEnrollments().size(), 1);
    Enrollment updated = Iterables.getFirst(account.getEnrollments(), null);
    assertEquals(updated.getAccountId(), TEST_USER_ID);
    assertEquals(updated.getAppId(), TEST_APP_ID);
    assertEquals(updated.getEnrolledBy(), "123");
    assertEquals(updated.getEnrolledOn(), CREATED_ON);
    assertEquals(updated.getStudyId(), TEST_STUDY_ID);
    assertEquals(updated.getExternalId(), "externalId");
    assertEquals(RequestContext.get().getCallerEnrolledStudies(), ImmutableSet.of(TEST_STUDY_ID));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Study(org.sagebionetworks.bridge.models.studies.Study) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) RequestContext(org.sagebionetworks.bridge.RequestContext) Test(org.testng.annotations.Test)

Example 97 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentServiceTest method unenroll_byThirdPartyAdmin.

@Test
public void unenroll_byThirdPartyAdmin() {
    RequestContext.set(new RequestContext.Builder().withCallerUserId("adminUser").withCallerRoles(ImmutableSet.of(ADMIN)).build());
    Enrollment existing = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    Account account = Account.create();
    account.setId(TEST_USER_ID);
    account.setEnrollments(Sets.newHashSet(existing));
    TestUtils.mockEditAccount(mockAccountService, account);
    Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    enrollment.setWithdrawnOn(MODIFIED_ON);
    enrollment.setWithdrawalNote("Withdrawal reason");
    Enrollment retValue = service.unenroll(enrollment);
    assertEquals(retValue.getWithdrawnOn(), MODIFIED_ON);
    assertEquals(retValue.getWithdrawnBy(), "adminUser");
    assertEquals(retValue.getWithdrawalNote(), "Withdrawal reason");
    verify(mockAccountService).editAccount(any(), any());
    Enrollment captured = Iterables.getFirst(account.getEnrollments(), null);
    assertEquals(captured.getWithdrawnOn(), MODIFIED_ON);
    assertEquals(captured.getWithdrawnBy(), "adminUser");
    assertEquals(captured.getWithdrawalNote(), "Withdrawal reason");
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 98 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentServiceTest method updateEnrollment_incomingEnrollmentIsValidated.

@Test(expectedExceptions = InvalidEntityException.class)
public void updateEnrollment_incomingEnrollmentIsValidated() {
    Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    enrollment.setAccountId(null);
    service.updateEnrollment(enrollment);
}
Also used : Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 99 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentServiceTest method unenroll_doesNotExists.

@Test(expectedExceptions = EntityNotFoundException.class)
public void unenroll_doesNotExists() {
    RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(ADMIN)).build());
    Account account = Account.create();
    account.setId(TEST_USER_ID);
    TestUtils.mockEditAccount(mockAccountService, account);
    Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    service.unenroll(enrollment);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) RequestContext(org.sagebionetworks.bridge.RequestContext) Test(org.testng.annotations.Test)

Example 100 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method researcherCanAddExternalIdOnCreate.

@Test
public void researcherCanAddExternalIdOnCreate() {
    RequestContext.set(new RequestContext.Builder().withCallerUserId("id").withCallerRoles(ImmutableSet.of(RESEARCHER)).build());
    when(studyService.getStudy(TEST_APP_ID, STUDY_ID, false)).thenReturn(Study.create());
    when(participantService.generateGUID()).thenReturn(ID, HEALTH_CODE);
    StudyParticipant participant = new StudyParticipant.Builder().copyOf(PARTICIPANT).withExternalIds(ENROLLMENT_MAP).build();
    participantService.createParticipant(APP, participant, false);
    verify(accountService).createAccount(eq(APP), accountCaptor.capture());
    verify(enrollmentService).addEnrollment(any(), enrollmentCaptor.capture(), eq(false));
    Enrollment enrollment = enrollmentCaptor.getValue();
    assertEquals(enrollment.getAppId(), TEST_APP_ID);
    assertEquals(enrollment.getStudyId(), STUDY_ID);
    assertEquals(enrollment.getExternalId(), EXTERNAL_ID);
    assertEquals(enrollment.getAccountId(), ID);
}
Also used : Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Aggregations

Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)142 Test (org.testng.annotations.Test)115 Account (org.sagebionetworks.bridge.models.accounts.Account)73 RequestContext (org.sagebionetworks.bridge.RequestContext)30 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)17 AssessmentConfigValidatorTest (org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)15 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)14 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)12 Study (org.sagebionetworks.bridge.models.studies.Study)12 DateTime (org.joda.time.DateTime)11 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)10 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)9 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)6 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)6 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)6 HibernateEnrollment (org.sagebionetworks.bridge.hibernate.HibernateEnrollment)5 AccountSummary (org.sagebionetworks.bridge.models.accounts.AccountSummary)5 App (org.sagebionetworks.bridge.models.apps.App)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4