Search in sources :

Example 1 with SearchRequest

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

the class CohortsController method materializeCohort.

@Override
public ResponseEntity<MaterializeCohortResponse> materializeCohort(String workspaceNamespace, String workspaceId, MaterializeCohortRequest request) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.READER);
    Workspace workspace = workspaceService.getRequired(workspaceNamespace, workspaceId);
    CdrVersion cdrVersion = workspace.getCdrVersion();
    CdrVersionContext.setCdrVersion(cdrVersion);
    if (request.getCdrVersionName() != null) {
        cdrVersion = cdrVersionDao.findByName(request.getCdrVersionName());
        if (cdrVersion == null) {
            throw new NotFoundException(String.format("Couldn't find CDR version with name %s", request.getCdrVersionName()));
        }
    }
    String cohortSpec;
    CohortReview cohortReview = null;
    if (request.getCohortName() != null) {
        org.pmiops.workbench.db.model.Cohort cohort = cohortDao.findCohortByNameAndWorkspaceId(request.getCohortName(), workspace.getWorkspaceId());
        if (cohort == null) {
            throw new NotFoundException(String.format("Couldn't find cohort with name %s in workspace %s/%s", request.getCohortName(), workspaceNamespace, workspaceId));
        }
        cohortReview = cohortReviewDao.findCohortReviewByCohortIdAndCdrVersionId(cohort.getCohortId(), cdrVersion.getCdrVersionId());
        cohortSpec = cohort.getCriteria();
    } else if (request.getCohortSpec() != null) {
        cohortSpec = request.getCohortSpec();
        if (request.getStatusFilter() != null) {
            throw new BadRequestException("statusFilter cannot be used with cohortSpec");
        }
    } else {
        throw new BadRequestException("Must specify either cohortName or cohortSpec");
    }
    Integer pageSize = request.getPageSize();
    if (pageSize == null || pageSize == 0) {
        request.setPageSize(DEFAULT_PAGE_SIZE);
    } else if (pageSize < 0) {
        throw new BadRequestException(String.format("Invalid page size: %s; must be between 1 and %d", pageSize, MAX_PAGE_SIZE));
    } else if (pageSize > MAX_PAGE_SIZE) {
        request.setPageSize(MAX_PAGE_SIZE);
    }
    SearchRequest searchRequest;
    try {
        searchRequest = new Gson().fromJson(cohortSpec, SearchRequest.class);
    } catch (JsonSyntaxException e) {
        throw new BadRequestException("Invalid cohort spec");
    }
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(cohortReview, searchRequest, request);
    return ResponseEntity.ok(response);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) SearchRequest(org.pmiops.workbench.model.SearchRequest) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) Gson(com.google.gson.Gson) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) JsonSyntaxException(com.google.gson.JsonSyntaxException) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 2 with SearchRequest

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

the class CohortBuilderControllerTest method countSubjectsICD9MeasurementChild.

@Test
public void countSubjectsICD9MeasurementChild() throws Exception {
    SearchParameter icd9 = createSearchParameter(icd9MeasurementChild, "003.1");
    SearchRequest searchRequest = createSearchRequests(icd9MeasurementChild.getType(), Arrays.asList(icd9));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

Example 3 with SearchRequest

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

the class CohortBuilderControllerTest method countSubjectsCPTMeasurement.

@Test
public void countSubjectsCPTMeasurement() throws Exception {
    SearchParameter cpt = createSearchParameter(cptMeasurement, "0001Q");
    SearchRequest searchRequest = createSearchRequests(cptMeasurement.getType(), Arrays.asList(cpt));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

Example 4 with SearchRequest

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

the class CohortBuilderControllerTest method countSubjectsICD9ProcedureOccurrenceParent.

@Test
public void countSubjectsICD9ProcedureOccurrenceParent() throws Exception {
    SearchParameter icd9 = createSearchParameter(icd9ProcedureParent, "002");
    SearchRequest searchRequest = createSearchRequests(icd9ProcedureParent.getType(), Arrays.asList(icd9));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

Example 5 with SearchRequest

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

the class CohortBuilderControllerTest method countSubjectsICD10ConditionOccurrenceParent.

@Test
public void countSubjectsICD10ConditionOccurrenceParent() throws Exception {
    SearchParameter icd10 = createSearchParameter(icd10ConditionParent, "A");
    SearchRequest searchRequest = createSearchRequests(icd10ConditionParent.getType(), Arrays.asList(icd10));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

Aggregations

SearchRequest (org.pmiops.workbench.model.SearchRequest)31 Test (org.junit.Test)27 SearchParameter (org.pmiops.workbench.model.SearchParameter)27 SearchGroup (org.pmiops.workbench.model.SearchGroup)8 SearchGroupItem (org.pmiops.workbench.model.SearchGroupItem)8 Criteria (org.pmiops.workbench.cdr.model.Criteria)6 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)4 LocalDate (java.time.LocalDate)3 Attribute (org.pmiops.workbench.model.Attribute)3 ArrayList (java.util.ArrayList)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 StringJoiner (java.util.StringJoiner)1 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)1 CohortReview (org.pmiops.workbench.db.model.CohortReview)1 Workspace (org.pmiops.workbench.db.model.Workspace)1 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)1 MaterializeCohortResponse (org.pmiops.workbench.model.MaterializeCohortResponse)1