Search in sources :

Example 6 with AccountRef

use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.

the class HibernateEnrollmentDao method getEnrollmentsForUser.

@Override
public List<EnrollmentDetail> getEnrollmentsForUser(String appId, Set<String> studyIds, String userId) {
    QueryBuilder builder = new QueryBuilder();
    builder.append("FROM HibernateEnrollment WHERE");
    builder.append("appId = :appId AND accountId = :userId", "appId", appId, "userId", userId);
    if (studyIds != null && !studyIds.isEmpty()) {
        builder.append("AND studyId IN :studyIds", "studyIds", studyIds);
    }
    List<HibernateEnrollment> enrollments = hibernateHelper.queryGet(builder.getQuery(), builder.getParameters(), null, null, HibernateEnrollment.class);
    return enrollments.stream().map(enrollment -> {
        AccountRef participantRef = nullSafeAccountRef(appId, enrollment.getAccountId());
        AccountRef enrolledByRef = nullSafeAccountRef(appId, enrollment.getEnrolledBy());
        AccountRef withdrawnByRef = nullSafeAccountRef(appId, enrollment.getWithdrawnBy());
        return new EnrollmentDetail(enrollment, participantRef, enrolledByRef, withdrawnByRef);
    }).collect(toList());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) ImmutableMap(com.google.common.collect.ImmutableMap) Resource(javax.annotation.Resource) Set(java.util.Set) AND(org.sagebionetworks.bridge.models.SearchTermPredicate.AND) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) EnrollmentDao(org.sagebionetworks.bridge.dao.EnrollmentDao) TEST_USER_GROUP(org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef) WhereClauseBuilder(org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder) EnrollmentFilter(org.sagebionetworks.bridge.models.studies.EnrollmentFilter) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef)

Example 7 with AccountRef

use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.

the class HibernateEnrollmentDao method getEnrollmentsForStudy.

@Override
public PagedResourceList<EnrollmentDetail> getEnrollmentsForStudy(String appId, String studyId, EnrollmentFilter filter, boolean includeTesters, Integer offsetBy, Integer pageSize) {
    QueryBuilder builder = new QueryBuilder();
    builder.append("FROM HibernateEnrollment AS h");
    if (!includeTesters) {
        builder.append("INNER JOIN org.sagebionetworks.bridge.hibernate.HibernateAccount AS acct ON acct.id = h.accountId");
    }
    WhereClauseBuilder where = builder.startWhere(AND);
    where.append("h.appId = :appId", "appId", appId);
    where.append("h.studyId = :studyId", "studyId", studyId);
    where.enrollment(filter, false);
    if (!includeTesters) {
        where.dataGroups(ImmutableSet.of(TEST_USER_GROUP), "NOT IN");
    }
    int total = hibernateHelper.queryCount("SELECT COUNT(*) " + builder.getQuery(), builder.getParameters());
    List<HibernateEnrollment> enrollments = hibernateHelper.queryGet("SELECT h " + builder.getQuery(), builder.getParameters(), offsetBy, pageSize, HibernateEnrollment.class);
    List<EnrollmentDetail> dtos = enrollments.stream().map(enrollment -> {
        AccountRef participantRef = nullSafeAccountRef(appId, enrollment.getAccountId());
        AccountRef enrolledByRef = nullSafeAccountRef(appId, enrollment.getEnrolledBy());
        AccountRef withdrawnByRef = nullSafeAccountRef(appId, enrollment.getWithdrawnBy());
        return new EnrollmentDetail(enrollment, participantRef, enrolledByRef, withdrawnByRef);
    }).collect(toList());
    return new PagedResourceList<>(dtos, total, true);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) ImmutableMap(com.google.common.collect.ImmutableMap) Resource(javax.annotation.Resource) Set(java.util.Set) AND(org.sagebionetworks.bridge.models.SearchTermPredicate.AND) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) EnrollmentDao(org.sagebionetworks.bridge.dao.EnrollmentDao) TEST_USER_GROUP(org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef) WhereClauseBuilder(org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder) EnrollmentFilter(org.sagebionetworks.bridge.models.studies.EnrollmentFilter) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef) WhereClauseBuilder(org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList)

Aggregations

AccountRef (org.sagebionetworks.bridge.models.accounts.AccountRef)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Account (org.sagebionetworks.bridge.models.accounts.Account)3 Test (org.testng.annotations.Test)3 Stopwatch (com.google.common.base.Stopwatch)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors.toList (java.util.stream.Collectors.toList)2 Resource (javax.annotation.Resource)2 DateTime (org.joda.time.DateTime)2 TEST_USER_GROUP (org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP)2 EnrollmentDao (org.sagebionetworks.bridge.dao.EnrollmentDao)2 WhereClauseBuilder (org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder)2 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)2 AND (org.sagebionetworks.bridge.models.SearchTermPredicate.AND)2 EventStreamDay (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay)2 StudyAdherenceReport (org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport)2 EnrollmentDetail (org.sagebionetworks.bridge.models.studies.EnrollmentDetail)2