Search in sources :

Example 26 with SearchParameter

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

the class DemoQueryBuilderTest method buildQueryJobConfig.

@Test
public void buildQueryJobConfig() throws Exception {
    String genderNamedParameter = "";
    String ageNamedParameter = "";
    String raceNamedParameter = "";
    List<SearchParameter> params = new ArrayList<>();
    params.add(new SearchParameter().type("DEMO").subtype("GEN").conceptId(8507L));
    params.add(new SearchParameter().type("DEMO").subtype("AGE").attribute(new Attribute().operator("=").operands(Arrays.asList("18"))));
    params.add(new SearchParameter().type("DEM0").subtype("RACE").conceptId(1234L));
    params.add(new SearchParameter().type("DEM0").subtype("RACE").conceptId(1235L));
    QueryJobConfiguration queryJobConfiguration = queryBuilder.buildQueryJobConfig(new QueryParameters().type("DEMO").parameters(params));
    for (String key : queryJobConfiguration.getNamedParameters().keySet()) {
        if (key.startsWith("gen")) {
            genderNamedParameter = key;
        } else if (key.startsWith("race")) {
            raceNamedParameter = key;
        } else {
            ageNamedParameter = key;
        }
    }
    String expected = "select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where\n" + "p.gender_concept_id in unnest(@" + genderNamedParameter + ")\n" + "and\n" + "p.race_concept_id in unnest(@" + raceNamedParameter + ")\n" + "and\n" + "CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(p.year_of_birth, p.month_of_birth, p.day_of_birth), MONTH)/12) as INT64) =\n" + "@" + ageNamedParameter + "\n";
    assertEquals(expected, queryJobConfiguration.getQuery());
    assertEquals("8507", queryJobConfiguration.getNamedParameters().get(genderNamedParameter).getArrayValues().get(0).getValue());
    assertEquals("18", queryJobConfiguration.getNamedParameters().get(ageNamedParameter).getValue());
    assertEquals("1234", queryJobConfiguration.getNamedParameters().get(raceNamedParameter).getArrayValues().get(0).getValue());
    assertEquals("1235", queryJobConfiguration.getNamedParameters().get(raceNamedParameter).getArrayValues().get(1).getValue());
}
Also used : Attribute(org.pmiops.workbench.model.Attribute) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Test(org.junit.Test)

Example 27 with SearchParameter

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

the class SearchRequests method codesRequest.

public static SearchRequest codesRequest(String type, String... codes) {
    SearchGroupItem searchGroupItem = new SearchGroupItem().id("id1").type(type);
    for (String code : codes) {
        SearchParameter parameter = new SearchParameter().type(type).group(true).value(code);
        searchGroupItem.addSearchParametersItem(parameter);
    }
    return searchRequest(searchGroupItem);
}
Also used : SearchParameter(org.pmiops.workbench.model.SearchParameter) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem)

Example 28 with SearchParameter

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

the class DomainLookupService method findCodesForEmptyDomains.

/**
 * Find all domain ids for {@link SearchGroup}s in the following groups:
 * ICD9, ICD10 and CPT.
 *
 * @param searchGroups
 */
public void findCodesForEmptyDomains(List<SearchGroup> searchGroups) {
    searchGroups.stream().flatMap(searchGroup -> searchGroup.getItems().stream()).filter(item -> item.getType().matches("ICD9|ICD10")).forEach(item -> {
        List<SearchParameter> paramsWithDomains = new ArrayList<>();
        for (SearchParameter parameter : item.getSearchParameters()) {
            if (parameter.getDomain() == null || parameter.getDomain().isEmpty()) {
                List<String> domainLookups = (parameter.getSubtype() == null) ? criteriaDao.findCriteriaByTypeAndCode(parameter.getType(), parameter.getValue()) : criteriaDao.findCriteriaByTypeAndSubtypeAndCode(parameter.getType(), parameter.getSubtype(), parameter.getValue());
                for (String row : domainLookups) {
                    paramsWithDomains.add(new SearchParameter().domain(row).value(parameter.getValue()).type(parameter.getType()).subtype(parameter.getSubtype()).group(parameter.getGroup()));
                }
            } else {
                paramsWithDomains.add(parameter);
            }
        }
        item.setSearchParameters(paramsWithDomains);
    });
}
Also used : SearchGroup(org.pmiops.workbench.model.SearchGroup) List(java.util.List) Service(org.springframework.stereotype.Service) Autowired(org.springframework.beans.factory.annotation.Autowired) CriteriaDao(org.pmiops.workbench.cdr.dao.CriteriaDao) SearchParameter(org.pmiops.workbench.model.SearchParameter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter)

Example 29 with SearchParameter

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

the class CohortBuilderControllerTest method countSubjectsDemoDec.

@Test
public void countSubjectsDemoDec() throws Exception {
    Criteria demoGender = createDemoCriteria("DEMO", "DEC", null);
    SearchParameter demo = createSearchParameter(demoGender, "Deceased");
    SearchRequest searchRequest = createSearchRequests(demoGender.getType(), Arrays.asList(demo));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) Criteria(org.pmiops.workbench.cdr.model.Criteria) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

Example 30 with SearchParameter

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

the class CohortBuilderControllerTest method countSubjectsICD10ProcedureOccurrenceParent.

@Test
public void countSubjectsICD10ProcedureOccurrenceParent() throws Exception {
    SearchParameter icd10 = createSearchParameter(icd10ProcedureParent, "16");
    SearchRequest searchRequest = createSearchRequests(icd10ProcedureParent.getType(), Arrays.asList(icd10));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

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