Search in sources :

Example 21 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithStringIsNull.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithStringIsNull() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id"));
    ColumnFilter filter = new ColumnFilter();
    filter.setColumnName("ethnicity_source_value");
    filter.setOperator(Operator.EQUAL);
    filter.setValueNull(true);
    tableQuery.addFiltersItem(ImmutableList.of(filter));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
    assertPersonIds(response, 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 22 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDatetimeLessThanOrEqualTo.

@Test
public void testMaterializeCohortObservationFilterObservationDatetimeLessThanOrEqualTo() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("observation");
    tableQuery.setColumns(ImmutableList.of("observation_id"));
    ColumnFilter columnFilter = new ColumnFilter();
    columnFilter.setColumnName("observation_datetime");
    columnFilter.setOperator(Operator.LESS_THAN_OR_EQUAL_TO);
    columnFilter.setValueDate("2009-12-03 05:00:00 UTC");
    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 23 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDateGreaterThanOrEqualTo.

@Test
public void testMaterializeCohortObservationFilterObservationDateGreaterThanOrEqualTo() {
    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_OR_EQUAL_TO);
    columnFilter.setValueDate("2009-12-03");
    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 24 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDatetimeEqual.

@Test
public void testMaterializeCohortObservationFilterObservationDatetimeEqual() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("observation");
    tableQuery.setColumns(ImmutableList.of("observation_id"));
    ColumnFilter columnFilter = new ColumnFilter();
    columnFilter.setColumnName("observation_datetime");
    columnFilter.setValueDate("2009-12-03 05:00:00 UTC");
    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 25 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetYearOfBirthOrPersonIdFilters.

@Test
public void testMaterializeCohortPersonFieldSetYearOfBirthOrPersonIdFilters() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id"));
    ColumnFilter filter1 = new ColumnFilter();
    filter1.setColumnName("year_of_birth");
    filter1.setValueNumber(new BigDecimal(1980));
    ColumnFilter filter2 = new ColumnFilter();
    filter2.setColumnName("person_id");
    filter2.setValueNumber(new BigDecimal(2L));
    tableQuery.addFiltersItem(ImmutableList.of(filter1));
    tableQuery.addFiltersItem(ImmutableList.of(filter2));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
    assertPersonIds(response, 1L, 2L);
    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)

Aggregations

TableQuery (org.pmiops.workbench.model.TableQuery)38 FieldSet (org.pmiops.workbench.model.FieldSet)36 Test (org.junit.Test)35 BigQueryBaseTest (org.pmiops.workbench.api.BigQueryBaseTest)35 MaterializeCohortResponse (org.pmiops.workbench.model.MaterializeCohortResponse)35 ColumnFilter (org.pmiops.workbench.model.ColumnFilter)31 BigDecimal (java.math.BigDecimal)9 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)3 QueryParameterValue (com.google.cloud.bigquery.QueryParameterValue)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ColumnConfig (org.pmiops.workbench.config.CdrBigQuerySchemaConfig.ColumnConfig)2 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1