Search in sources :

Example 1 with ConsentSignature

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

the class ConsentServiceTest method noConsentIfAlreadyConsented.

@Test
public void noConsentIfAlreadyConsented() {
    ConsentSignature sig = new ConsentSignature.Builder().withConsentCreatedOn(CONSENT_CREATED_ON).withSignedOn(DateTime.now().getMillis()).withName("A Name").withBirthdate("1960-10-10").build();
    account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(sig));
    try {
        consentService.consentToResearch(app, SUBPOP_GUID, PARTICIPANT, CONSENT_SIGNATURE, SharingScope.NO_SHARING, false);
        fail("Exception expected.");
    } catch (EntityAlreadyExistsException e) {
        verify(accountService).getAccount(any());
        verifyNoMoreInteractions(accountService);
    }
}
Also used : ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) EntityAlreadyExistsException(org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException) Test(org.testng.annotations.Test)

Example 2 with ConsentSignature

use of org.sagebionetworks.bridge.models.subpopulations.ConsentSignature 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)

Example 3 with ConsentSignature

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

the class ConsentServiceTest method noConsentIfTooYoung.

@Test
public void noConsentIfTooYoung() {
    ConsentSignature consentSignature = new ConsentSignature.Builder().withConsentSignature(CONSENT_SIGNATURE).withBirthdate("2018-05-12").build();
    try {
        consentService.consentToResearch(app, SUBPOP_GUID, PARTICIPANT, consentSignature, SharingScope.NO_SHARING, false);
        fail("Exception expected.");
    } catch (InvalidEntityException e) {
        verifyNoMoreInteractions(accountService);
    }
}
Also used : ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Example 4 with ConsentSignature

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

the class ConsentServiceTest method consentToResearch.

@Test
public void consentToResearch() {
    when(subpopulation.getStudyId()).thenReturn(TEST_STUDY_ID);
    // Account already has a withdrawn consent, to make sure we're correctly appending consents.
    account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(WITHDRAWN_CONSENT_SIGNATURE));
    // Consent signature should have a withdrawOn and a dummy consentCreatedOn just to make sure that we're setting
    // those properly in ConsentService.
    ConsentSignature sig = new ConsentSignature.Builder().withConsentSignature(CONSENT_SIGNATURE).withConsentCreatedOn(CONSENT_CREATED_ON + 20000).withWithdrewOn(12345L).build();
    consentService.consentToResearch(app, SUBPOP_GUID, PARTICIPANT, CONSENT_SIGNATURE, SharingScope.NO_SHARING, true);
    // verify consents were set on account properly
    verify(accountService).updateAccount(accountCaptor.capture());
    Account updatedAccount = accountCaptor.getValue();
    List<ConsentSignature> updatedConsentList = updatedAccount.getConsentSignatureHistory(SUBPOP_GUID);
    assertEquals(updatedConsentList.size(), 2);
    // First consent is the same.
    assertEquals(updatedConsentList.get(0), WITHDRAWN_CONSENT_SIGNATURE);
    // Second consent has consentCreatedOn added and withdrawnOn clear, but is otherwise the same.
    assertEquals(updatedConsentList.get(1).getBirthdate(), sig.getBirthdate());
    assertEquals(updatedConsentList.get(1).getName(), sig.getName());
    assertEquals(updatedConsentList.get(1).getSignedOn(), sig.getSignedOn());
    assertEquals(updatedConsentList.get(1).getConsentCreatedOn(), CONSENT_CREATED_ON);
    assertNull(updatedConsentList.get(1).getWithdrewOn());
    verify(sendMailService).sendEmail(emailCaptor.capture());
    // We notify the app administrator and send a copy to the user.
    BasicEmailProvider provider = emailCaptor.getValue();
    assertEquals(provider.getType(), EmailType.SIGN_CONSENT);
    Set<String> recipients = provider.getRecipientEmails();
    assertEquals(recipients.size(), 2);
    assertTrue(recipients.contains(app.getConsentNotificationEmail()));
    assertTrue(recipients.contains(PARTICIPANT.getEmail()));
    Map<String, String> tokenMap = provider.getTokenMap();
    assertEquals(tokenMap.get("studyName"), "Test App [ConsentServiceTest]");
    assertEquals(tokenMap.get("appName"), "Test App [ConsentServiceTest]");
    assertEquals(tokenMap.get("sponsorName"), "The Council on Test Studies");
    assertEquals(tokenMap.get("appShortName"), "ShortName");
    assertEquals(tokenMap.get("supportEmail"), "bridge-testing+support@sagebase.org");
    assertEquals(tokenMap.get("technicalEmail"), "bridge-testing+technical@sagebase.org");
    assertEquals(tokenMap.get("consentEmail"), "bridge-testing+consent@sagebase.org");
    assertEquals(tokenMap.get("studyShortName"), "ShortName");
    assertEquals(tokenMap.get("appId"), app.getIdentifier());
    assertEquals(tokenMap.get("studyId"), app.getIdentifier());
    assertEquals(tokenMap.get("participantFirstName"), PARTICIPANT.getFirstName());
    assertEquals(tokenMap.get("participantLastName"), PARTICIPANT.getLastName());
    assertEquals(tokenMap.get("participantEmail"), PARTICIPANT.getEmail());
    assertEquals(tokenMap.get("participantPhone"), PARTICIPANT.getPhone().getNumber());
    assertEquals(tokenMap.get("participantPhoneRegion"), PARTICIPANT.getPhone().getRegionCode());
    assertEquals(tokenMap.get("participantPhoneNationalFormat"), PARTICIPANT.getPhone().getNationalFormat());
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) BasicEmailProvider(org.sagebionetworks.bridge.services.email.BasicEmailProvider) ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) Test(org.testng.annotations.Test)

Example 5 with ConsentSignature

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

the class ConsentController method getConsentSignatureV2.

// V2: consent to a specific subpopulation
@GetMapping(path = "/v3/subpopulations/{guid}/consents/signature", produces = { APPLICATION_JSON_UTF8_VALUE })
public String getConsentSignatureV2(@PathVariable String guid) throws Exception {
    UserSession session = getAuthenticatedAndConsentedSession();
    App app = appService.getApp(session.getAppId());
    ConsentSignature sig = consentService.getConsentSignature(app, SubpopulationGuid.create(guid), session.getId());
    return ConsentSignature.SIGNATURE_WRITER.writeValueAsString(sig);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ConsentSignature (org.sagebionetworks.bridge.models.subpopulations.ConsentSignature)75 Test (org.testng.annotations.Test)62 DateTime (org.joda.time.DateTime)7 BasicEmailProvider (org.sagebionetworks.bridge.services.email.BasicEmailProvider)7 Account (org.sagebionetworks.bridge.models.accounts.Account)6 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)6 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)6 InvalidEntityException (org.sagebionetworks.bridge.exceptions.InvalidEntityException)5 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 ConsentStatus (org.sagebionetworks.bridge.models.accounts.ConsentStatus)4 App (org.sagebionetworks.bridge.models.apps.App)4 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)3 HibernateAccountConsent (org.sagebionetworks.bridge.hibernate.HibernateAccountConsent)3 HibernateAccountConsentKey (org.sagebionetworks.bridge.hibernate.HibernateAccountConsentKey)3 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)3 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)3 MimeTypeEmailProvider (org.sagebionetworks.bridge.services.email.MimeTypeEmailProvider)3 Region (com.amazonaws.regions.Region)2