Search in sources :

Example 21 with MaterializeCohortResponse

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDateGreaterThan.

@Test
public void testMaterializeCohortObservationFilterObservationDateGreaterThan() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("observation");
    tableQuery.setColumns(ImmutableList.of("observation_id"));
    ColumnFilter columnFilter = new ColumnFilter();
    columnFilter.setColumnName("observation_date");
    columnFilter.setOperator(Operator.GREATER_THAN);
    columnFilter.setValueDate("2009-12-02");
    tableQuery.addFiltersItem(ImmutableList.of(columnFilter));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.males(), makeRequest(fieldSet, 1000));
    assertResults(response, ImmutableMap.of("observation_id", 5L));
    assertThat(response.getNextPageToken()).isNull();
}
Also used : FieldSet(org.pmiops.workbench.model.FieldSet) TableQuery(org.pmiops.workbench.model.TableQuery) ColumnFilter(org.pmiops.workbench.model.ColumnFilter) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) BigQueryBaseTest(org.pmiops.workbench.api.BigQueryBaseTest) Test(org.junit.Test)

Example 22 with MaterializeCohortResponse

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithStringFilter.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithStringFilter() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id"));
    ColumnFilter filter = new ColumnFilter();
    filter.setColumnName("person_source_value");
    filter.setValue("psv");
    tableQuery.addFiltersItem(ImmutableList.of(filter));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
    assertPersonIds(response, 1L, 2L, 102246L);
    assertThat(response.getNextPageToken()).isNull();
}
Also used : FieldSet(org.pmiops.workbench.model.FieldSet) TableQuery(org.pmiops.workbench.model.TableQuery) ColumnFilter(org.pmiops.workbench.model.ColumnFilter) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) BigQueryBaseTest(org.pmiops.workbench.api.BigQueryBaseTest) Test(org.junit.Test)

Example 23 with MaterializeCohortResponse

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithNumberFilter.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithNumberFilter() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id"));
    ColumnFilter filter = new ColumnFilter();
    filter.setColumnName("person_id");
    filter.setValueNumber(new BigDecimal(1L));
    tableQuery.addFiltersItem(ImmutableList.of(filter));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
    assertPersonIds(response, 1L);
    assertThat(response.getNextPageToken()).isNull();
}
Also used : FieldSet(org.pmiops.workbench.model.FieldSet) TableQuery(org.pmiops.workbench.model.TableQuery) ColumnFilter(org.pmiops.workbench.model.ColumnFilter) BigDecimal(java.math.BigDecimal) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) BigQueryBaseTest(org.pmiops.workbench.api.BigQueryBaseTest) Test(org.junit.Test)

Example 24 with MaterializeCohortResponse

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetAllColumns.

@Test
public void testMaterializeCohortPersonFieldSetAllColumns() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.males(), makeRequest(fieldSet, 1000));
    ImmutableMap<String, Object> p1Map = ImmutableMap.<String, Object>builder().put("person_id", 1L).put("gender_source_value", "1").put("race_source_value", "1").put("gender_concept_id", 8507L).put("year_of_birth", 1980L).put("month_of_birth", 8L).put("day_of_birth", 1L).put("race_concept_id", 1L).put("ethnicity_concept_id", 1L).put("location_id", 1L).put("provider_id", 1L).put("care_site_id", 1L).put("person_source_value", "psv").put("gender_source_concept_id", 1L).put("race_source_concept_id", 1L).put("ethnicity_source_value", "esv").put("ethnicity_source_concept_id", 1L).build();
    assertResults(response, p1Map);
    assertThat(response.getNextPageToken()).isNull();
}
Also used : FieldSet(org.pmiops.workbench.model.FieldSet) TableQuery(org.pmiops.workbench.model.TableQuery) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) BigQueryBaseTest(org.pmiops.workbench.api.BigQueryBaseTest) Test(org.junit.Test)

Example 25 with MaterializeCohortResponse

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

the class CohortsControllerTest method testMaterializeCohortPageSizeZero.

public void testMaterializeCohortPageSizeZero() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    request.setPageSize(0);
    MaterializeCohortRequest adjustedRequest = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    request.setPageSize(CohortsController.DEFAULT_PAGE_SIZE);
    MaterializeCohortResponse response = new MaterializeCohortResponse();
    when(cohortMaterializationService.materializeCohort(null, searchRequest, adjustedRequest)).thenReturn(response);
    assertThat(cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request).getBody()).isEqualTo(response);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse)

Aggregations

MaterializeCohortResponse (org.pmiops.workbench.model.MaterializeCohortResponse)56 Test (org.junit.Test)52 BigQueryBaseTest (org.pmiops.workbench.api.BigQueryBaseTest)48 FieldSet (org.pmiops.workbench.model.FieldSet)36 TableQuery (org.pmiops.workbench.model.TableQuery)35 ColumnFilter (org.pmiops.workbench.model.ColumnFilter)29 MaterializeCohortRequest (org.pmiops.workbench.model.MaterializeCohortRequest)17 BigDecimal (java.math.BigDecimal)8 Cohort (org.pmiops.workbench.model.Cohort)6 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)3 CohortReview (org.pmiops.workbench.db.model.CohortReview)2 CohortStatus (org.pmiops.workbench.model.CohortStatus)2 PaginationToken (org.pmiops.workbench.utils.PaginationToken)2 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 QueryResult (com.google.cloud.bigquery.QueryResult)1 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1