Search in sources :

Example 1 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithStringLessThanNullNonMatch.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithStringLessThanNullNonMatch() {
    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.LESS_THAN);
    filter.setValue("esv");
    tableQuery.addFiltersItem(ImmutableList.of(filter));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
    assertPersonIds(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 2 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithNumberGreaterThanFilter.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithNumberGreaterThanFilter() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id"));
    ColumnFilter filter = new ColumnFilter();
    filter.setColumnName("person_id");
    filter.setOperator(Operator.GREATER_THAN);
    filter.setValueNumber(new BigDecimal(2L));
    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) BigDecimal(java.math.BigDecimal) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) BigQueryBaseTest(org.pmiops.workbench.api.BigQueryBaseTest) Test(org.junit.Test)

Example 3 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortObservationPersonNotFound.

@Test
public void testMaterializeCohortObservationPersonNotFound() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("observation");
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.females(), makeRequest(fieldSet, 1000));
    assertResults(response);
    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 4 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetOrderByGenderConceptIdDesc.

@Test
public void testMaterializeCohortPersonFieldSetOrderByGenderConceptIdDesc() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id", "gender_concept_id"));
    tableQuery.setOrderBy(ImmutableList.of("gender_concept_id DESC"));
    FieldSet fieldSet = new FieldSet();
    fieldSet.setTableQuery(tableQuery);
    MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
    ImmutableMap<String, Object> p1Map = ImmutableMap.of("person_id", 1L, "gender_concept_id", 8507L);
    ImmutableMap<String, Object> p2Map = ImmutableMap.of("person_id", 2L, "gender_concept_id", 2L);
    ImmutableMap<String, Object> p3Map = ImmutableMap.of("person_id", 102246L, "gender_concept_id", 8532L);
    assertResults(response, p3Map, p1Map, p2Map);
    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 5 with TableQuery

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

the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithNumberLessThanFilter.

@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithNumberLessThanFilter() {
    TableQuery tableQuery = new TableQuery();
    tableQuery.setTableName("person");
    tableQuery.setColumns(ImmutableList.of("person_id"));
    ColumnFilter filter = new ColumnFilter();
    filter.setColumnName("person_id");
    filter.setOperator(Operator.LESS_THAN);
    filter.setValueNumber(new BigDecimal(2L));
    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)

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