Search in sources :

Example 16 with SearchParameter

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

the class CodesQueryBuilderTest method getMappedParameters.

@Test
public void getMappedParameters() throws Exception {
    final SearchParameter searchParam1 = new SearchParameter().group(false).domain("Condition").value("001");
    final SearchParameter searchParam2 = new SearchParameter().group(false).domain("Procedure").value("002");
    final SearchParameter searchParam3 = new SearchParameter().group(false).domain("Procedure").value("003");
    final SearchParameter searchParam4 = new SearchParameter().group(true).domain("Procedure").value("0");
    SearchGroupItem item = new SearchGroupItem().type("ICD9").searchParameters(Arrays.asList(searchParam1, searchParam2, searchParam3, searchParam4));
    Map<CodesQueryBuilder.GroupType, ListMultimap<String, SearchParameter>> mappedParemeters = queryBuilder.getMappedParameters(item.getSearchParameters());
    assertEquals(2, mappedParemeters.keySet().size());
    assertEquals(new HashSet<CodesQueryBuilder.GroupType>(Arrays.asList(CodesQueryBuilder.GroupType.GROUP, CodesQueryBuilder.GroupType.NOT_GROUP)), mappedParemeters.keySet());
    assertEquals(Arrays.asList(searchParam1), mappedParemeters.get(CodesQueryBuilder.GroupType.NOT_GROUP).get("Condition"));
    assertEquals(Arrays.asList(searchParam2, searchParam3), mappedParemeters.get(CodesQueryBuilder.GroupType.NOT_GROUP).get("Procedure"));
    assertEquals(Arrays.asList(searchParam4), mappedParemeters.get(CodesQueryBuilder.GroupType.GROUP).get("Procedure"));
}
Also used : SearchParameter(org.pmiops.workbench.model.SearchParameter) ListMultimap(com.google.common.collect.ListMultimap) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem) Test(org.junit.Test)

Example 17 with SearchParameter

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

the class CodesQueryBuilderTest method buildQueryJobConfigICD9Group.

@Test
public void buildQueryJobConfigICD9Group() throws Exception {
    String procedureNamedParameter = "";
    String cmProcedureParameter = "";
    String procProcedureParameter = "";
    String conditionNamedParameter = "";
    String cmConditionParameter = "";
    String procConditionParameter = "";
    String measurementNamedParameter = "";
    String cmMeasurementParameter = "";
    String procMeasurementParameter = "";
    List<SearchParameter> params = new ArrayList<>();
    params.add(new SearchParameter().group(false).type("ICD9").domain("Condition").value("10.1"));
    params.add(new SearchParameter().group(false).type("ICD9").domain("Condition").value("20.2"));
    params.add(new SearchParameter().group(true).type("ICD9").domain("Measurement").value("0"));
    params.add(new SearchParameter().group(true).type("ICD9").domain("Procedure").value("1"));
    /* Check the generated querybuilder */
    QueryJobConfiguration queryJobConfiguration = queryBuilder.buildQueryJobConfig(new QueryParameters().type("ICD9").parameters(params));
    for (String key : queryJobConfiguration.getNamedParameters().keySet()) {
        if (key.startsWith("Condition")) {
            conditionNamedParameter = key;
            cmConditionParameter = "cm" + key.replace("Condition", "");
            procConditionParameter = "proc" + key.replace("Condition", "");
        } else if (key.startsWith("Measurement")) {
            measurementNamedParameter = key;
            cmMeasurementParameter = "cm" + key.replace("Measurement", "");
            procMeasurementParameter = "proc" + key.replace("Measurement", "");
        } else if (key.startsWith("Procedure")) {
            procedureNamedParameter = key;
            cmProcedureParameter = "cm" + key.replace("Procedure", "");
            procProcedureParameter = "proc" + key.replace("Procedure", "");
        }
    }
    String expected = "select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.measurement` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.measurement_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmMeasurementParameter + ",@" + procMeasurementParameter + ")\n" + "and b.concept_code like @" + measurementNamedParameter + "\n" + " union all\n" + "select person_id\n" + "from `${projectId}.${dataSetId}.procedure_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.procedure_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmProcedureParameter + ",@" + procProcedureParameter + ")\n" + "and b.concept_code like @" + procedureNamedParameter + "\n" + " union all\n" + "select person_id\n" + "from `${projectId}.${dataSetId}.condition_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.condition_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmConditionParameter + ",@" + procConditionParameter + ")\n" + "and b.concept_code in unnest(@" + conditionNamedParameter + ")\n" + ")\n";
    assertEquals(expected, queryJobConfiguration.getQuery());
    /* Check the querybuilder parameters */
    List<QueryParameterValue> conditionCodes = queryJobConfiguration.getNamedParameters().get(conditionNamedParameter).getArrayValues();
    assertTrue(conditionCodes.contains(QueryParameterValue.newBuilder().setValue("10.1").setType(StandardSQLTypeName.STRING).build()));
    assertTrue(conditionCodes.contains(QueryParameterValue.newBuilder().setValue("20.2").setType(StandardSQLTypeName.STRING).build()));
    String measurementCode = queryJobConfiguration.getNamedParameters().get(measurementNamedParameter).getValue();
    assertTrue("0%".equals(measurementCode));
    String procedureCode = queryJobConfiguration.getNamedParameters().get(procedureNamedParameter).getValue();
    assertTrue("1%".equals(procedureCode));
    assertEquals("ICD9CM", queryJobConfiguration.getNamedParameters().get(cmConditionParameter).getValue());
    assertEquals("ICD9Proc", queryJobConfiguration.getNamedParameters().get(procConditionParameter).getValue());
}
Also used : QueryParameterValue(com.google.cloud.bigquery.QueryParameterValue) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Test(org.junit.Test)

Example 18 with SearchParameter

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

the class CodesQueryBuilderTest method buildQueryJobConfigICD9NotGroup.

@Test
public void buildQueryJobConfigICD9NotGroup() throws Exception {
    String measurementNamedParameter = "";
    String conditionNamedParameter = "";
    String cmConditionParameter = "";
    String procConditionParameter = "";
    String cmMeasurementParameter = "";
    String procMeasurementParameter = "";
    List<SearchParameter> params = new ArrayList<>();
    params.add(new SearchParameter().group(false).type("ICD9").domain("Condition").value("10.1"));
    params.add(new SearchParameter().group(false).type("ICD9").domain("Condition").value("20.2"));
    params.add(new SearchParameter().group(false).type("ICD9").domain("Measurement").value("30.3"));
    /* Check the generated querybuilder */
    QueryJobConfiguration queryJobConfiguration = queryBuilder.buildQueryJobConfig(new QueryParameters().type("ICD9").parameters(params));
    for (String key : queryJobConfiguration.getNamedParameters().keySet()) {
        if (key.startsWith("Condition")) {
            conditionNamedParameter = key;
            cmConditionParameter = "cm" + key.replace("Condition", "");
            procConditionParameter = "proc" + key.replace("Condition", "");
        } else if (key.startsWith("Measurement")) {
            measurementNamedParameter = key;
            cmMeasurementParameter = "cm" + key.replace("Measurement", "");
            procMeasurementParameter = "proc" + key.replace("Measurement", "");
        }
    }
    String expected = "select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.condition_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.condition_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmConditionParameter + ",@" + procConditionParameter + ")\n" + "and b.concept_code in unnest(@" + conditionNamedParameter + ")\n" + " union all\n" + "select person_id\n" + "from `${projectId}.${dataSetId}.measurement` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.measurement_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmMeasurementParameter + ",@" + procMeasurementParameter + ")\n" + "and b.concept_code in unnest(@" + measurementNamedParameter + ")\n" + ")\n";
    assertEquals(expected, queryJobConfiguration.getQuery());
    /* Check the querybuilder parameters */
    List<QueryParameterValue> conditionCodes = queryJobConfiguration.getNamedParameters().get(conditionNamedParameter).getArrayValues();
    assertTrue(conditionCodes.contains(QueryParameterValue.newBuilder().setValue("10.1").setType(StandardSQLTypeName.STRING).build()));
    assertTrue(conditionCodes.contains(QueryParameterValue.newBuilder().setValue("20.2").setType(StandardSQLTypeName.STRING).build()));
    List<QueryParameterValue> measurementCodes = queryJobConfiguration.getNamedParameters().get(measurementNamedParameter).getArrayValues();
    assertTrue(measurementCodes.contains(QueryParameterValue.newBuilder().setValue("30.3").setType(StandardSQLTypeName.STRING).build()));
    assertEquals("ICD9CM", queryJobConfiguration.getNamedParameters().get(cmConditionParameter).getValue());
    assertEquals("ICD9Proc", queryJobConfiguration.getNamedParameters().get(procConditionParameter).getValue());
}
Also used : QueryParameterValue(com.google.cloud.bigquery.QueryParameterValue) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Test(org.junit.Test)

Example 19 with SearchParameter

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

the class PhecodesQueryBuilderTest method buildQueryJobConfig.

@Test
public void buildQueryJobConfig() throws Exception {
    String pheCodesNamedParameter = "";
    List<SearchParameter> params = new ArrayList<>();
    params.add(new SearchParameter().value("008"));
    params.add(new SearchParameter().value("010"));
    params.add(new SearchParameter().value("031"));
    /* Check the generated querybuilder */
    QueryJobConfiguration queryJobConfiguration = queryBuilder.buildQueryJobConfig(new QueryParameters().type("PHECODE").parameters(params));
    for (String key : queryJobConfiguration.getNamedParameters().keySet()) {
        if (key.startsWith("PheCodes")) {
            pheCodesNamedParameter = key;
        }
    }
    String expected = "select person_id\n" + "from `${projectId}.${dataSetId}.condition_occurrence` co\n" + "where co.condition_source_concept_id in (select concept_id\n" + "from `${projectId}.${dataSetId}.concept`\n" + "where concept_code in\n" + "(select icd9 from `${projectId}.${dataSetId}.phecode_criteria_icd`\n" + "where phecode in unnest(@" + pheCodesNamedParameter + "))\n" + "and vocabulary_id in ('ICD9Proc', 'ICD9CM')\n" + ")\n" + "union all\n" + "select person_id\n" + "from `${projectId}.${dataSetId}.procedure_occurrence` po\n" + "where po.procedure_source_concept_id in (select concept_id\n" + "from `${projectId}.${dataSetId}.concept`\n" + "where concept_code in\n" + "(select icd9 from `${projectId}.${dataSetId}.phecode_criteria_icd`\n" + "where phecode in unnest(@" + pheCodesNamedParameter + "))\n" + "and vocabulary_id in ('ICD9Proc', 'ICD9CM')\n" + ")\n" + "union all\n" + "select person_id\n" + "from `${projectId}.${dataSetId}.measurement` m\n" + "where m.measurement_source_concept_id in (select concept_id\n" + "from `${projectId}.${dataSetId}.concept`\n" + "where concept_code in\n" + "(select icd9 from `${projectId}.${dataSetId}.phecode_criteria_icd`\n" + "where phecode in unnest(@" + pheCodesNamedParameter + "))\n" + "and vocabulary_id in ('ICD9Proc', 'ICD9CM')\n" + ")\n" + "union all\n" + "select person_id\n" + "from `${projectId}.${dataSetId}.observation` o\n" + "where o.observation_source_concept_id in (select concept_id\n" + "from `${projectId}.${dataSetId}.concept`\n" + "where concept_code in\n" + "(select icd9 from `${projectId}.${dataSetId}.phecode_criteria_icd`\n" + "where phecode in unnest(@" + pheCodesNamedParameter + "))\n" + "and vocabulary_id in ('ICD9Proc', 'ICD9CM')\n" + ")\n";
    assertEquals(expected, queryJobConfiguration.getQuery());
    /* Check the querybuilder parameters */
    List<QueryParameterValue> pheCodes = queryJobConfiguration.getNamedParameters().get(pheCodesNamedParameter).getArrayValues();
    assertTrue(pheCodes.contains(QueryParameterValue.newBuilder().setValue("008").setType(StandardSQLTypeName.STRING).build()));
    assertTrue(pheCodes.contains(QueryParameterValue.newBuilder().setValue("010").setType(StandardSQLTypeName.STRING).build()));
    assertTrue(pheCodes.contains(QueryParameterValue.newBuilder().setValue("031").setType(StandardSQLTypeName.STRING).build()));
}
Also used : QueryParameterValue(com.google.cloud.bigquery.QueryParameterValue) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Test(org.junit.Test)

Example 20 with SearchParameter

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

the class SearchRequests method genderRequest.

public static SearchRequest genderRequest(long... conceptIds) {
    SearchGroupItem searchGroupItem = new SearchGroupItem().id("id1").type(DEMO_TYPE);
    for (long conceptId : conceptIds) {
        SearchParameter parameter = new SearchParameter().domain(DEMO_DOMAIN).subtype(GENDER_SUBTYPE).conceptId(conceptId);
        searchGroupItem.addSearchParametersItem(parameter);
    }
    return searchRequest(searchGroupItem);
}
Also used : SearchParameter(org.pmiops.workbench.model.SearchParameter) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem)

Aggregations

SearchParameter (org.pmiops.workbench.model.SearchParameter)39 Test (org.junit.Test)34 SearchRequest (org.pmiops.workbench.model.SearchRequest)27 SearchGroupItem (org.pmiops.workbench.model.SearchGroupItem)10 ArrayList (java.util.ArrayList)9 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)8 SearchGroup (org.pmiops.workbench.model.SearchGroup)7 Criteria (org.pmiops.workbench.cdr.model.Criteria)6 Attribute (org.pmiops.workbench.model.Attribute)5 QueryParameterValue (com.google.cloud.bigquery.QueryParameterValue)4 ListMultimap (com.google.common.collect.ListMultimap)3 LocalDate (java.time.LocalDate)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 LinkedHashMap (java.util.LinkedHashMap)2 HashMap (java.util.HashMap)1 List (java.util.List)1 CriteriaDao (org.pmiops.workbench.cdr.dao.CriteriaDao)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1