Search in sources :

Example 1 with StudyConsent

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

the class StudyConsentService method deleteAllConsentsPermanently.

/**
 * Physically delete all the consents for a subpopulation.
 */
public void deleteAllConsentsPermanently(SubpopulationGuid subpopulationGuid) {
    checkNotNull(subpopulationGuid);
    // We need to load all consents, so we know their storage paths and can delete their S3 contents.
    List<StudyConsent> consentList = getAllConsents(subpopulationGuid);
    for (StudyConsent consent : consentList) {
        studyConsentDao.deleteConsentPermanently(consent);
        s3Client.deleteObject(consentsBucket, consent.getStoragePath());
    }
    // We need to delete from the publications bucket.
    s3Client.deleteObject(publicationsBucket, subpopulationGuid.getGuid() + CONSENT_HTML_SUFFIX);
    s3Client.deleteObject(publicationsBucket, subpopulationGuid.getGuid() + CONSENT_PDF_SUFFIX);
}
Also used : StudyConsent(org.sagebionetworks.bridge.models.subpopulations.StudyConsent)

Example 2 with StudyConsent

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

the class StudyConsentService method addConsent.

/**
 * Adds a new consent document to the study, and sets that consent document as active.
 *
 * @param subpopGuid
 *            the subpopulation associated with this consent
 * @param form
 *            form filled out by researcher including the path to the consent document and the minimum age required
 *            to consent.
 * @return the added consent document of type StudyConsent along with its document content
 */
public StudyConsentView addConsent(SubpopulationGuid subpopGuid, StudyConsentForm form) {
    checkNotNull(subpopGuid);
    checkNotNull(form);
    String sanitizedContent = sanitizeHTML(form.getDocumentContent());
    Validate.entityThrowingException(validator, new StudyConsentForm(sanitizedContent));
    sanitizedContent = appendSignatureBlockIfNeeded(sanitizedContent);
    long createdOn = DateUtils.getCurrentMillisFromEpoch();
    String storagePath = subpopGuid.getGuid() + "." + createdOn;
    logger.info("Accessing bucket: " + consentsBucket + " with storagePath: " + storagePath);
    try {
        Stopwatch stopwatch = Stopwatch.createStarted();
        s3Helper.writeBytesToS3(consentsBucket, storagePath, sanitizedContent.getBytes(defaultCharset()));
        logger.info("Finished writing consent to bucket " + consentsBucket + " storagePath " + storagePath + " (" + sanitizedContent.length() + " chars) in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
        StudyConsent consent = studyConsentDao.addConsent(subpopGuid, storagePath, createdOn);
        return new StudyConsentView(consent, sanitizedContent);
    } catch (Throwable t) {
        throw new BridgeServiceException(t);
    }
}
Also used : StudyConsent(org.sagebionetworks.bridge.models.subpopulations.StudyConsent) StudyConsentView(org.sagebionetworks.bridge.models.subpopulations.StudyConsentView) Stopwatch(com.google.common.base.Stopwatch) BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) StudyConsentForm(org.sagebionetworks.bridge.models.subpopulations.StudyConsentForm)

Example 3 with StudyConsent

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

the class StudyConsentService method publishConsent.

/**
 * Set the specified consent document as active, setting all other consent documents
 * as inactive.
 *
 * @param app
 *            app for this consent
 * @param subpop
 *            the subpopulation associated with this consent
 * @param timestamp
 *            time the consent document was added to the database.
 * @return the activated consent document along with its document content
 */
public StudyConsentView publishConsent(App app, Subpopulation subpop, long timestamp) {
    checkNotNull(app);
    checkNotNull(subpop);
    checkArgument(timestamp > 0, "Timestamp is 0");
    StudyConsent consent = studyConsentDao.getConsent(subpop.getGuid(), timestamp);
    if (consent == null) {
        throw new EntityNotFoundException(StudyConsent.class);
    }
    // Only if we can publish the document, do we mark it as published in the database.
    String documentContent = loadDocumentContent(consent);
    try {
        publishFormatsToS3(app, subpop.getGuid(), documentContent);
        subpop.setPublishedConsentCreatedOn(timestamp);
        subpopService.updateSubpopulation(app, subpop);
    } catch (IOException | DocumentException | XRRuntimeException e) {
        throw new BridgeServiceException(e.getMessage());
    }
    return new StudyConsentView(consent, documentContent);
}
Also used : StudyConsent(org.sagebionetworks.bridge.models.subpopulations.StudyConsent) XRRuntimeException(org.xhtmlrenderer.util.XRRuntimeException) DocumentException(com.lowagie.text.DocumentException) StudyConsentView(org.sagebionetworks.bridge.models.subpopulations.StudyConsentView) BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) IOException(java.io.IOException)

Example 4 with StudyConsent

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

the class StudyConsentService method getMostRecentConsent.

/**
 * Gets the most recently created consent document for the study.
 *
 * @param subpopGuid
 *            the subpopulation associated with this consent
 * @return the most recent StudyConsent along with its document content
 */
public StudyConsentView getMostRecentConsent(SubpopulationGuid subpopGuid) {
    checkNotNull(subpopGuid);
    StudyConsent consent = studyConsentDao.getMostRecentConsent(subpopGuid);
    if (consent == null) {
        throw new EntityNotFoundException(StudyConsent.class);
    }
    String documentContent = loadDocumentContent(consent);
    return new StudyConsentView(consent, documentContent);
}
Also used : StudyConsent(org.sagebionetworks.bridge.models.subpopulations.StudyConsent) StudyConsentView(org.sagebionetworks.bridge.models.subpopulations.StudyConsentView) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException)

Example 5 with StudyConsent

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

the class SubpopulationService method updateSubpopulation.

/**
 * Update a subpopulation.
 * @param app
 * @param subpop
 * @return
 */
public Subpopulation updateSubpopulation(App app, Subpopulation subpop) {
    checkNotNull(app);
    checkNotNull(subpop);
    subpop.setAppId(app.getIdentifier());
    // Verify this subpopulation is part of the app. Existing code also doesn't submit
    // this publication timestamp back to the server, so set if it doesn't exist.
    Subpopulation existingSubpop = getSubpopulation(app.getIdentifier(), subpop.getGuid());
    if (subpop.getPublishedConsentCreatedOn() == 0L) {
        subpop.setPublishedConsentCreatedOn(existingSubpop.getPublishedConsentCreatedOn());
    }
    // Verify that the publishedConsentCreatedOn field points to a real app consent. Don't use the service
    // because it loads the document from S3.
    StudyConsent consent = studyConsentDao.getConsent(subpop.getGuid(), subpop.getPublishedConsentCreatedOn());
    if (consent == null) {
        throw new EntityNotFoundException(StudyConsent.class);
    }
    Set<String> studyIds = studyService.getStudyIds(app.getIdentifier());
    Validator validator = new SubpopulationValidator(app.getDataGroups(), studyIds);
    Validate.entityThrowingException(validator, subpop);
    Subpopulation updated = subpopDao.updateSubpopulation(subpop);
    cacheProvider.removeObject(CacheKey.subpop(updated.getGuid(), app.getIdentifier()));
    cacheProvider.removeObject(CacheKey.subpopList(app.getIdentifier()));
    return updated;
}
Also used : StudyConsent(org.sagebionetworks.bridge.models.subpopulations.StudyConsent) Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) SubpopulationValidator(org.sagebionetworks.bridge.validators.SubpopulationValidator) Validator(org.springframework.validation.Validator) SubpopulationValidator(org.sagebionetworks.bridge.validators.SubpopulationValidator)

Aggregations

StudyConsent (org.sagebionetworks.bridge.models.subpopulations.StudyConsent)29 Test (org.testng.annotations.Test)22 StudyConsentView (org.sagebionetworks.bridge.models.subpopulations.StudyConsentView)15 StudyConsentForm (org.sagebionetworks.bridge.models.subpopulations.StudyConsentForm)7 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)5 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)4 IOException (java.io.IOException)3 App (org.sagebionetworks.bridge.models.apps.App)3 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 Stopwatch (com.google.common.base.Stopwatch)1 DocumentException (com.lowagie.text.DocumentException)1 DynamoStudyConsent1 (org.sagebionetworks.bridge.dynamodb.DynamoStudyConsent1)1 ResourceList (org.sagebionetworks.bridge.models.ResourceList)1 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)1 SubpopulationValidator (org.sagebionetworks.bridge.validators.SubpopulationValidator)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 Validator (org.springframework.validation.Validator)1