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);
}
}
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));
}
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);
}
}
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());
}
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);
}
Aggregations