Search in sources :

Example 36 with Workspace

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

the class CohortsController method getCohortsInWorkspace.

@Override
public ResponseEntity<CohortListResponse> getCohortsInWorkspace(String workspaceNamespace, String workspaceId) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.READER);
    Workspace workspace = workspaceService.getRequiredWithCohorts(workspaceNamespace, workspaceId);
    CohortListResponse response = new CohortListResponse();
    Set<org.pmiops.workbench.db.model.Cohort> cohorts = workspace.getCohorts();
    if (cohorts != null) {
        response.setItems(cohorts.stream().map(TO_CLIENT_COHORT).sorted(Comparator.comparing(c -> c.getName())).collect(Collectors.toList()));
    }
    return ResponseEntity.ok(response);
}
Also used : CohortReview(org.pmiops.workbench.db.model.CohortReview) Provider(javax.inject.Provider) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) Level(java.util.logging.Level) CohortReviewDao(org.pmiops.workbench.db.dao.CohortReviewDao) Strings(com.google.common.base.Strings) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CdrVersionDao(org.pmiops.workbench.db.dao.CdrVersionDao) Gson(com.google.gson.Gson) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) Workspace(org.pmiops.workbench.db.model.Workspace) User(org.pmiops.workbench.db.model.User) CdrVersionContext(org.pmiops.workbench.cdr.CdrVersionContext) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) JsonSyntaxException(com.google.gson.JsonSyntaxException) CohortListResponse(org.pmiops.workbench.model.CohortListResponse) OptimisticLockException(javax.persistence.OptimisticLockException) WorkspaceService(org.pmiops.workbench.db.dao.WorkspaceService) Timestamp(java.sql.Timestamp) CdrVersion(org.pmiops.workbench.db.model.CdrVersion) Set(java.util.Set) Cohort(org.pmiops.workbench.model.Cohort) CohortDao(org.pmiops.workbench.db.dao.CohortDao) ConflictException(org.pmiops.workbench.exceptions.ConflictException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) SearchRequest(org.pmiops.workbench.model.SearchRequest) List(java.util.List) CohortMaterializationService(org.pmiops.workbench.cohorts.CohortMaterializationService) CohortStatus(org.pmiops.workbench.model.CohortStatus) EmptyResponse(org.pmiops.workbench.model.EmptyResponse) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) Clock(java.time.Clock) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) ResponseEntity(org.springframework.http.ResponseEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Cohort(org.pmiops.workbench.model.Cohort) CohortListResponse(org.pmiops.workbench.model.CohortListResponse) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 37 with Workspace

use of org.pmiops.workbench.db.model.Workspace 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)

Example 38 with Workspace

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

the class CohortReviewServiceImpl method validateMatchingWorkspace.

@Override
public Workspace validateMatchingWorkspace(String workspaceNamespace, String workspaceName, long workspaceId, WorkspaceAccessLevel accessRequired) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceName, accessRequired);
    Workspace workspace = workspaceService.getRequired(workspaceNamespace, workspaceName);
    if (workspace.getWorkspaceId() != workspaceId) {
        throw new NotFoundException(String.format("Not Found: No workspace matching workspaceNamespace: %s, workspaceId: %s", workspaceNamespace, workspaceName));
    }
    return workspace;
}
Also used : NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) Workspace(org.pmiops.workbench.db.model.Workspace)

Aggregations

Workspace (org.pmiops.workbench.db.model.Workspace)38 Cohort (org.pmiops.workbench.db.model.Cohort)23 Test (org.junit.Test)21 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)18 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)15 CohortReview (org.pmiops.workbench.db.model.CohortReview)7 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)6 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)5 CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)5 Gson (com.google.gson.Gson)4 Timestamp (java.sql.Timestamp)4 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)4 org.pmiops.workbench.model (org.pmiops.workbench.model)4 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)4 Before (org.junit.Before)3 ConflictException (org.pmiops.workbench.exceptions.ConflictException)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)2 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)2 EmptyResponse (org.pmiops.workbench.model.EmptyResponse)2