use of org.pmiops.workbench.model.TableQuery 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();
}
use of org.pmiops.workbench.model.TableQuery 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();
}
use of org.pmiops.workbench.model.TableQuery in project workbench by all-of-us.
the class FieldSetQueryBuilder method extractResults.
public Map<String, Object> extractResults(TableQueryAndConfig tableQueryAndConfig, List<FieldValue> row) {
TableQuery tableQuery = tableQueryAndConfig.getTableQuery();
List<ColumnConfig> columnConfigs = tableQuery.getColumns().stream().map(columnName -> tableQueryAndConfig.getColumn(columnName)).collect(Collectors.toList());
Map<String, Object> results = new HashMap<>(tableQuery.getColumns().size());
for (int i = 0; i < columnConfigs.size(); i++) {
FieldValue fieldValue = row.get(i);
ColumnConfig columnConfig = columnConfigs.get(i);
if (!fieldValue.isNull()) {
Object value;
switch(columnConfig.type) {
case DATE:
value = fieldValue.getStringValue();
break;
case FLOAT:
value = fieldValue.getDoubleValue();
break;
case INTEGER:
value = fieldValue.getLongValue();
break;
case STRING:
value = fieldValue.getStringValue();
break;
case TIMESTAMP:
value = DATE_TIME_FORMAT.print(fieldValue.getTimestampValue() / 1000L);
break;
default:
throw new IllegalStateException("Unrecognized column type: " + columnConfig.type);
}
results.put(columnConfig.name, value);
}
}
return results;
}
use of org.pmiops.workbench.model.TableQuery in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithNumberGreaterThanOrEqualToFilter.
@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithNumberGreaterThanOrEqualToFilter() {
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_OR_EQUAL_TO);
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, 2L, 102246L);
assertThat(response.getNextPageToken()).isNull();
}
use of org.pmiops.workbench.model.TableQuery in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithStringFilterNullNonMatch.
@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithStringFilterNullNonMatch() {
TableQuery tableQuery = new TableQuery();
tableQuery.setTableName("person");
tableQuery.setColumns(ImmutableList.of("person_id"));
ColumnFilter filter = new ColumnFilter();
filter.setColumnName("ethnicity_source_value");
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, 1L, 2L);
assertThat(response.getNextPageToken()).isNull();
}
Aggregations