Search in sources :

Example 26 with ColumnFilter

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDatetimeGreaterThan.

@Test
public void testMaterializeCohortObservationFilterObservationDatetimeGreaterThan() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("observation");
    tableQuery.setColumns(ImmutableList.of("observation_id"));
    ColumnFilter columnFilter = new ColumnFilter();
    columnFilter.setColumnName("observation_datetime");
    columnFilter.setOperator(Operator.GREATER_THAN);
    columnFilter.setValueDate("2009-12-03 04:59:59 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 27 with ColumnFilter

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDateMismatch.

@Test
public void testMaterializeCohortObservationFilterObservationDateMismatch() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("observation");
    tableQuery.setColumns(ImmutableList.of("observation_id"));
    ColumnFilter columnFilter = new ColumnFilter();
    columnFilter.setColumnName("observation_date");
    columnFilter.setValueDate("2009-12-04");
    tableQuery.addFiltersItem(ImmutableList.of(columnFilter));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.males(), makeRequest(fieldSet, 1000));
    assertResults(response);
    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 28 with ColumnFilter

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationFilterObservationDatetimeMismatch.

@Test
public void testMaterializeCohortObservationFilterObservationDatetimeMismatch() {
    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:01 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);
    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 29 with ColumnFilter

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithStringGreaterThanNullNonMatch.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithStringGreaterThanNullNonMatch() {
    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.GREATER_THAN);
    filter.setValue("esf");
    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);
    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 30 with ColumnFilter

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

the class FieldSetQueryBuilder method handleColumnFilters.

private void handleColumnFilters(List<ColumnFilter> columnFilters, TableQueryAndConfig tableQueryAndConfig, StringBuilder sqlBuilder, Map<String, QueryParameterValue> paramMap) {
    if (columnFilters.isEmpty()) {
        throw new BadRequestException("Empty column filter list is invalid");
    }
    sqlBuilder.append("(");
    boolean first = true;
    for (ColumnFilter columnFilter : columnFilters) {
        if (first) {
            first = false;
        } else {
            sqlBuilder.append("\nand\n");
        }
        handleColumnFilter(columnFilter, tableQueryAndConfig, sqlBuilder, paramMap);
    }
    sqlBuilder.append(")");
}
Also used : BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) ColumnFilter(org.pmiops.workbench.model.ColumnFilter)

Aggregations

ColumnFilter (org.pmiops.workbench.model.ColumnFilter)31 TableQuery (org.pmiops.workbench.model.TableQuery)30 Test (org.junit.Test)29 BigQueryBaseTest (org.pmiops.workbench.api.BigQueryBaseTest)29 FieldSet (org.pmiops.workbench.model.FieldSet)29 MaterializeCohortResponse (org.pmiops.workbench.model.MaterializeCohortResponse)29 BigDecimal (java.math.BigDecimal)8 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 QueryParameterValue (com.google.cloud.bigquery.QueryParameterValue)1 HashMap (java.util.HashMap)1 List (java.util.List)1