Search in sources :

Example 1 with Subpopulation

use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.

the class CacheProviderStudyMigrationTest method subpopulationWithStudyIdentifier.

@Test
public void subpopulationWithStudyIdentifier() throws Exception {
    String json = TestUtils.createJson("{'studyIdentifier':'" + TEST_APP_ID + "','type':'Subpopulation'}");
    CacheKey key = CacheKey.subpop(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID);
    when(mockJedisOps.get(key.toString())).thenReturn(json);
    Subpopulation subpop = provider.getObject(key, Subpopulation.class);
    assertEquals(subpop.getAppId(), TEST_APP_ID);
}
Also used : Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) Test(org.testng.annotations.Test)

Example 2 with Subpopulation

use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.

the class CacheProviderStudyMigrationTest method subpopulationWithAppId.

@Test
public void subpopulationWithAppId() throws Exception {
    String json = TestUtils.createJson("{'appId':'" + TEST_APP_ID + "','type':'Subpopulation'}");
    CacheKey key = CacheKey.subpop(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID);
    when(mockJedisOps.get(key.toString())).thenReturn(json);
    Subpopulation subpop = provider.getObject(key, Subpopulation.class);
    assertEquals(subpop.getAppId(), TEST_APP_ID);
}
Also used : Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) Test(org.testng.annotations.Test)

Example 3 with Subpopulation

use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.

the class IntentServiceTest method registerIntentToParticipateWithMultipleConsents.

@Test
public void registerIntentToParticipateWithMultipleConsents() {
    Subpopulation subpopA = Subpopulation.create();
    subpopA.setGuidString("AAA");
    Subpopulation subpopB = Subpopulation.create();
    subpopB.setGuidString("BBB");
    IntentToParticipate intentAAA = new IntentToParticipate.Builder().withOsName("Android").withPhone(TestConstants.PHONE).withScope(SharingScope.NO_SHARING).withAppId(TEST_APP_ID).withSubpopGuid("AAA").withConsentSignature(new ConsentSignature.Builder().withName("Test Name").withBirthdate("1975-01-01").build()).build();
    IntentToParticipate intentBBB = new IntentToParticipate.Builder().withOsName("Android").withPhone(TestConstants.PHONE).withScope(SharingScope.NO_SHARING).withAppId(TEST_APP_ID).withSubpopGuid("BBB").withConsentSignature(new ConsentSignature.Builder().withName("Test Name").withBirthdate("1975-01-01").build()).build();
    Account account = Account.create();
    account.setId("id");
    account.setPhone(TestConstants.PHONE);
    StudyParticipant participant = new StudyParticipant.Builder().build();
    CacheKey keyAAA = CacheKey.itp(SubpopulationGuid.create("AAA"), TEST_APP_ID, TestConstants.PHONE);
    CacheKey keyBBB = CacheKey.itp(SubpopulationGuid.create("BBB"), TEST_APP_ID, TestConstants.PHONE);
    when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
    when(mockSubpopService.getSubpopulations(TEST_APP_ID, false)).thenReturn(Lists.newArrayList(subpopA, subpopB));
    when(mockCacheProvider.getObject(keyAAA, IntentToParticipate.class)).thenReturn(intentAAA);
    when(mockCacheProvider.getObject(keyBBB, IntentToParticipate.class)).thenReturn(intentBBB);
    when(mockParticipantService.getParticipant(mockApp, "id", true)).thenReturn(participant);
    service.registerIntentToParticipate(mockApp, account);
    verify(mockSubpopService).getSubpopulations(TEST_APP_ID, false);
    verify(mockCacheProvider).removeObject(keyAAA);
    verify(mockCacheProvider).removeObject(keyBBB);
    verify(mockConsentService).consentToResearch(eq(mockApp), eq(SubpopulationGuid.create("AAA")), any(), eq(intentAAA.getConsentSignature()), eq(intentAAA.getScope()), eq(true));
    verify(mockConsentService).consentToResearch(eq(mockApp), eq(SubpopulationGuid.create("BBB")), any(), eq(intentBBB.getConsentSignature()), eq(intentBBB.getScope()), eq(true));
    // Only loaded the participant once...
    verify(mockParticipantService, times(1)).getParticipant(mockApp, "id", true);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Example 4 with Subpopulation

use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.

the class IntentServiceTest method noIntentDoesNothing.

@Test
public void noIntentDoesNothing() {
    Subpopulation subpopA = Subpopulation.create();
    subpopA.setGuidString("AAA");
    Subpopulation subpopB = Subpopulation.create();
    subpopB.setGuidString("BBB");
    Account account = Account.create();
    account.setPhone(TestConstants.PHONE);
    CacheKey key = CacheKey.itp(SubpopulationGuid.create("BBB"), TEST_APP_ID, PHONE);
    when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
    when(mockSubpopService.getSubpopulations(TEST_APP_ID, false)).thenReturn(Lists.newArrayList(subpopA, subpopB));
    service.registerIntentToParticipate(mockApp, account);
    verify(mockSubpopService).getSubpopulations(TEST_APP_ID, false);
    verify(mockCacheProvider, never()).removeObject(key);
    verifyNoMoreInteractions(mockConsentService);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Example 5 with Subpopulation

use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.

the class ConsentServiceTest method setupWithdrawTest.

private void setupWithdrawTest(boolean subpop1Required, boolean subpop2Required) {
    // two consents, withdrawing one does not turn sharing entirely off.
    account.setSharingScope(SharingScope.ALL_QUALIFIED_RESEARCHERS);
    account.setHealthCode(PARTICIPANT.getHealthCode());
    Subpopulation subpop1 = Subpopulation.create();
    subpop1.setName(SUBPOP_GUID.getGuid());
    subpop1.setGuid(SUBPOP_GUID);
    subpop1.setRequired(subpop1Required);
    Subpopulation subpop2 = Subpopulation.create();
    subpop2.setName(SECOND_SUBPOP.getGuid());
    subpop2.setGuid(SECOND_SUBPOP);
    subpop2.setRequired(subpop2Required);
    doReturn(ImmutableList.of(subpop1, subpop2)).when(subpopService).getSubpopulationsForUser(any());
    ConsentSignature secondConsentSignature = new ConsentSignature.Builder().withName("Test User").withBirthdate("1990-01-01").withSignedOn(SIGNED_ON).build();
    account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(CONSENT_SIGNATURE));
    account.setConsentSignatureHistory(SECOND_SUBPOP, ImmutableList.of(secondConsentSignature));
}
Also used : ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation)

Aggregations

Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)105 Test (org.testng.annotations.Test)76 Criteria (org.sagebionetworks.bridge.models.Criteria)20 DynamoSubpopulation (org.sagebionetworks.bridge.dynamodb.DynamoSubpopulation)16 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)12 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)9 App (org.sagebionetworks.bridge.models.apps.App)9 ConsentSignature (org.sagebionetworks.bridge.models.subpopulations.ConsentSignature)9 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)7 Account (org.sagebionetworks.bridge.models.accounts.Account)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)6 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)6 StudyConsentView (org.sagebionetworks.bridge.models.subpopulations.StudyConsentView)6 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)5 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 StudyConsent (org.sagebionetworks.bridge.models.subpopulations.StudyConsent)5 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)4 ConsentStatus (org.sagebionetworks.bridge.models.accounts.ConsentStatus)4 IntentToParticipate (org.sagebionetworks.bridge.models.itp.IntentToParticipate)4