Search in sources :

Example 31 with Cohort

use of org.pmiops.workbench.db.model.Cohort in project workbench by all-of-us.

the class CohortReviewController method validateRequestAndSetCdrVersion.

private CohortReview validateRequestAndSetCdrVersion(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, WorkspaceAccessLevel level) {
    Cohort cohort = cohortReviewService.findCohort(cohortId);
    // this validates that the user is in the proper workspace
    Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), level);
    CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
    return cohortReviewService.findCohortReview(cohort.getCohortId(), cdrVersionId);
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 32 with Cohort

use of org.pmiops.workbench.db.model.Cohort in project workbench by all-of-us.

the class CohortReviewController method getParticipantCohortStatuses.

/**
 * Get all participants for the specified cohortId and cdrVersionId. This endpoint does pagination
 * based on page, pageSize, sortOrder and sortColumn.
 */
@Override
public ResponseEntity<org.pmiops.workbench.model.CohortReview> getParticipantCohortStatuses(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, PageFilterRequest request) {
    CohortReview cohortReview = null;
    Cohort cohort = cohortReviewService.findCohort(cohortId);
    Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), WorkspaceAccessLevel.READER);
    CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
    try {
        cohortReview = cohortReviewService.findCohortReview(cohortId, cdrVersionId);
    } catch (NotFoundException nfe) {
        cohortReview = initializeCohortReview(cdrVersionId, cohort);
    }
    PageRequest pageRequest = createPageRequest(request);
    List<Filter> filters = request.getFilters() == null ? Collections.<Filter>emptyList() : request.getFilters().getItems();
    List<ParticipantCohortStatus> participantCohortStatuses = cohortReviewService.findAll(cohortReview.getCohortReviewId(), filters, pageRequest);
    org.pmiops.workbench.model.CohortReview responseReview = TO_CLIENT_COHORTREVIEW.apply(cohortReview, pageRequest);
    responseReview.setParticipantCohortStatuses(participantCohortStatuses.stream().map(TO_CLIENT_PARTICIPANT).collect(Collectors.toList()));
    return ResponseEntity.ok(responseReview);
}
Also used : PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Cohort(org.pmiops.workbench.db.model.Cohort) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) org.pmiops.workbench.model(org.pmiops.workbench.model) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 33 with Cohort

use of org.pmiops.workbench.db.model.Cohort in project workbench by all-of-us.

the class CohortMaterializationServiceTest method setUp.

@Before
public void setUp() {
    cdrVersion = new CdrVersion();
    cdrVersion.setBigqueryDataset(testWorkbenchConfig.bigquery.dataSetId);
    cdrVersion.setBigqueryProject(testWorkbenchConfig.bigquery.projectId);
    cdrVersionDao.save(cdrVersion);
    CdrVersionContext.setCdrVersion(cdrVersion);
    Criteria icd9CriteriaGroup = new Criteria().group(true).name("group").selectable(true).code(SearchRequests.ICD9_GROUP_CODE).type(SearchRequests.ICD9_TYPE).parentId(0);
    criteriaDao.save(icd9CriteriaGroup);
    Criteria icd9CriteriaChild = new Criteria().group(false).name("child").selectable(true).code(SearchRequests.ICD9_GROUP_CODE + ".1").type(SearchRequests.ICD9_TYPE).domainId("Condition").parentId(icd9CriteriaGroup.getId());
    criteriaDao.save(icd9CriteriaChild);
    Workspace workspace = new Workspace();
    workspace.setCdrVersion(cdrVersion);
    workspace.setName("name");
    workspace.setDataAccessLevel(DataAccessLevel.PROTECTED);
    workspaceDao.save(workspace);
    Cohort cohort = new Cohort();
    cohort.setWorkspaceId(workspace.getWorkspaceId());
    cohort.setName("males");
    cohort.setType("AOU");
    Gson gson = new Gson();
    cohort.setCriteria(gson.toJson(SearchRequests.males()));
    cohortDao.save(cohort);
    Cohort cohort2 = new Cohort();
    cohort2.setWorkspaceId(workspace.getWorkspaceId());
    cohort2.setName("all genders");
    cohort2.setType("AOU");
    cohort2.setCriteria(gson.toJson(SearchRequests.allGenders()));
    cohortDao.save(cohort2);
    cohortReview = new CohortReview();
    cohortReview.setCdrVersionId(cdrVersion.getCdrVersionId());
    cohortReview.setCohortId(cohort2.getCohortId());
    cohortReview.setMatchedParticipantCount(3);
    cohortReview.setReviewedCount(2);
    cohortReview.setReviewSize(3);
    cohortReviewDao.save(cohortReview);
    participantCohortStatusDao.save(makeStatus(cohortReview.getCohortReviewId(), 1L, CohortStatus.INCLUDED));
    participantCohortStatusDao.save(makeStatus(cohortReview.getCohortReviewId(), 2L, CohortStatus.EXCLUDED));
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) Cohort(org.pmiops.workbench.db.model.Cohort) Gson(com.google.gson.Gson) Criteria(org.pmiops.workbench.cdr.model.Criteria) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace) Before(org.junit.Before)

Aggregations

Cohort (org.pmiops.workbench.db.model.Cohort)33 Workspace (org.pmiops.workbench.db.model.Workspace)23 Test (org.junit.Test)17 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)15 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)10 CohortReview (org.pmiops.workbench.db.model.CohortReview)6 CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)6 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)4 ConflictException (org.pmiops.workbench.exceptions.ConflictException)4 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)4 Before (org.junit.Before)3 org.pmiops.workbench.model (org.pmiops.workbench.model)3 Gson (com.google.gson.Gson)2 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)2 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)2 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)2 EmptyResponse (org.pmiops.workbench.model.EmptyResponse)2 Transactional (org.springframework.transaction.annotation.Transactional)2 QueryResult (com.google.cloud.bigquery.QueryResult)1 Date (java.sql.Date)1