Search in sources :

Example 1 with StudyAssociations

use of org.sagebionetworks.bridge.BridgeUtils.StudyAssociations in project BridgeServer2 by Sage-Bionetworks.

the class HibernateAccountDao method unmarshallAccountSummary.

// Helper method to unmarshall a HibernateAccount into an AccountSummary.
// Package-scoped to facilitate unit tests.
AccountSummary unmarshallAccountSummary(HibernateAccount acct) {
    AccountSummary.Builder builder = new AccountSummary.Builder();
    builder.withAppId(acct.getAppId());
    builder.withId(acct.getId());
    builder.withFirstName(acct.getFirstName());
    builder.withLastName(acct.getLastName());
    builder.withEmail(acct.getEmail());
    builder.withPhone(acct.getPhone());
    builder.withCreatedOn(acct.getCreatedOn());
    builder.withStatus(acct.getStatus());
    builder.withSynapseUserId(acct.getSynapseUserId());
    builder.withAttributes(acct.getAttributes());
    builder.withOrgMembership(acct.getOrgMembership());
    builder.withNote(acct.getNote());
    builder.withClientTimeZone(acct.getClientTimeZone());
    builder.withRoles(acct.getRoles());
    builder.withDataGroups(acct.getDataGroups());
    StudyAssociations assoc = BridgeUtils.studyAssociationsVisibleToCaller(null);
    if (acct.getId() != null) {
        assoc = BridgeUtils.studyAssociationsVisibleToCaller(acct);
    }
    builder.withExternalIds(assoc.getExternalIdsVisibleToCaller());
    builder.withStudyIds(assoc.getStudyIdsVisibleToCaller());
    return builder.build();
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) WhereClauseBuilder(org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder) StudyAssociations(org.sagebionetworks.bridge.BridgeUtils.StudyAssociations)

Example 2 with StudyAssociations

use of org.sagebionetworks.bridge.BridgeUtils.StudyAssociations in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantService method getSelfParticipant.

public StudyParticipant getSelfParticipant(App app, CriteriaContext context, boolean includeHistory) {
    AccountId accountId = AccountId.forId(app.getIdentifier(), context.getUserId());
    // already filters for study
    Account account = getAccountThrowingException(accountId);
    StudyParticipant.Builder builder = new StudyParticipant.Builder();
    StudyAssociations assoc = studyAssociationsVisibleToCaller(account);
    copyAccountToParticipant(builder, assoc, account);
    copyConsentStatusToParticipant(builder, account, context);
    if (includeHistory) {
        copyHistoryToParticipant(builder, account, context.getAppId());
    }
    return builder.build();
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) StudyAssociations(org.sagebionetworks.bridge.BridgeUtils.StudyAssociations) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant)

Example 3 with StudyAssociations

use of org.sagebionetworks.bridge.BridgeUtils.StudyAssociations in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantService method getParticipant.

public StudyParticipant getParticipant(App app, Account account, boolean includeHistory) {
    if (account == null) {
        // This should never happen. However, it occasionally does happen, generally only during integration tests.
        // If a call is taking a long time for whatever reason, the call will timeout and the tests will delete the
        // account. If this happens in the middle of a call (such as give consent or update self participant),
        // we'll suddenly have no account here.
        // 
        // We'll still want to log an error for this so we'll be aware when it happens. At the very least, we'll
        // have this comment and a marginally useful error message instead of a mysterious null pointer exception.
        // 
        // See https://sagebionetworks.jira.com/browse/BRIDGE-1463 for more info.
        LOG.error("getParticipant() called with no account. Was the account deleted in the middle of the call?");
        throw new EntityNotFoundException(Account.class);
    }
    StudyParticipant.Builder builder = new StudyParticipant.Builder();
    StudyAssociations assoc = studyAssociationsVisibleToCaller(account);
    copyAccountToParticipant(builder, assoc, account);
    if (includeHistory) {
        copyHistoryToParticipant(builder, account, app.getIdentifier());
    }
    // Without requestInfo, we cannot reliably determine if the user is consented
    RequestInfo requestInfo = requestInfoService.getRequestInfo(account.getId());
    if (requestInfo != null) {
        CriteriaContext context = new CriteriaContext.Builder().withAppId(app.getIdentifier()).withUserId(account.getId()).withHealthCode(account.getHealthCode()).withUserDataGroups(account.getDataGroups()).withUserStudyIds(assoc.getStudyIdsVisibleToCaller()).withClientInfo(requestInfo.getClientInfo()).withLanguages(requestInfo.getLanguages()).build();
        copyConsentStatusToParticipant(builder, account, context);
    }
    return builder.build();
}
Also used : StudyAssociations(org.sagebionetworks.bridge.BridgeUtils.StudyAssociations) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext)

Aggregations

StudyAssociations (org.sagebionetworks.bridge.BridgeUtils.StudyAssociations)3 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)2 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 WhereClauseBuilder (org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder)1 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)1 RequestInfo (org.sagebionetworks.bridge.models.RequestInfo)1 Account (org.sagebionetworks.bridge.models.accounts.Account)1 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)1 AccountSummary (org.sagebionetworks.bridge.models.accounts.AccountSummary)1